Two images with different dimensions as inputs of mrcalc

Hi all,

I read that mrcalc will allow images with different dimensions but my images are of the following dimensions:
149 x 174 x 137 and 154 x 188 x 149

and I’m getting this error from mrcalc:

mrcalc: [ERROR] dimensions of input images do not match - aborting

I’ve done the following:

mraverageheader ${image1} ${image2} ./av.mif
mrtransform ${image1} -template ./av.mif ./ah.mif -oversample 1 -interp linear
mrtransform ${image2} -template ./av.mif ./bh.mif -oversample 1 -interp linear
mrcalc ./ah.mif ./bh.mif -subtract ./transformed_sub.mif

Is this correct? or can I do better?

Thanks!

Is this correct? or can I do better?

Depends on the reason for which the image dimensions are different.

If they are images with completely different voxel grids, then generating the average header, resampling both images to that grid, and then performing your calculation, probably is indeed the “best” you can do.

If however one image is strictly a subset of the other - ie. many of the voxel locations overlap perfectly, but merely the extent of the FoV is reduced in one image compared to the other - then re-sampling the larger image onto the smaller one with nearest-neighbour interpolation would actually be preferable, as the underlying image data would not undergo any interpolation in either image.

Rob

The difference between the two images come from choosing the -initial_alignment geometric option in population_template for the one with bigger dimensions. So my guess is that they should not be with completely different voxel grid. Am I right? if yes, then should I use your suggestion?

The only reason I can think of for this error, given your pipeline, is that your two input images have different numbers of volumes (hard to tell from the information you provide). What’s the full output of mrinfo on your original inputs?

Hi Donald,

Are you asking about two input images to mrcalc orpopulation_template?

The same images were fed to population_template with two different initialization schemes and then the output templates which have different dimensions (149 x 174 x 137 vs. 154 x 188 x 149) were fed to mrcalc.

Either will do. But you’re only showing the spatial dimensions here, are both images purely 3D? No volumes? I’d like to see the full output of mrinfo for both inputs (to either command) just to be sure…

  1. If you used different initialisation schemes, there is no guarantee that any locations (scanner or voxel) between the two templates correspond to the same anatomical features. Comparing the two images with mrcalc or mrmetric is quite meaningless unless register both templates and transform them to their average space.

  2. mrcalc operates on a per-voxel basis, all input images must have the same voxel grid.

If you actually did exactly this, both images ah.mif and bh.mif should have the exact same header transformation and number of voxels. If in doubt, repeat with -force in all commands. If this still gives the same error, please post the full output pf:

mrtransform ${image1} -template av.mif ah.mif -oversample 1 -interp linear -force
mrtransform ${image2} -template av.mif bh.mif -oversample 1 -interp linear -force
mrcalc ./ah.mif ./bh.mif -subtract transformed_sub.mif -force
mrinfo -transform -size -info ${image1} ${image2} av.mif ah.mif bh.mif
1 Like