---
# System prepended metadata

title: epi_reg bbr issues

---

# Script - `reg.sh`

FLIRT / BBR seems to have an issue when given images with a resolution greater than 1mm<sup>3</sup>; the resulting transformation contains a large shift along the Z axis. In all of the examples below, the _pre-alignment_ registration is superior to the _BBR_ registration (and does not contain the large shift).

Note that for this particular data-set, BBR would not be expected to calculate a good registration, due to the relatively high EPI distortion, and relatively poor WM segmentation.  But there is obviously something going wrong when BBR is asked to register an EPI image to a high-resolution T1 image.

```
#!/usr/bin/env bash

set -ex

vrefbrain=T1_brain
vrefhead=T1
vepi=epi
vout=epi_reg

#bbrsch=bbr.sch
bbrsch=$FSLDIR/etc/flirtsch/bbr.sch

echo "FLIRT pre-alignment"
$FSLDIR/bin/flirt -ref ${vrefbrain}      \
                  -in ${vepi}            \
                  -dof 6                 \
                  -omat ${vout}_init.mat \
                  -out ${vout}_prealign  \
                  -verbose 9 &> pre_align.log

echo "Running BBR"
$FSLDIR/bin/flirt -ref ${vrefhead}          \
                  -in ${vepi}               \
                  -dof 6                    \
                  -cost bbr                 \
                  -wmseg ${vout}_fast_wmseg \
                  -init ${vout}_init.mat    \
                  -omat ${vout}.mat         \
                  -out ${vout}              \
                  -schedule ${bbrsch}       \
                  "$@"                      \
                  -verbose 9 &> bbr.log


echo "Done"

fsleyes render -of pre_align.png     \
        ${vrefhead} ${vout}_prealign \
        -ot mask -o -t 750 4750 -mc 1 0 0 -w 3

fsleyes render -of bbr.png   \
        ${vrefhead} ${vout}  \
        -ot mask -o -t 750 4750 -mc 1 0 0 -w 3
```


## A - Standard `epi_reg`

```
mkdir A && cd A
cp ../data/* .
../reg.sh
```

![A](https://hackmd.io/_uploads/r1ao8pCAT.png)


## B - Resample EPI and T1 to 1mm^3:

```
mkdir B && cd B
cp ../data/* .
for img in *gz; do
  $FSLDIR/bin/resample_image -d 1,1,1 $img $img
done
../reg.sh
```

![B](https://hackmd.io/_uploads/B1Y6U60Ca.png)


## C - Use brain extracted EPI

```
mkdir C && cd C
cp ../data/* .
bet epi epi -f 0.3
../reg.sh
```

![C](https://hackmd.io/_uploads/r1RAIpRAT.png)


## D - Add `-basescale 1`

```
mkdir D && cd D
cp ../data/* .
../reg.sh -basescale 1
```

![D](https://hackmd.io/_uploads/BkGgD6RA6.png)


## E - Resample EPI and T1 to 1.5mm^3:
```
mkdir E && cd E
cp ../data/* .
for img in *gz; do
  $FSLDIR/bin/resample_image -d 1.5,1.5,1.5 $img $img
done
../reg.sh
```

![E](https://hackmd.io/_uploads/rkrbDp0Ca.png)


## F - Resample EPI and T1 to 1mm^3 and use brain extracted EPI

```
mkdir F && cd F
cp ../data/* .
for img in *gz; do
  $FSLDIR/bin/resample_image -d 1,1,1 $img $img
done
bet epi epi -f 0.3
../reg.sh
```

![F](https://hackmd.io/_uploads/rJBmPTCRT.png)

## G - Resample EPI to 1mm^3
```
mkdir G && cd G
cp ../data/* .
for img in epi*gz; do
  $FSLDIR/bin/resample_image -d 1,1,1 $img $img
done
../reg.sh
```

![G](https://hackmd.io/_uploads/HkaeRv3s0.png)

## H - Resample T1 to 1mm^3
```
mkdir H && cd H
cp ../data/* .
for img in T1*gz; do
  $FSLDIR/bin/resample_image -d 1,1,1 $img $img
done
../reg.sh
```

![H](https://hackmd.io/_uploads/S1uHkOhoA.png)
