Creating mask from rtstruct

Hi,

I’m just beginning with SimpleITK and all other medical image related software. I’m actually loading some dicom series and their corresponding RTSTRUCT contours in python, manually with numpy, because as far as i know there’s no support for loading RTSTRUCT into SimpleITK. Then i convert those contours to a mask, then load both image serie and mask into SimpleITK and from that into Pyradiomics.

My problem is with my contour to mask conversion, i’ve written a first approach simple algo, but it does not work well at all. I’m wondering if there’s some filter or other feature in SimpleITK helping with that task. I guess that would imply creating kind of a mesh from the 3d contour, maybe softening it, and pass and algorithm to determine interior voxels to it. Is there such a feature in SimpleITK? Or any other approach anybody can recommend?

Thank you in advance.
Roi

Yeah, scan converting complex polygons into pixels is a tricky, non-trivial process. I wrote some python code do to it that you can see here:

It uses VTK’s vtkPolyDataToImageStencil filter to convert polyline to image stencils.

1 Like

Thanks a lot! i’ll try and read your github repo.
EDIT: Still fighting with this, i seem to get unconnected slices, have to take a look.

Anyone knows any simpleitk approach?

Hey my team and I actually wrote a small Python package called RT-Utils that I think can help you out! The package will allow you to load a 3D numpy binary mask for any contour within an RTStruct and deal with things such as holes and disconnected components in contours automatically. You can find the package here https://github.com/qurit/RT-Utils and install via pip. Your use case would fall under the Loading an existing RT Struct contour as a mask section and example code would be as simple as:

mask_3d = rtstruct.get_roi_mask_by_name("ROI NAME")
4 Likes

The code shown by Asim is great and very useful! If you would like something else to parse through folders of DICOM, or are working with non-axially acquired MR images, please also check out our code here: GitHub - brianmanderson/Dicom_RT_and_Images_to_Mask: Various utilities created to help with the interpretation of dicom images/RT Structures, specifically into NumPy masks and Nifti images. Some necessary steps for deep learning
The technical note for the program is here: Simple Python Module for Conversions Between DICOM Images and Radiation Therapy Structures, Masks, and Prediction Arrays - ScienceDirect