Sct_crop_image masks with different resolution

Hi there,

I noticed with sct_crop_image that it’s not possible to crop an image using a mask that’s in a different resolution. The image is still cropped but just not in the correct place. I think it could be a good additional functionality if the mask could be resampled in the background (perhaps with a warning). Or it would be good to at least throw an error if a given input image and mask have different resolutions to make the issue more explicit for users who are trying to do this.

Example using SCTv6.1, with the data that comes with the installation in data/sct_testing_data/t2/ :

sct_create_mask -i t2.nii.gz -p centerline,t2_centerline-optic.nii.gz -o t2_mask_orig_space.nii.gz -size 28

sct_resample -i t2.nii.gz -o t2_resampled.nii.gz -mm 0.5x0.5x0.5

sct_crop_image -i t2_resampled.nii.gz -o t2_resampled_cropped.nii.gz -m t2_mask_orig_space.nii.gz

Output:
Crop mask shown in red, t2_resampled_cropped shown in yellow.
crop_output

Sorry about the duplicate post, nothing showed in the previous one as I put everything inside the comment tags…

Thanks,
Ricky

Hi @Ricky_Walsh,

Thank you for the comment. Indeed, the input image and mask should be in the same voxel space (ie: same qform matrix, same resolution). I agree that throwing a warning or an error would be a useful feature. I’ve opened an issue.

Cheers,
Julien