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

Make SimpleITK dependency optional #497

Merged
merged 19 commits into from
May 11, 2023
Merged

Conversation

yoda-vid
Copy link
Collaborator

Addresses #496. This PR change SimpleITK from a required to an optional dependency. Equivalent support for most SimpleITK functionality has been implemented through ITK-Elastix. I/O operations have been moved into wrapper functions that support both libraries, while #495 added support to ITK-Elastix in image registration functions.

To determine which library to use, the following approach is applied:

  • Functions that take an image as input determine the library based on the type of the image, either sitk.Image or itk.Image
  • If a function does not take an image, the type of other objects is used if available, eg the Transformix filter in registration functions
  • If no arguments are available to specify type, SimpleITK will be used if installed
  • Otherwise, ITK will be used and assumed to be installed

yoda-vid added 18 commits May 10, 2023 12:34
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
- 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.
@yoda-vid yoda-vid added the enhancement New feature or request label May 10, 2023
@yoda-vid yoda-vid added this to the v1.6.0 milestone May 10, 2023
Also, add `itk` install group docs.
@yoda-vid yoda-vid merged commit e7025a7 into support_itk_elastix May 11, 2023
@yoda-vid yoda-vid deleted the sitk_optional branch May 11, 2023 03:52
yoda-vid added a commit that referenced this pull request May 25, 2023
Also, add `itk` install group docs.
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.

1 participant