Extract the 2D mask in all three planar directions (the specific voxels that are shown in all three slices)
Convert this 2D region to a contour. (There are algorithms for doing that, so I essentially just need to extract the mask from part 1)
I’ve figured out that slicer.util.getNode(‘1: RTSTRUCT: AutoSS’) will return a vthMRMLSegmentationNode, but I can’t figure out how to traverse it to get the segmentation. Is there an easy way to just export the 3d array of zeros and ones using python?
Examples in the “Nightly” script repository page work with the latest Slicer Preview Release (which I would highly recommend to use, as latest stable is very old now and we added tons of features and fixes since then).
Great. It seems to work in 4.11. Thank you. Just one question though. When I show the Labelmap as well as the segments, they don’t seem to match up completely. (the green segment in the Yellow and Green slices appear much more blocky)
You see two different representations of the same segmentation (closed surface and binary labelmap). The higher the resolution is in the reference geometry (or higher the oversampling factor is) the labelmap, the closer is the match between the two representations. See more information about representations in segmentations here: https://slicer.readthedocs.io/en/latest/user_guide/image_segmentation.html
I believe I understand. Is there an easy way to extract the contour representation from Python? When it exports as a DICOM RT file, I believe this is what gets output as the contour data field (tag 3006,0050). I’m sure it’s another function under segmentations.logic(), but I can’t find anything obvious in the API docs.
I will be doing a transform on the data, and want to extract the contour along a specific plane, in the same format (i.e. a sequence of points) that would be exported to a Dicom RT file.
These are convenience functions for the most useful representations. Most likely you actually want the closed surface representation and not the contours (that is the one you see on screen).
Parallel contours representation is really, really bad way to store a 3D shape, but if you are curious how you can access it: you can do it via segmentation node -> GetSegmentation -> GetSegment-> GetRepresentation.