qurit / rt-utils

A minimal Python library to facilitate the creation and manipulation of DICOM RTStructs.
MIT License
181 stars 56 forks source link

nifti mask to RT-struct dicom #84

Closed qurit-frizi closed 1 year ago

qurit-frizi commented 1 year ago

I’ve recently designed a model which gives an output mask in nifti format. As I need to have rtstruct created as well, I am leveraging your rt_utils library. Below is the code I wrote for the same. I am getting the rtstruct which seems to be rotated of flipped. The snapshot shows both nifti mask and generated Dicom rtstruct. Just wanted to check if you’ve happened to see such behavior? It would be great if you could share your thought/recommendations to address this issue.

image

image

qurit-frizi commented 1 year ago

I will add a function to solve this issue.

MattAWard commented 1 year ago

Hi @qurit-frizi could I ask what your solution was for this? I'm having the same problem...

rotated_screengrab

pritamrungta commented 1 year ago

Hi @qurit-frizi I'm in a similar situation. Any ideas to fix would be really helpful.

MattAWard commented 1 year ago

Hi @pritamrungta I ended up just rotating the arrays manually...

nii = nib.load(path\to\nii\file) arr = np.array(nii.dataobj, dtype = bool) rot_arr = np.rot90(arr) rtstruct.add_roi(mask=rot_arr, name=roi_name)

iterate this over every mask and it should come out fine

pritamrungta commented 1 year ago

Hi @MattAWard Thanks for the info. I had thought of something in the similar lines, but turns out it isn't a generalized solution (atleast didn't work for my images 😔)

pritamrungta commented 1 year ago

I had to eventually do arr.swapaxes(0, 1) instead of rotation on the data returned by nibabel. Still open for feedback.