In this example, we will register two brain MRI scans from two different patients. One MRI will be designated as "fixed" and the other as "moving".
The two brains are in different physical locations. We first perform affine registration to correct for differences in brain position, rotation, and size.
> greedy -d 3 -a \
-m NCC 2x2x2 \
-i fixed.nii.gz moving.nii.gz \
-o affine.mat \
-ia-image-centers -n 100x50x10
This call to greedy uses some of the most common options:
The result of the registration is the file out_affine.mat. We can view the contents of this file:
> cat affine.mat
xxxx
We can now perform deformable registration between the fixed and moving images.
> greedy -d 3 \
-m NCC 2x2x2 \
-i fixed.nii.gz moving.nii.gz \
-it affine.mat \
-o warp.nii.gz \
-oinv inverse_warp.nii.gz \
-n 100x50x10
This is pretty similar to the affine command. Notice the differences:
After you run the command above, the warp.nii.gz file will be generated. You can view it in ITK-SNAP or other viewer. It is a 3D image volume where each voxel stores the x,y,z components of a displacement vector. For every voxel in the fixed image space, the warp image specifies the displacement that maps that voxel's center to the corresponding location in the moving image.
So far we have just computed the affine and deformable transformation between the fixed image and the moving image. We now need to apply these transformations to the moving image. We also have a segmentation of the moving image, moving_seg.nii.gz, which we would also like to warp into the fixed image space. We do this using the greedy reslice mode (-r commands).
> greedy -d 3 \
-rf fixed.nii.gz \
-rm moving.nii.gz resliced.nii.gz \
-ri LABEL 0.2vox \
-rm moving_seg.nii.gz resliced_seg.nii.gz \
-r warp.nii.gz affine.mat
Let's deconstruct this command:
Optionally, you can warp the fixed image back into the space of the moving. This requires using the (-oinv) option when calling greedy for deformable registration. You can also invert a warp computed previously using the -iw command (see documentation).
The following command warps the fixed image to the moving image space.
> greedy -d 3 \
-rf moving.nii.gz \
-rm fixed.nii.gz reslice_fix_into_mov.nii.gz \
-r affine.mat,-1 inverse_warp.nii.gz
Very similar to above, except that:
That's pretty much it for learning to use greedy. See detailed documentation for other options and more details. Enjoy!