pyushkevich / greedy

Very fast greedy diffeomorphic registration code
GNU General Public License v3.0
59 stars 16 forks source link

Greedy Issues #42

Closed neurolabusc closed 8 months ago

neurolabusc commented 8 months ago

I am very interested in Greedy due to its speed and ability to use the mutual information cost functions which help for post-contrast scans where scalp and brain intensity can vary a lot from templates. We are dealing with huge clinical datasets and tools like FLIRT are robust but too constrained while tools like FNIRT do not use sensible cost functions for our use case.

  1. I am using Greedy on my M2 Mac as installed with ITKsnap Greedy Version 1.2.0 Release date: Jan 12, 2021 Compile date: Sep 28, 2023 GIT branch: HEAD GIT commit: 9f1fcd8e82261d262eb087cdeaae2e66352755b2 GIT commit date: 2022-01-07 06:22:51 -0500
  2. I am unable to build from source, this seems to be a common problem with C++ on the latest versions of MacOS, though I do not think this is involved with my issues
  3. I am working with a sample dataset that is anonymized and I have sent a link to your email.
  4. The sform and qform are already close, so one would expect -ia-identity would work, but this creates an error (IFLAG= -1 LINE SEARCH FAILED) and nonsense images, so I use -ia-image-centers
    1. With -ia-image-centers the results of the affine are very poor for this example. The new NIfTI image does not seem to inherit the SForm and QForm of the fixed image (e.g. origin is outside of volume, rather than at anterior commissure)
    2. The silent mode (V 0) is indeed silent for the affine stages, but still generates per iteration messages for the nonlinear stages.

Silent with mutual information cost function

fixed=template.nii.gz
moving=flair.nii.gz

greedy -V 0 -d 3 -a \
    -m NMI \
    -i $fixed $moving \
    -o affine.mat \
    -ia-image-centers  -n 100x50x10

greedy -V 0 -d 3 \
  -rf $fixed \
  -rm $moving affineOnly.nii.gz \
  -r affine.mat

greedy -V 0 -d 3 \
    -m WNCC 2x2x2 \
    -i $fixed $moving \
    -it affine.mat \
    -o warp.nii.gz \
    -oinv inverse_warp.nii.gz \
    -sv -n 100x50x10

greedy -V 0 -d 3 \
  -rf $fixed \
  -rm $moving resliced.nii.gz \
  -ri LABEL 0.2vox \
  -r warp.nii.gz affine.mat

Direct from quick start (verbose, default cost function)

fixed=template.nii.gz
moving=flair.nii.gz

greedy -d 3 -a \
    -m NCC 2x2x2 \
    -i $fixed $moving \
    -o affine.mat \
    -ia-image-centers -n 100x50x10

greedy -d 3 \
    -m NCC 2x2x2 \
    -i $fixed $moving \
    -it affine.mat \
    -o warp.nii.gz \
    -oinv inverse_warp.nii.gz \
    -n 100x50x10

greedy -d 3 \
    -rf $fixed  \
    -rm $moving resliced.nii.gz \
    -ri LABEL 0.2vox \
    -r warp.nii.gz affine.mat 
pyushkevich commented 8 months ago

Hi Chris,

I think the issue is with ITK NIFTI IO and qform/sform. When I load the template and flair images from your example in ITK-SNAP, the template has wrong orientation and the flair is nowhere.

[image: image.png] I think that ITK might not know about flags NIFTI_XFORM_MNI_152 and NIFTI_XFORM_ALIGNED_ANAT when setting the DirectionMatrix of the ITK image. I don't remember seeing these flags in the past. For sure Greedy sees the images exactly how ITK-SNAP sees them, so this is the root of the problem.

If I match the images by centers (same as -ia-image-centers), they are still off:

[image: image.png] But if I replace the header of the template using c3d template.nii.gz -orient LPI -o template_lpi.nii.gz then after aligning image centers, the initialization is better.

[image: image.png] Finally, I can do registration in ITK-SNAP (which is the same as Greedy rigid/affine)

[image: image.png] Thanks, and hope this helps! Thank you for the heads up about silent mode issue.

Paul

On Tue, Nov 14, 2023 at 2:46 PM Chris Rorden @.***> wrote:

I am very interested in Greedy due to its speed and ability to use the mutual information cost functions which help for post-contrast scans where scalp and brain intensity can vary a lot from templates. We are dealing with huge clinical datasets and tools like FLIRT are robust but too constrained while tools like FNIRT do not use sensible cost functions for our use case.

  1. I am using Greedy on my M2 Mac as installed with ITKsnap Greedy Version 1.2.0 Release date: Jan 12, 2021 Compile date: Sep 28, 2023 GIT branch: HEAD GIT commit: 9f1fcd8 https://github.com/pyushkevich/greedy/commit/9f1fcd8e82261d262eb087cdeaae2e66352755b2 GIT commit date: 2022-01-07 06:22:51 -0500
  2. I am unable to build from source, this seems to be a common problem with C++ on the latest versions of MacOS https://apple.stackexchange.com/questions/458062/unable-to-find-include-file-on-newly-updated-macosc-c/459037#459037, though I do not think this is involved with my issues
  3. I am working with a sample dataset that is anonymized and I have sent a link to your email.
  4. The sform and qform are already close, so one would expect -ia-identity would work, but this creates an error (IFLAG= -1 LINE SEARCH FAILED) and nonsense images, so I use -ia-image-centers
  5. With -ia-image-centers the results of the affine are very poor for this example. The new NIfTI image does not seem to inherit the SForm and QForm of the fixed image (e.g. origin is outside of volume, rather than at anterior commissure)
  6. The silent mode (V 0) is indeed silent for the affine stages, but still generates per iteration messages for the nonlinear stages.

Silent with mutual information cost function

fixed=template.nii.gz moving=flair.nii.gz

greedy -V 0 -d 3 -a \ -m NMI \ -i $fixed $moving \ -o affine.mat \ -ia-image-centers -n 100x50x10

greedy -V 0 -d 3 \ -rf $fixed \ -rm $moving affineOnly.nii.gz \ -r affine.mat

greedy -V 0 -d 3 \ -m WNCC 2x2x2 \ -i $fixed $moving \ -it affine.mat \ -o warp.nii.gz \ -oinv inverse_warp.nii.gz \ -sv -n 100x50x10

greedy -V 0 -d 3 \ -rf $fixed \ -rm $moving resliced.nii.gz \ -ri LABEL 0.2vox \ -r warp.nii.gz affine.mat

Direct from quick start (verbose, default cost function)

fixed=template.nii.gz moving=flair.nii.gz

greedy -d 3 -a \ -m NCC 2x2x2 \ -i $fixed $moving \ -o affine.mat \ -ia-image-centers -n 100x50x10

greedy -d 3 \ -m NCC 2x2x2 \ -i $fixed $moving \ -it affine.mat \ -o warp.nii.gz \ -oinv inverse_warp.nii.gz \ -n 100x50x10

greedy -d 3 \ -rf $fixed \ -rm $moving resliced.nii.gz \ -ri LABEL 0.2vox \ -r warp.nii.gz affine.mat

— Reply to this email directly, view it on GitHub https://github.com/pyushkevich/greedy/issues/42, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJPEW7C7HWNZIIVH4CN4ODYEPDBFAVCNFSM6AAAAAA7LLKSS6VHI2DSMVQWIX3LMV43ASLTON2WKOZRHE4TGNBUG43DAOI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

neurolabusc commented 8 months ago

Paul

Your intuition is correct, if I change the sform_name to Scanner Anat for both images I can use -ia-identity and get a nice result with -m NMI.

Thanks for a terrific tool!