oncoray / mirp

Medical Image Radiomics Processor
https://oncoray.github.io/mirp/
European Union Public License 1.2
38 stars 11 forks source link

Error when attempting to use a NIfTI file with DICOM RTSTRUCT file #89

Closed alexzwanenburg closed 1 month ago

alexzwanenburg commented 1 month ago

Expected behaviour

Segmentations from DICOM RTSTRUCT files can be combined with NIfTI images. MIRP supports this as long as the world-coordinates have the same reference.

Observed behaviour

MIRP fails to register RTSTRUCT segmentations that do not spatially coincide with the NIfTI voxel grid, and throws an error that mentions that SwigPyObjects cannot be pickled. This happens when attempting to create a copy of the image object. This copy is then used as basis for generating the image space for the mask itself.

Specifications

alexzwanenburg commented 1 month ago

The error is caused because the metadata attribute of the ImageFile-derived object contains a reference (as an ITK-specific class) to the NIfTI file header. This attribute cannot be pickled upon creating a deep copy of the object in MaskDicomFileRTSTRUCT._create_image_from_contour.

However, it is not necessary to create a direct copy of ImageFile object. The only aspects of interest are the attributes related to spatial positioning. Hence, the issue can be circumvented by creating a dummy BaseImage object and only copying parameters related to spatial positioning.

alexzwanenburg commented 1 month ago

Alternatively, and preferably, override the copy method in ImageITKFile to remove metadata before making a deep copy. This prevents this issue from occuring elsewhere where a copy of the image file object is required or might be required in the future.