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 Python utility functions: ITK image <-> volume node #7094
Conversation
Thank you, this s very useful. Is it only for ITKPython images or SimpleITK as well? Can you make it work for multiple components (such as color images) as well? |
It is only for ITK images, but SimpleITK has methods for converting from and to ITK images. I didn't need multi-component images so far, so I forgot about them. I just started my 2 week vacation, so it will be a while before I can get to it. |
This was adapted from SlicerITKUltrasound extension at 6d7ea98bc329fc52e9c9bfddccc807cf76806fc2. Direct link: https://github.com/KitwareMedical/SlicerITKUltrasound/blob/6d7ea98bc329fc52e9c9bfddccc807cf76806fc2/ITKUltrasoundCommon/ITKUltrasoundCommon.py#L98-L204
d8049c3
to
2532363
Compare
The limitation regarding multi-component images comes from https://github.com/InsightSoftwareConsortium/ITK/blob/v5.4rc01/Wrapping/Generators/Python/itk/support/extras.py#L740 |
This is heavily dependent on a fix in ITK: InsightSoftwareConsortium/ITK#4142
For consistency with the existing API: * Remove the "Node" suffix from "VolumeNode" Consistent with arrayFromVolume, arrayFromModel, ... * Append "Array" to "RASAffine". Consistent with vtkMatrixFromArray, vtkMatrixFromArray, ...) Rename the following functions: * volumeNodeFromITKImage - -> addVolumeFromITKImage * itkImageFromVolumeNode -> itkImageFromVolume * _getRASAffineFromITK -> _getRASAffineArrayFromITKImage - _getITKMetadataFromRASAffine -> _getITKMetadataFromRASAffineArray * updateVolumeNodeFromITKImage -> updateVolumeFromITKImage Also fix spacing and add additional empty lines to improve readability.
…rLayers Update of the Slice viewer is expected to be done at the application level.
Approach adapted from addVolumeFromArray()
Rely on the fact ITK functions vtk_image_from_image and image_from_vtk_image already account for VTL image direction introduced in VTK 9. Adapted from https://discourse.slicer.org/t/installing-itk-python-package-in-slicer-5-1-and-above/25636
This is quite a big and useful simplification! |
Co-authored-by: Dženan Zukić <dzenan.zukic@kitware.com>
This has been tested and is functionally complete. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Remaining:
Summary: Buffer is shared between MRML Volume Node -> ITK Image:
|
Proposed commit message when squashing:
|
@lassoan When you have a chance, could you review the docstings related to memory ownership. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks JC.
Co-authored-by: Andras Lasso <lasso@queensu.ca>
Co-authored-by: Andras Lasso <lasso@queensu.ca>
vtkImageCopy = vtk.vtkImageData() | ||
vtkImageCopy.DeepCopy(vtkImage) | ||
volumeNode.SetAndObserveImageData(vtkImageCopy) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I plan on integrating (by squashing) this afternoon 🚀 and I will be using the following message:
|
Thanks for taking care of this JC! |
This was adapted from https://github.com/KitwareMedical/SlicerITKUltrasound/blob/6d7ea98bc329fc52e9c9bfddccc807cf76806fc2/ITKUltrasoundCommon/ITKUltrasoundCommon.py#L98-L204Update: This was adapted from https://discourse.slicer.org/t/installing-itk-python-package-in-slicer-5-1-and-above/25636