How to simply move the brain to center of matrix-space


I have a large set of T1-scans from different sites which I have skull-stripped GM-extracted (i.e. I have a set of GM-maps) that are all in native space, no warping has been preformed. That means that some of the brains are pretty far of the matrix-space center.

I am going to run augmentations on these so it is important that they somewhat overlap in space and since I will run rotational augmentations they will also be clipped if they are not in the center of space. I tried this:

  1. I wanted the template to have dimensions divisible by 32 for deep learning purposes :

3dZeropad -RL 192 -AP 224 -IS 192 -prefix new_template.nii.gz MNI152_2009_template_SSW.nii.gz

Since the template has the dims 193, 229, 193 the zero-padding doesn’t change much and the the template brain is pretty much in the center after this operation which is fine

  1. Now I want my data to have the same dimensions so I ran:

3dAllineate -cmass -warp shift_only -base ../new_template.nii.gz -source 28336_1_MR_T1_struc_GM.nii.gz -prefix ../test_out/test.nii.gz

The data now has dims 192,224,192, the brains are centered and it looks good. But the file-size is 3 times larger so i suspect there is some interpolation going on. Is my command as simple as it can be for my purpose or should I add some flags if my goal is to change the resolution and have the brain at the center of volume?

Because I don’t want them to be aligned and matched, just to move each subject’s T1 so that the center of mass-overlap and give it the same 192,224,192 grid. If that makes sense.


Have you tried the @Align_Centers command?

Doesn’t that only move the center of the image (e.g. move the center from center of mass to center of the volume) but not moving the data itself?

Doing a simple 3dresample command is problematic since that can cut of parts of the brain. What seems to work is this:

for i in * ; do 3dAllineate -cmass -warp shift_only -base ../new_template.nii.gz -source $i -prefix rs_$i ; done

The -warp shif_only option in combination with the -cm option seems to move the brain into the center of the new volume and it has the right resolution. No rotation or further alignment seem to have taken place. This basically does what I want - I just want to know if there is a better option or a flag I should use.

Adding image of original image, template and resulting image

I am not completely sure what you want to do, but it sounds like you want a centered dataset on the same grid as some other dataset. A couple options to consider:

  1. @Align_Centers, then 3dresample. @Align_Centers has a -cm option to use the center of mass or the default move to the center of the grid.
  2. Rigid or “rigid_equiv” -, @auto_tlrc, fat_proc_axialize_anat all offer rigid_body and/or rigid_equiv options. 3dAllineate can also do the same in the way you have done this above. Rigid body aligns uses only 6 parameters for rotations and translations. The rigid equiv method computes the alignment using a full affine but applies only the 6 parameters. This is usually more appropriate for “axializing” the data - getting the data into a similar orientation as the template. The rigid transformation is extracted from the full affine with the cat_matvec -P option.

Thank you!

But then it sounds like my approach is correct.

I wanted my varying native resolution data to all have the same resolution (192,224,192) and that the brains are placed at the center of the volumes so that they all somewhat overlap.

But a simple 3dresample command gives me the correct grid but the brains are not moved to the center (of course)

And a simple 3dresampel command with the template as -master sometimes results in that the brain ends up at the corner of the image. It is important that the brains are centred in the volume an all somewhat overlap (not aligned to each other but basically occupies the same space).

So I re sampled the MNI-template (actually zero-padded since the template dims where very close to the wanted res) and used 3dAllineate with the template with the wanted resolution as a base. But I don’t want it to actually align my brains to it (no rotation or scaling), just move them to where the MNI brain is and the -cmass -warp shift_only options seems to only preform the “shift”. The individual brains seem to keep their angulations etc which is what I want. Does that seem about right?

I would probably do it with the first approach I mentioned - @Align_Centers for the central location (maybe with -cm) and then 3dresample to get the grid the same. Both those steps and in that order are needed. Computing an alignment with a shift only affine transformation will probably work too, but it’s a little different. That seems more likely to fail if alignment is thrown off, but it might be okay for your acquisition types.

Thanks! That gave similar results. But I had to use the -cm option in the @AlignCenters functions, otherwise the brain stays where it was in space (e.g. low in y-dim). Perhaps due to the native images having its center at the matrix center? Anyways, this worked:

for i in * ; do

@Align_Centers -cm -base $template -dset $i -prefix ../$out_dir/temp_$i

3dresample -master $template -inset ../$out_dir/temp_$i -prefix ../$out_dir/$i

rm ../$out_dir/temp_$i


Thanks =)