Improve segmentation : "Paint" and "Erase" (or "Scissors") effects in Segment Editor or Sphere brush?

Good afternoon,

First of all, thanks a lot to the one that is going to read my message !
I am currently an intern doing the segmentation of an organ on 3D Slicer (I am so new on 3D Slicer).
However, I have some problems by improving this segmentation…

From scanner volume in dicom and after image treatments, I have a “vtkMRMLScalarVolumeNode” which represents my organ segmented in white with a grey background.
I would like to add some pixels that have been erased by mistake to my segmentation and also erase some pixels that are in my segmentation by mistake…
After trying different techniques, I think that “Segment editor” with “Paint” and “Erase” could do the job perfectly.

However, these two effects don’t have any “self().onApply()” function so I can’t set the result in my segmentation.
I have tried so many different ways to do this but unfortunately nothing works…
Currently, I have written that on my python script :

effect = segmentEditorWidget.activeEffect()
effect.SetParameter(“Paint, sphere”, “1”) # Agir en 3D sur image
segmentEditorWidget = None

However, I don’t succeed in :

  • Open “Segment Editor” as a little window in the foreground with my module extension in the background
    (my code generates that the “Segment editor” window appears as fast as it disappears…)
  • “Paint” on my segmented organ
  • Save the paint pixels as if they become part of my segmented organ
  • Get my new segmentation upgraded

As a consequence, I have the same problems with “Erase” and “Scissors” effects…
I hope that I have been clear a little bit
It would be so grateful if someone could help me !
Thanks a lot in advance

You can embed a segment editor widget directly into your module’s user interface.

You can use the segment editor widget to paint (activate the effect then draw in any of the views).

If you want to paint/erase at a certain position using Python script, you can create a sphere-shaped segment as shown in this example. Then use logical operators effect to add (paint) or subtract (erase) this segment from the segment that you would like to modify.

1 Like

Good morning,

Thanks a lot for your answer !
However I still have some difficulties to implement…

On my python script I have written :

            segmentationNode = slicer.vtkMRMLSegmentationNode()
	    segmentationNode.CreateDefaultDisplayNodes() # only needed for display
	    addedSegmentID = segmentationNode.GetSegmentation().AddEmptySegment("Foie")
	    lm =
	    for sliceViewName in lm.sliceViewNames():
	      sliceWidget = lm.sliceWidget(sliceViewName)
	      view = lm.sliceWidget(sliceViewName).sliceView()
	      sliceNode = view.mrmlSliceNode()
	      sliceLogic =
	      compositeNode = sliceLogic.GetSliceCompositeNode()
					## Setup background volume
					## Setup foreground volume
					## Changer l'opacite
	    editorWidget = slicer.modules.segmenteditor.createNewWidgetRepresentation()
	    segmentEditorNode = slicer.vtkMRMLSegmentEditorNode()

So :

  • I create my node ‘Foie’ which is used to paint
  • I am able to get a little window Segment Editor which appears
  • I use the effect “paint” in some areas of my image vtkMRMLScalarVolumeNode (with the “Edith in 3D views”)

But then, I don’t know how to implement “put what is painted as white pixels in my vtkMRMLScalarVolumeNode” just to be able to create only one image which compiled my previous segmentation + my additionnal adjustements with paint (or erase, of course)

I have tried to export segments (that is to say my ‘Foie’ node) but after I don’t know how to put everything together…
Moreover, I would love being able to do everything from my widget extension without going in the different modules on 3D Slicer manually…

Do you know how can I do that, what kind of code I have to add ?
I just add that the areas that I want to paint (or erase) are not previously selected, I have to do that “visually” so it is different from one scanner to another

Thanks a lot in advance

Good afternoon,

After this second day of only looking for the segment editor tool with “paint” and “erase”, I have maybe another idea that could be easier (I hope so because I despair to succeed in doing this improvement on my image…) :

  • Create a sphere brush
  • Click with the sphere brush on my image vtkMRMLScalarVolumeNode
  • Get the voxels values that I have clicked on
  • Set these values to 255 so that they have the same value as the pixel of my organ segmented
    However I haven’t find how to do this even if I have read lot and lot of codes (such as and so on)

Do you think this is a better idea to get my result ?
Do you know some parts of code that I can use to do this ?
Sorry if this is very easy to answer but it seems to me that I don’t see the end of this road…

Thanks a lot for your help


I often mouse over a target area and look at the voxel values displayed in the data probe area in the lower left of the slicer window, when I need to decide on values.


I agree with you it is possible to do that except that I want to set lots of pixels at a certain value for painting more than my organ segmented (because it misses some voxels after my image treatments) or for erasing some voxels.
That’s why I think it is important to succeed in creating a “sphere brush” in order to get more than one voxel at a time
This is to improve and get a perfect organ segmented (because after I measure distances, volumetric data…and everything is already done, I have just this part that I don’t manage to do)

Thanks a lot for your help !