Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WARNING: the resulting image could have wrong apparent results #2810

Closed
jcohenadad opened this issue Jul 22, 2020 · 1 comment · Fixed by #2811
Closed

WARNING: the resulting image could have wrong apparent results #2810

jcohenadad opened this issue Jul 22, 2020 · 1 comment · Fixed by #2811
Assignees
Labels
user requested Raised by user on the SCT forum/email/GitHub. Be sure to notify them when fixed in a release.

Comments

@jcohenadad
Copy link
Member

jcohenadad commented Jul 22, 2020

The following warning is thrown when running sct_register_to_template with the -ref subject flag:

WARNING: the resulting image could have wrong apparent results. You should use an affine transformation as last transformation...
Full output
sct_register_to_template -i t2.nii.gz -s t2_seg.nii.gz -l labels.nii.gz -c t2s -ref subject

--
Spinal Cord Toolbox (git-master-67c679deadd8af0c2eb7445041b0c61628d8bbfa)


Check template files...
  OK: /Users/julien/code/sct/data/PAM50/template/PAM50_t2s.nii.gz
  OK: /Users/julien/code/sct/data/PAM50/template/PAM50_levels.nii.gz
  OK: /Users/julien/code/sct/data/PAM50/template/PAM50_cord.nii.gz

Check parameters:
  Data:                 t2.nii.gz
  Landmarks:            labels.nii.gz
  Segmentation:         t2_seg.nii.gz
  Path template:        /Users/julien/code/sct/data/PAM50
  Remove temp files:    1

Check input labels...

Create temporary folder (/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150931.564854-register_to_template-iqdb79td)...

Copying input data to tmp folder and convert to nii...

Generate labels from template vertebral labeling
Value = 1 : (70.0, 70.0505921918409, 951.0333382073403) --> ( 70.0, 70.0, 951.0)
Value = 2 : (70.0, 70.30833886308339, 923.9948020349481) --> ( 70.0, 70.0, 924.0)
Value = 3 : (70.0, 70.50121918179356, 889.7335862006682) --> ( 70.0, 71.0, 890.0)
Value = 4 : (70.0, 70.38403779633848, 852.8857673162912) --> ( 70.0, 70.0, 853.0)
Value = 5 : (70.0, 70.30789525112371, 818.2217119405902) --> ( 70.0, 70.0, 818.0)
Value = 6 : (70.0, 70.7014333993707, 786.225032047547) --> ( 70.0, 71.0, 786.0)
Value = 7 : (70.0, 70.80759724209705, 753.9094575256927) --> ( 70.0, 71.0, 754.0)
Value = 8 : (70.0, 70.35343403351428, 715.2977342459287) --> ( 70.0, 70.0, 715.0)
Value = 9 : (70.0, 70.41839798246667, 670.7036147472079) --> ( 70.0, 70.0, 671.0)
Value = 10 : (70.0, 70.41868823000898, 624.8615068668977) --> ( 70.0, 70.0, 625.0)
Value = 11 : (70.0, 70.43996427204287, 577.066096720684) --> ( 70.0, 70.0, 577.0)
Value = 12 : (70.0, 70.4400396432111, 527.0463330029733) --> ( 70.0, 70.0, 527.0)
Value = 13 : (70.0, 70.48122739179244, 475.89622053137083) --> ( 70.0, 70.0, 476.0)
Value = 14 : (70.0, 70.57302038880987, 424.0064011379801) --> ( 70.0, 71.0, 424.0)
Value = 15 : (70.0, 70.64169901804065, 370.32187714089974) --> ( 70.0, 71.0, 370.0)
Value = 16 : (70.0, 70.69621109607577, 316.83818222823635) --> ( 70.0, 71.0, 317.0)
Value = 17 : (70.0, 70.5720703125, 261.3439453125) --> ( 70.0, 71.0, 261.0)
Value = 18 : (70.0, 70.67006390034781, 200.1311979293052) --> ( 70.0, 71.0, 200.0)
Value = 19 : (70.0, 70.47842956120093, 141.44073903002308) --> ( 70.0, 70.0, 141.0)
Value = 20 : (70.0, 70.68440271257172, 92.52008346374544) --> ( 70.0, 71.0, 93.0)

Check if provided labels are available in the template

Binarize segmentation

Done! To view results, type:
fsleyes seg_bin.nii.gz &


Change orientation of input images to RPI...

Remove unused label on template. Keep only label present in the input label image...
sct_label_utils -i template_label_body.nii.gz -o template_label_body.nii.gz -remove-reference /private/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150931.564854-register_to_template-iqdb79td/label_projected_rpi.nii.gz # in /private/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150931.564854-register_to_template-iqdb79td
File /private/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150931.564854-register_to_template-iqdb79td/label_projected_rpi.nii.gz already exists. Will overwrite it.
File /private/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150931.564854-register_to_template-iqdb79td/template_label_body.nii.gz already exists. Will overwrite it.

Create temporary folder (/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150936.537995-register-bp5l2iyn)...

Copying input data to tmp folder and convert to nii...

--
ESTIMATE TRANSFORMATION FOR STEP #0
Registration parameters:
  type ........... label
  algo ........... syn
  slicewise ...... 0
  metric ......... MeanSquares
  iter ........... 10
  smooth ......... 0
  laplacian ...... 0
  shrink ......... 1
  gradStep ....... 0.5
  deformation .... 1x1x0
  init ........... 
  poly ........... 5
  filter_size .... 5
  dof ............ Tx_Ty_Tz_Rx_Ry_Rz_Sz
  smoothWarpXY ... 2
  rot_method ..... pca
Labels src: [[-0.0, 45.720001220703125, -116.84002685546875], [-0.0, 46.220001220703125, -152.84002685546875], [5.0, 45.720001220703125, -116.84002685546875]]
Labels dest: [[7.2192840576171875, -1.7866058349609375, 24.678329467773438], [7.2192840576171875, -0.7866058349609375, -10.321670532226562], [12.219284057617188, -1.7866058349609375, 24.678329467773438]]
Degrees of freedom (dof): Tx_Ty_Tz_Rx_Ry_Rz_Sz
Optimization terminated successfully.
         Current function value: 0.000000
         Iterations: 14
         Function evaluations: 1124
Matrix:
[[ 1.00000000e+00 -1.27249256e-11  1.97608995e-12]
 [ 1.26954035e-11  9.99897996e-01  1.42827999e-02]
 [-2.15763595e-12 -1.42827999e-02  9.99897996e-01]]
Center:
[ 8.88595072 -1.4532725  13.0116628 ]
Translation:
[[  -7.21928406   47.33994039 -141.85168966]]

--
ESTIMATE TRANSFORMATION FOR STEP #1

Apply transformation from previous step

Parse list of warping fields...

Get dimensions of data...
  141 x 141 x 991 x 1

Apply transformation...

Apply transformation and resample to destination space...
/Users/julien/code/sct/bin/isct_antsApplyTransforms -d 3 -i src.nii -o src_reg.nii -t warp_forward_0.txt -r dest_RPI.nii -n 'BSpline[3]' # in /private/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150936.537995-register-bp5l2iyn
Copy affine matrix from destination space to make sure qform/sform are the same.
WARNING: the resulting image could have wrong apparent results. You should use an affine transformation as last transformation...

Done! To view results, type:
fsleyes dest_RPI.nii src_reg.nii &


Parse list of warping fields...

Get dimensions of data...
  141 x 141 x 991 x 1

Apply transformation...

Apply transformation and resample to destination space...
/Users/julien/code/sct/bin/isct_antsApplyTransforms -d 3 -i src_seg.nii -o src_seg_reg.nii -t warp_forward_0.txt -r dest_seg_RPI.nii -n NearestNeighbor # in /private/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150936.537995-register-bp5l2iyn
Copy affine matrix from destination space to make sure qform/sform are the same.
WARNING: the resulting image could have wrong apparent results. You should use an affine transformation as last transformation...

Done! To view results, type:
fsleyes dest_seg_RPI.nii src_seg_reg.nii &

Registration parameters:
  type ........... imseg
  algo ........... centermassrot
  slicewise ...... 0
  metric ......... MeanSquares
  iter ........... 10
  smooth ......... 0
  laplacian ...... 0
  shrink ......... 1
  gradStep ....... 0.5
  deformation .... 1x1x0
  init ........... 
  poly ........... 5
  filter_size .... 5
  dof ............ Tx_Ty_Tz_Rx_Ry_Rz
  smoothWarpXY ... 2
  rot_method ..... pcahog

Create temporary folder (/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150939.266722-register-q9cwh82e)...

Copy input data to temp folder...
sct_convert -i src_reg.nii -o /var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150939.266722-register-q9cwh82e/src.nii
sct_convert -i src_seg_reg.nii -o /var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150939.266722-register-q9cwh82e/src_seg.nii
sct_convert -i dest_RPI.nii -o /var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150939.266722-register-q9cwh82e/dest.nii
sct_convert -i dest_seg_RPI.nii -o /var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150939.266722-register-q9cwh82e/dest_seg.nii

Get image dimensions of destination image...
  matrix size: 52 x 60 x 55
  voxel size:  1.0mm x 1.0mm x 1.0mm

Split input segmentation...

Split destination segmentation...

Split input image...

Split destination image...
Estimate cord angle for each slice: 100%|████████████████████████| 55/55 [00:00<00:00, 120.47iter/s]
Build 3D deformation field: 100%|████████████████████████████████| 55/55 [00:00<00:00, 100.90iter/s]

Generate warping field...
 --> step1Warp.nii.gz

Generate warping field...
 --> step1InverseWarp.nii.gz

Move warping fields...
cp step1Warp.nii.gz /private/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150936.537995-register-bp5l2iyn
cp step1InverseWarp.nii.gz /private/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150936.537995-register-bp5l2iyn
rm -rf /var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150939.266722-register-q9cwh82e

--
ESTIMATE TRANSFORMATION FOR STEP #2

Apply transformation from previous step

Parse list of warping fields...

Get dimensions of data...
  141 x 141 x 991 x 1

Apply transformation...

Apply transformation and resample to destination space...
/Users/julien/code/sct/bin/isct_antsApplyTransforms -d 3 -i src_seg.nii -o src_seg_reg.nii -t warp_forward_1.nii.gz warp_forward_0.txt -r dest_seg_RPI.nii -n NearestNeighbor # in /private/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150936.537995-register-bp5l2iyn
Copy affine matrix from destination space to make sure qform/sform are the same.

Done! To view results, type:
fsleyes dest_seg_RPI.nii src_seg_reg.nii &

Registration parameters:
  type ........... seg
  algo ........... bsplinesyn
  slicewise ...... 0
  metric ......... MeanSquares
  iter ........... 3
  smooth ......... 1
  laplacian ...... 0
  shrink ......... 1
  gradStep ....... 0.5
  deformation .... 1x1x0
  init ........... 
  poly ........... 5
  filter_size .... 5
  dof ............ Tx_Ty_Tz_Rx_Ry_Rz
  smoothWarpXY ... 2
  rot_method ..... pca
sct_image -i dest_seg_RPI.nii -o dest_seg_RPI_pad.nii -pad 0,0,10 # in /private/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150936.537995-register-bp5l2iyn

Estimate transformation
/Users/julien/code/sct/bin/isct_antsRegistration --dimensionality 3 --transform 'bsplinesyn[0.5,1,3]' --metric 'MeanSquares[dest_seg_RPI_pad.nii,src_seg_reg.nii,1,4]' --convergence 3 --shrink-factors 1 --smoothing-sigmas 1mm --restrict-deformation 1x1x0 --output '[step2,src_seg_reg_regStep2.nii]' --interpolation 'BSpline[3]' --verbose 1 # in /private/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150936.537995-register-bp5l2iyn

Concatenate transformations...

Parse list of warping fields...

Check file existence...
  OK: dest.nii
  OK: warp_forward_0.txt
  OK: warp_forward_1.nii.gz
  OK: warp_forward_2.nii.gz
/Users/julien/code/sct/bin/isct_ComposeMultiTransform 3 warp_final.nii.gz -R dest.nii warp_forward_2.nii.gz warp_forward_1.nii.gz warp_forward_0.txt # in /private/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150936.537995-register-bp5l2iyn

Generate output files...
  File created: warp_src2dest.nii.gz

Parse list of warping fields...

Check file existence...
  OK: src.nii
  OK: warp_inverse_2.nii.gz
  OK: warp_inverse_1.nii.gz
  OK: warp_forward_0.txt
/Users/julien/code/sct/bin/isct_ComposeMultiTransform 3 warp_final.nii.gz -R src.nii -i warp_forward_0.txt warp_inverse_1.nii.gz warp_inverse_2.nii.gz # in /private/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150936.537995-register-bp5l2iyn

Generate output files...
  File created: warp_dest2src.nii.gz

Apply transfo source --> dest...

Parse list of warping fields...

Get dimensions of data...
  141 x 141 x 991 x 1

Apply transformation...

Apply transformation and resample to destination space...
/Users/julien/code/sct/bin/isct_antsApplyTransforms -d 3 -i src.nii -o src_reg.nii -t warp_src2dest.nii.gz -r dest.nii -n Linear # in /private/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150936.537995-register-bp5l2iyn
Copy affine matrix from destination space to make sure qform/sform are the same.

Done! To view results, type:
fsleyes dest.nii src_reg.nii &


Apply transfo dest --> source...

Parse list of warping fields...

Get dimensions of data...
  52 x 60 x 55 x 1

Apply transformation...

Apply transformation and resample to destination space...
/Users/julien/code/sct/bin/isct_antsApplyTransforms -d 3 -i dest.nii -o dest_reg.nii -t warp_dest2src.nii.gz -r src.nii -n Linear # in /private/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150936.537995-register-bp5l2iyn
Copy affine matrix from destination space to make sure qform/sform are the same.

Done! To view results, type:
fsleyes src.nii dest_reg.nii &


Generate output files...
  File created: template_reg.nii
  File created: data_rpi_reg.nii
  File created: warp_template2data_rpi.nii.gz
  File created: warp_data_rpi2template.nii.gz

Remove temporary files...
rm -rf /var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150936.537995-register-bp5l2iyn
sct_apply_transfo -i template.nii -o template2anat.nii.gz -d data.nii -w warp_template2anat.nii.gz -crop 0 # in /private/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150931.564854-register_to_template-iqdb79td
sct_apply_transfo -i data.nii -o anat2template.nii.gz -d template.nii -w warp_anat2template.nii.gz -crop 0 # in /private/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150931.564854-register_to_template-iqdb79td

Generate output files...
  WARNING: File warp_template2anat.nii.gz already exists. Deleting it...
  File created: warp_template2anat.nii.gz
  WARNING: File warp_anat2template.nii.gz already exists. Deleting it...
  File created: warp_anat2template.nii.gz
  WARNING: File template2anat.nii.gz already exists. Deleting it...
  File created: template2anat.nii.gz
  WARNING: File anat2template.nii.gz already exists. Deleting it...
  File created: anat2template.nii.gz

Delete temporary files...
rm -rf /var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200722150931.564854-register_to_template-iqdb79td

Finished! Elapsed time: 30s

Done! To view results, type:
fsleyes t2.nii.gz template2anat.nii.gz &


Done! To view results, type:
fsleyes /Users/julien/code/sct/data/PAM50/template/PAM50_t2s.nii.gz anat2template.nii.gz &

Note: this warning is not thrown when using -ref template.

To reproduce

  • SCT version: v4.3.0
  • data: sct_testing_data/t2

Also see: http://forum.spinalcordmri.org/t/sct-register-to-template-spurious-warning/441

@jcohenadad jcohenadad changed the title DRAFT-- WAITING FOR MORE CONTENT-- Unnecessary warning WARNING: the resulting image could have wrong apparent results Jul 22, 2020
@jcohenadad jcohenadad self-assigned this Jul 22, 2020
@jcohenadad
Copy link
Member Author

The culprit is here:
https://github.com/neuropoly/spinalcordtoolbox/blob/544a0267c62137e15953e633a750cabe04912fa6/scripts/sct_apply_transfo.py#L312

The variable isLastAffine is suspicious here (might be some legacy code). I will investigate further and clarify the comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user requested Raised by user on the SCT forum/email/GitHub. Be sure to notify them when fixed in a release.
Projects
None yet
2 participants