oncoray/mirp

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

alexzwanenburg opened this issue · 2 comments

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

  • MIRP version: 2.2.2

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.

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.