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")
1 Like