Mrgrid/3dresample image cropped

Hi all,

I want to resample an image with dimensions 128, 256, 256 to 182, 218, 182

I ran:
3dresample -master path/to/image182.218.182 -prefix resized -input path/to/image128.256.256

I also tried regrid with -template flag, but got same results.

The result is the right dimensions but an image that is cropped! So even though the resulting image has the same dimensions as the one I wanted, part of it was chopped off.

Any recommendations what to do in this situation? Thanks in advance.

I’ve no clue about 3dresample, it’s not one of ours – I assume you’re referring to the AFNI program?

But in MRtrix3, you should be able to use the mrgrid command:

mrgrid original.nii regrid -size 182,218,182 resampled.nii

This will preserve the field of view while changing the number of voxels along each dimension as specified. If you need to match some other image exactly in terms of dimensions, voxel size, orientation and field of view, you can pass that image as the -template (and also override image dimensions or voxel size if needed), e.g.:

mrgrid original.nii regrid -template master.mif resampled.nii

Thank you for your answer Donald.

Yes, 3dresample is AFNI, was trying a bunch of things and included this here instead of at another forum. I also tried mrgrid with the template flag but gave me same results as 3dresample. The brain is cut somehow. When I try mrgrid original.nii regrid -size 182,218,182 resampled.nii, it looks good, but it is not in MNI space where I want it to be (like the reference image). Is there a way to do that including change the image to MNI?

OK, there’s a couple of ways I could interpret that:

  1. you want to register an image to MNI space so that the anatomy in your image maps onto the anatomy of the MNI template.

  2. you want the voxel grid of your image to match that of the MNI template, in terms of voxel size, image dimensions, orientation of the axes, etc.

Note that these are essentially independent concepts. You can have co-registered data defined on a completely different voxel grid, but since we can figure the real-space position of each voxel (via the transform matrix), equivalent locations can overlap in real-space even if the voxel grid is completely different. Likewise, two images can be defined on the same voxel grid, but without alignment of the anatomy in these images. See this wiki post for details.

Your original question implies interpretation 2 only. If that’s all you need is to regrid to match the reference image, then the second example I provided should do that for you:

 mrgrid original.nii regrid -template master.mif resampled.nii

However, if you need to register to MNI space (i.e interpretation 1), then that’s an altogether different problem…

Thanks again. Interpretation 2 is correct, and I have performed what you suggested, but the image looks cropped. Even when I move it around it’s not out of view or anything, I am literally looking at part of an image!

OK, it sounds like the field of views genuinely don’t match – maybe one of them has the wrong voxel size? If you look at the data using the mrview overlay tool, do they look aligned as expected? E.g. what do you see with a command like this:

mrview original.nii -overlay.load template.nii -overlay.opacity 0.5

What do you mean by “wrong” voxel size?
When I use that command, I see the original.nii sitting on top of (not overlapping) the template.nii where the template.nii is about 8 times bigger. Also the original view is coronal and template is axial.

Well, if the field of view is wrong by a factor of 8, either the image dimensions are off by a factor of 8 (which didn’t sound like it was the case), or the voxel size is wrong by a factor of 8. What does mrinfo report for these images?

So that very clearly tells you that the images are not at all coregistered. That mrview command should show both images in their correct location with respect to real space, so if they’re not even the right size or orientation, that’s the issue that needs fixing – not the resampling itself. You’ll need to figure out which of these images is not right, and then figure out what went wrong in the steps that produced that image…

Oh! I think I know what you mean. This is a mouse brain (original.nii) vs human brain (template.nii In MNI). Sorry I didn’t mention that…
I want to resample the mouse brain to be the same voxel size and location as the human brain. The reason behind this is that I am using a program that hard codes that human template in and If my image is not in the same parameters if doesn’t proceed.