pyplati / platipy

Processing Library and Analysis Toolkit for Medical Imaging in Python
https://pyplati.github.io/platipy/
Apache License 2.0
103 stars 24 forks source link

RTStruct to NIFTI generates missing slices for non-constant z-axis #165

Open MLK97 opened 1 year ago

MLK97 commented 1 year ago

I am working on a set of MR images with RTStructs. The protocol for generating those MR images is in such a way that the patient does not lie parallel but is slightly rotated in the z-axis (of the RTStruct). I was told this is in order to have the actual organ of interest parallel to the z-axis. So therefore there is a difference between the patient z-axis and that RTStruct z-axis.

When converting this RTStruct to Nifti or a mask with either platipy.dicom.io.rtstruct_to_nifti.convert_rtstruct or platipy.dicom.io.rtstruct_to_nifti.transform_point_set_from_dicom_struct this leads to missing slices/holes in the generated mask.

Rectum Nifti Mask

I assume this might be caused from the assumption during the mask generation that the z-index is constant inside each closed contour defined in the RTStruct.

https://github.com/pyplati/platipy/blob/3432ae613cb893c1fefc2ab8b0e23243e602952e/platipy/dicom/io/rtstruct_to_nifti.py#L182-L188

I'll try to check if this behavior might be avoided if one removes this generalization but would also be happy to hear your thoughts about this.

pchlap commented 1 year ago

Hi @MLK97, thanks for the bug report.

Yes I believe you are correct in the assumption that this is caused by the z-index not being constant per slice. One option to fix this would be to rotate the contour points to an orientation where the z-index is constant. Then the resulting mask could be rotated back to the image space.

I don't have any data to be able to investigate this. If you happen to have an MRI image along with an RTSTRUCT file of a phantom or similar and you'd be happy to share this I could take a look. If not I can have a chat to our MR Radiographers to see if someone at our centre could scan a phantom with this kind of orientation (not sure if/when that would be possible though).

MLK97 commented 1 year ago

Hey @pchlap,

sorry for the late reply, we did some further investigation into the dataset to make sure that the problem is really caused by this rotation problem and it surprisingly turned out that there instead were a lot of missing contour slices from the manual delineation process itself. So while we are sure that for a lot of the studies, we looked at, the actual error stems from the manual delineation process and not from the rotation, it might as well be that there are studies that have an additional error that is caused by the rotation of the scan. I will do some further control on my dataset and compare it to a Matlab package that has a rotation matrix built-in and get back to you in case I find anything. If I don't find anything, I would close this issue unless you think it is worthwhile keeping this visible in case of other cases where this might become an issue in the conversion process.

pchlap commented 1 year ago

Thanks for the update @MLK97, that's very interesting. Yes please do let me know what you discover.

I'll leave this issue open for now to give others a chance to leave their input in case they have experienced similar issues.