Skip to content
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

RTStruct FrameOfReferenceUID is not matching with the reference CT #29

Closed
jinkoo2 opened this issue Aug 19, 2021 · 8 comments · Fixed by #65
Closed

RTStruct FrameOfReferenceUID is not matching with the reference CT #29

jinkoo2 opened this issue Aug 19, 2021 · 8 comments · Fixed by #65

Comments

@jinkoo2
Copy link

jinkoo2 commented Aug 19, 2021

Hi my code is simple, like below. It runs fine, but I see the FrameOfRefernceUID in the output file (RS.new.dcm) is difference from the FrameOfRefceUID of the reference CT dicom series. So, I cannot import the RS file to my application. Is this a bug?... any suggestion would be greatly appreciated. Thanks! Jay.

from rt_utils import RTStructBuilder
import numpy as np
import SimpleITK as sitk
from os.path import join

ct_path = 'U:\\temp\\New folder\\ct_dicom'
mask_mhd = '.\\data1\\00001500\Rectum.mhd'
out_rs_path = 'U:\\temp\\New folder\\RS.new.dcm'

# read segmentation image
mask_img = sitk.ReadImage(mask_mhd)

# convert to np array
mask_np = sitk.GetArrayFromImage(mask_img)

# reorder from z,y,x->y,x,z (donno why... but this worked ok for my application)
new_shape = (mask_np.shape[2], mask_np.shape[1], mask_np.shape[0])
mask_np_trans = np.empty(new_shape, dtype=bool)
for k in range(mask_np.shape[0]):
    for j in range(mask_np.shape[1]):
        for i in range(mask_np.shape[2]):
            mask_np_trans[i,j,k] = bool(mask_np[k,j,i])

# create new RT Struct. 
rtstruct = RTStructBuilder.create_new(dicom_series_path=ct_path)

# add mask
rtstruct.add_roi(
  mask=mask_np_trans, 
  color=[255, 0, 255], 
  name="Rectum"
)

#save
rtstruct.save(out_rs_path)
print('done')
@jinkoo2
Copy link
Author

jinkoo2 commented Aug 19, 2021

Changing the first code block to the following made my code start working... code repo not updated at github... donno how...

From

def add_refd_frame_of_ref_sequence(ds: FileDataset, series_data):
    refd_frame_of_ref = Dataset()
    refd_frame_of_ref.FrameOfReferenceUID = generate_uid() # TODO Find out if random generation is ok
    refd_frame_of_ref.RTReferencedStudySequence = create_frame_of_ref_study_sequence(series_data)
    ...

To

def add_refd_frame_of_ref_sequence(ds: FileDataset, series_data):
    refd_frame_of_ref = Dataset()
    refd_frame_of_ref.FrameOfReferenceUID =  getattr(series_data[0], 'FrameOfReferenceUID', generate_uid())
    refd_frame_of_ref.RTReferencedStudySequence = create_frame_of_ref_study_sequence(series_data)
    ...

@asim-shrestha
Copy link
Contributor

Hi Jinkoo, when we first created this library, we made the assumption that any ROI's added would be contained within a new FrameOfReferenceUID, not an existing one. I'm thinking as a fix, we could add another parameter to the RTStruct builder in order for users to input a their own frame of reference uid. Otherwise, it would just create a new one. What do you think?

@jinkoo2
Copy link
Author

jinkoo2 commented Aug 26, 2021 via email

@locastre
Copy link

locastre commented Feb 5, 2022

I'm writing to second the opinion of the OP. In our experience, when an RTSTRUCT is created it needs to be associated with a "parent" DICOM image set. It is customary, and multiple image viewing platforms rely on the convention, that the RTSTRUCT will have the same FrameOfReferenceUID as the parent DICOM series the contours are to be displayed over.

@xfuren
Copy link

xfuren commented Apr 26, 2022

This commit solved my problem, too.
Please merge it into main.
Is there any reason to use a random FrameOfReferenceUID instead of the real referenced one?

@jforthomme
Copy link

I agree with @locastre and @jinkoo2 , this is how CTs and structure sets are usually linked in DICOM. Most treatment planning systems will complain if those 2 tags don't match.

@asim-shrestha
Copy link
Contributor

Thanks for the input folks! Will ensure this gets pushed in later today

@jinkoo2
Copy link
Author

jinkoo2 commented Jan 9, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants