Transforming multiple MRI Images (in a Jiffy!)

 

 

Hey,

Update: So far, The Image registration workflow has been put into the PR zone. See the PR below (from earlier this week) for details:

Link to the PR: Image Registration Workflow 

This blog post is about the extension of the Image Registration Workflow for transforming several quickly. Wondering why is that any different from the conventional image registration (which is already pending approval).

Here is the thing, the typical image registration process takes anywhere between 16 – 158 seconds (just for the coronal slices) and 34-593 seconds (for brain images depending on the input size and type of registration). So, the idea is to not do the registration repeatedly for different images of the same brain but rather use the affine transformation matrix (obtained from the first registration itself) to align different images at once to the static/reference image.

Apart from huge savings (both time and computation), this will be handy when a user has a large collection of moving images where any one of them is aligned and the rest can then simply follow the information in the affine matrix without having to be registered individually.

Step-1: Load the static and moving image/image(s) as numpy arrays

static_image = nib.load(static_image_file)
static_grid2world = static_image.affine

moving_image = nib.load(moving_image_file)
image_data = moving_image.get_data()

Step-2: Do the basic sanity check before moving on to align them. This will ensure that the dimensions of the images are same so that the workflow doesn’t break down while running.

affine_matrix = load_affine_matrix(affine_matrix_file)

Step-3: Instantiate the AffineMap (with the affine matrix that is obtained in step-2 above) class and call the transform() method on that object.

img_transformation = AffineMap(affine=affine_matrix, domain_grid_shape=image_data.shape)
transformed = img_transformation.transform(image_data)

Step-4: Save the transformed image on the disk using the coordinate system of the static image.

save_nifti(out_dir+out_file, transformed, affine=static_grid2world)

Here is the link to the latest version of the workflow

Commit Link: Apply Transform Workflow

Commit Link: Unit test cases for the Apply Transform Workflow

I will open the PR for this workflow once the initial Image Registration workflow is merged (that’s a pre-requisite for this one to work). Also, this is a good opportunity for getting the feedback about possible code modifications, optimizations, and testing with different input data.

Soon, I will be updating this blog with images that were aligned using this workflow along with the benchmarks.

Adios for now,

Parichit

Leave a Reply

Your email address will not be published. Required fields are marked *