2d segmentation in 3d slicer

hello,am trying to programme an extension in python that does brain tumour segmentation.
my plan was that i draw a contour around the tumour once in each one of the axes then iterate in each of the slices where the initial contour will shrink until it finds the tumour in each slice
but am really just a beginner and even though i have read many tutorials i still have a hard time understanding how I get to show my segmentation, i understand that i have to create a segment but beyond that, i have no idea how to connect it to the contour that my programme generated and how do i connect it to a labelmap ?
am i sorry for asking a question that is probably basic i would really appreciate the help !!
ps the contour is a numpy array that contains ras coordinates

Lots of solutions have been developed over past few decades for brain tumor segmentation. There are AI models for fully automatic tumor detection and segmentation or tumor segmentation from a region of interest. There are semi-automatic tools, such as “Grow from seeds” or “Local threshold” in Segment Editor module, for segmenting more challenging cases from a single click or a few scribbles in the image. There are also many manual tools that can segment a tumor that you can use to create segmentations from scratch or touch-up automatic segmentation results.

Since this segmentation task has been so widely worked on, for so long, by so many groups, it would be hard to come up with something really new or significantly better. However, if your goal is mainly learning then experimenting with development of a new segmentation algorithm may make sense. If your goal is to solve the clinical task then I would recommend to try the existing tools (and improve them as needed).

yes i would really like to learn and experiment! my idea was to use my own segmentation algorithm for the input images and then maybe use some of the tools that already exist
my question is since my segmentation algorithm is a 2d segmentation is it possible to link them to for example segment editor effect modules since most of them use a 3d segmentation
and can you please explain to me how do i get to show the result of the segmentation what confuses me in the tutorials is the concept of creating a segment and how to link to the results of the algorithm i implemented to it
thank you for your response !

Even if you segment only single slices, those slices still exist in 3D space (their position, orientation, pixel size are still in 3D), so they are still 3D images, they just happen to have a single slice. You could create a separate segmentation for each slice, but most probably it makes your life simpler if you store all the slices in one 3D segmentation. You can access voxels of a segmentation as shown in these examples.

okey thank you so much!!! but now i have this problem so i did write my algorithme and at the end i get a numpy array containing RAS coordinates of the contour of the tumeur, i tried to use the surface cut module because it seemed the one that would most likely allow me to display my segmentation using this code :

 segmentationNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
            #segmentationNode = slicer.vtkMRMLSegmentationNode()

            segmentName = "Tumor"

            import vtkSegmentationCorePython as vtkSegmentationCore

            segment = vtkSegmentationCore.vtkSegment()

            segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
            segmentEditorNode = slicer.vtkMRMLSegmentEditorNode()

            segmentEditorWidget.setActiveEffectByName("Surface cut")
            effect = segmentEditorWidget.activeEffect()

            for p in points:


            segmentationDisplayNode = segmentationNode.GetDisplayNode()
            segmentationDisplayNode.SetSegmentVisibility(segmentName, True)

it’s basically the same code used in the test of the SegmentEditorSurfaceCut.py but i removed segmentEditorWidget.show() because when i executed the code it would show me this

then slicer would bug and stops working so when i removed it i did get the segmentation that i wanted but it took too long almost 10 min
all of this happened with me using slicer 5
the interesting part is when i tried the same code in a better performing computer but has slicer 4 i got this erreur

so what is actually happening why did it work in one version but not the other

Please use a current Slicer version. The error message about vtkVector3d required should not appear for current Slicer versions when you provide a numpy array as input.

ok thank you so much it’s working fine now !

1 Like