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

Add support for ITK-Elastix #501

Merged
merged 39 commits into from
May 25, 2023
Merged

Add support for ITK-Elastix #501

merged 39 commits into from
May 25, 2023

Conversation

yoda-vid
Copy link
Collaborator

Fixes #496. Adds support for ITK-Elastix as an alternative to SimpleITK and its Elastix integration. This PR will merge in the feature branch tracking sub-PRs for this task.

yoda-vid added 30 commits May 10, 2023 12:33
Quote type hints with Elastix-specific classes.
…with Elastix

Support Elastix-based image registration using the ITK-Elastix package as an alternative to using SimpleITK with Elastix. Add `itk-elastix` as a package dependency and default to using it in the `register_duo` function. Provide library functions to convert among SimpleITK Image, ITK Image, and NumPy arrays.
Accept Transformix filters provided from ITK-Elastix in addition to SimpleITK. Detect the appropriate library to use based on the given filter type. Add a library method to support conversion from either SimpleITK or ITK Image objects to NumPy arrays and vice versa, and add support for replacing the array in an ITK Image.
Now that Elastix can be accessed through ITK-Elastix rather than the custom SimpleITK build that contains Elastix, use the standard SimpleITK install instead of the custom wheel.
Accept ITK Image instances in `register_duo`, which also serves as a flag to use ITK-Elastix for registration. Continue to accept SimpleITK Image instances, using SimpleITK for registration if Elastix is enabled or converting the images to ITK Image types. Also, allow images given to the SimpleITK and ITK conversion functions to be None.
Accept ITK Image instances in `register_repeat`. Continue to accept SimpleITK Image instances, converting them to ITK Images if the Transformix filter is from ITK.
- Use the data class to manage image casting
- Add fields for masks
- Add a function to update all non-None fields
- Apply to SimpleITK to ITK conversions during image registration
- Check for presence of at least one registration library before any image conversions during registration
- Refactor to use the import error message function
- Add docstring note on image type conversions and registration libraries used
The Transformix filter appears to require initialization with a 3D image to support 3D images (see InsightSoftwareConsortium/ITKElastix#56). Re-set-up the Transformix filter with the moving image when applying repeat transformations.
The translation parameters have been extracted for overlaying single planes, but this overlay has been deprecated and commented out. Group and comment out this extraction with the overlay. This change will no longer save the translation parameters, but they are only a subset of the transformation, and the full transformation is still saved in the working directory.
Replace the ITK-Elastix-based main registration has used the functionally oriented interface with the object-oriented access for consistency with SimpleITK and access for Transformix (both SimpleITK and ITK-Elastix). This change also allows common filter functions to be applied for both SimpleITK and ITK-Elastix.
Cast images individually to their appropriate type:
- Float for the main images
- Unsigned character for the masks
…ence

For backward compatibility, change the default target conversion from NumPy arrays to SimpleITK Image instances if the library is present.
Unlike SimpleITK, ITK requires the multichannel setting to be set explicitly and returns a type that is not a subclass if `itk.Image`. Attempt to auto-detect multichannel images for ITK based on number of dimensions and include ITK vector images when converting ITK images to NumPy arrays.
Now that NumPy conversions have been fixed in SimpleITK (SimpleITK/SimpleITK#1687), remove this type mapping.
Surround SimpleITK type hints in quotes to avoid errors on load.
ITK requires world metadata to be set with the same shape as the current values. Adjust these values when replacing the NumPy array in a ITK or SimpleITK Image instance.
- Convert to list if a tuple
- Convert docstrings to type hints
- Add unit tests
- Add a library function that replaces as many values as possible by another sequence
- Apply this function to replacing metadata in a SimpleITK/ITK Image instance
To support ITK in addition to SimpleITK when converting between arrays and image instances, use the conversion function instead.
Refactor transferring world info metadata from the function to replace the `Image` array to the world info matching function to make this transfer more generally available.
Support ITK in addition to SimpleITK type images.
Refactor measuring overlap between binarized images into the measure overlaps function to reduce redundancy and generalize support for SimpleITK and ITK images
- Allow using ITK in place of SimpleITK
- Convert more docstring types to type hints
- Showing the image is only supported in SimpleITK and not extended to ITK here
- Add a library function to load images based on the available library, using SimpleITK if it is available
- Use this function when loading images with alternate extensions
- Also apply to `edge_seq` and make SimpleITK optional for this module
Check for presence of SimpleITK before using it to show images. Applied to remaining instances of `sitk.Show`.
- Add an image write wrapper function to support both libraries
- Apply to `export_rois`, removing SimpleITK import there
yoda-vid added 5 commits May 11, 2023 11:52
- Support ITK type hint for labels image in config
- Catch import error for SimpleITK type hint
- Add an install group for SimpleITK and make this dependency optional
- Use the custom pre-built SimpleITK with Elastix dependencies in this install group to continue supporting this registration pipeline
- Add doc for this install group
- Alphabetize individual install groups
When ITK-based dependencies were added as an alternative for SimpleITK, both libraries were made to be optional for core functionality. Move the these ITK-based dependencies into an `itk` install group, which will also be included in the `most` and `all` groups. Also, make the SimpleITK group constant's name consistent with the other extra installs constants.
Also, add `itk` install group docs.
@yoda-vid yoda-vid added the enhancement New feature or request label May 23, 2023
@yoda-vid yoda-vid added this to the v1.6.0 milestone May 23, 2023
yoda-vid added 4 commits May 24, 2023 11:21
Check for the package before setting this threader.
- Fall back to groupwise registration using ITK-Elastix if SimpleITK is not available
- Support either library for reading or writing transformation files
Remove this function as it has not been used and can be replaced by other existing functions.
@yoda-vid yoda-vid merged commit 0b62414 into master May 25, 2023
@yoda-vid yoda-vid deleted the support_itk_elastix branch May 25, 2023 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support ITK-Elastix as an alternative to SimpleITK with Elastix
1 participant