platipy icon indicating copy to clipboard operation
platipy copied to clipboard

Structure orientations inverted when converting nifti to RTSS

Open indranilmallick opened this issue 1 year ago • 2 comments

Hi, thanks for developing a great tool. I have converted a set of nifti structures to rtss using your code. The nifti structures were generated from a CT using TotalSegmentator. When I visualize the nifti CT series and the nifti structures on 3D Slicer, it looks good. nifti_normal

However, after conversion to RTSS using Platipy (which otherwise went very smoothly), the structures are inverted (supine to prone). upsidedown

I don't know why this is happening and how to fix this.

indranilmallick avatar Jun 18 '23 14:06 indranilmallick

Hi @indranilmallick, thanks for opening up this issue.

It seems like some geometric information has been lost/changed somewhere along the conversion process.

To help narrow down the cause of this problem could I ask for some additional information:

  1. Is the CT scan in the second screenshot the converted image (NIfTI) or original DICOM?
  2. Have you noticed this problem for one case or multiple?
  3. Could you run this code snippet below and paste the output:
import SimpleITK as sitk
img = sitk.ReadImage("name of CT.nii.gz")
structs = sitk.ReadImage("name of SS.nii.gz") # just pick any of the contours since they all look flipped

print("CT:", img.GetDirection())
print("SS:", structs .GetDirection())

I'll also just note that the conversion tool is a wrapper around rt_utils (https://github.com/qurit/rt-utils), so it might be helpful to post this issue there.

Hope we can help fix this! 🤖

rnfinnegan avatar Jun 20 '23 03:06 rnfinnegan

Hi, I could fix it by first reading the nifti file with nibabel, then rotating the numpy array by 90 and then using rt-utils to write it to a dicom rtss. That solved it.

indranilmallick avatar Jun 23 '23 00:06 indranilmallick