Applying warps from cropped images to uncropped ones?

Dear Experts

Is it possible to do the following:
1, Have two large scans (~250x250x18 voxels in-plane); A and B
2, Segment them to get the centerline for better coregistration (A_seg and B_seg) and for masking
3, Mask and crop them both with the same mask (cutting it down to 80x80x18 voxels); A_crop and B_crop
4, Coregister the two masked scans (A_crop to B_crop)
5, Apply the warp to the original A?

(This is a follow-up from an old question of mine: Non-rigid coregistration shrinks cord (sct_register_multimodal, syn algo, 4.0 beta 2))

Steps 1-4 work fine for me, but when I apply the warp to the uncropped image, the end result is confusing, and the warp seems to be applied not to the cropped and masked area, but to a corner of the original image. See the black tear in the top of this image

I think it is down to the cooridante system of the cropped scans and the uncropped ones not being the same. When visualised in FSLeyes, the cropped scan is in the upper corned of it’s own uncropped version (original scan in full view, mask in white opaque overlay, cropped scam in the top, close to the left edge):

I am guessing the way around this is to properly define the -d destination files. Here is my code, using these mock filenames.


‘sct_register_multimodal -i A_crop.nii -iseg A_seg.nii -d B_crop.nii -dseg B_seg.nii -param step=1,type=seg,algo=centermassrot:step=2,algo=bsplinesyn,type=im,metric=MI,iter=3,slicewise=0 -o B_reg.nii -owarp A_warptoB.nii -qc /QAfolder’

sct_apply_transfo -i A.nii -d B.nii -w A_warptoB.nii

SCT version 4.2. I tried checking pages 99-101 of the most recent SCT course (20190122), but it appears I am doing things right.

What am I doing wrong?

Hi Daniel,

I’ve tried with the code below, and steps 1-5 seem to be working fine:

# Tested on SCT commit 72c7e4fdb52cdc45030168d379f019b6da00e16c
# Download dummy data
sct_download_data -d sct_testing_data
cd sct_testing_data/mt
# Crop
sct_crop_image -i mt0.nii.gz -xmin 5 -xmax 45 -ymin 5 -ymax 45 -o mt0_crop.nii
sct_crop_image -i mt1.nii.gz -xmin 5 -xmax 45 -ymin 5 -ymax 45 -o mt1_crop.nii
# Segment
sct_propseg -i mt0_crop.nii -c t2 -qc qc
sct_propseg -i mt1_crop.nii -c t2 -qc qc
# Register mt0 to mt1
sct_register_multimodal -i mt0_crop.nii -iseg mt0_crop_seg.nii -d mt1_crop.nii -dseg mt1_crop_seg.nii -param step=1,type=seg,algo=centermassrot:step=2,algo=bsplinesyn,type=im,metric=MI,iter=3,slicewise=0 -qc qc
# Apply transfo to uncropped data
sct_apply_transfo -i mt0.nii.gz -d mt1.nii.gz -w warp_mt0_crop2mt1_crop.nii.gz
# --> IT WORKS :-)

Would you be able to upload your mock files and write the complete code you used so I can try to reproduce on my end and find the source of the bug?


Apologies, this is a case of PICNIC. :hot_face:

I had mixed up B and B_crop in the sct_apply_transfo line.

Sorry to have wasted your time.

1 Like