I would like to create a new segment from an existing segment. The idea would be to expand the existing segment in the three directions, adding different margins to each of the directions (e.g. x = 1 mm, y = 2 mm and z = 3 mm) via Python script.
I found the margin effect of the Segment Editor module a possibility, but I think the margin for growth has to be the same in all directions. Am I wrong? Is there any workaround? Thank you in advance.
We use distance map transform for fast grow/shrink (regardless of margin size), which requires isotropic growth. However, you can use morphological operations to grow by different amount along each axis - see Margin effectâs old implementation.
What is the reason you would like to increase the margin by different amount along different axes?
I would like to increase the margin by different amounts along different axes for radiotherapy purposes. During radiation treatments, geometrical uncertainties are taking into account by adding a margin to the target volume. And my question comes up since I want to grow a segment by a margin that is related to the 3D movement of the target volume. I was expected to use the SegmentMorphology module but the SlicerRT extension does not have this module anymore.
Is there any surrogate module for 3D slicer version 4.11?
I tried to use the Margin effectâs implementation to increase the segment margins, but the argument of the SetDilateValue function must be a real number and not a list.
What I really needed is something like the ContourMorphology module of SlicerRT extension. But this module is no longer available in the latest nightly version.
However, I would not recommend to simulate effect of motion by applying anisotropic margin growing along imaging axes, because in general the motion axis directions and magnitudes are not the same as imaging axes, and you cannot simulate rotations at all.
Instead, I would recommend to actually simulate motion. Copy a segment to a separate segmentation node, apply a small transform to that node, copy the segment back to the original segmentation node, and combine it with the existing segment using Logical operators effect. Repeat this with slightly different translations, rotations (a set of representative typical displacements).
The margins that I want to add take into account the 3D movement of the tumour. They were calculated using the B-spline image registration method and the transform module available in 3D Slicer.
I tried to use the aforementioned code but there was no change in the segment. The parameters and the code that I am using are the following:
You need to run self.scriptedEffect.modifySelectedSegmentByLabelmap from inside a segment editor effect (as it is done in SegmentEditorSmoothingEffect.py). If you donât want to put your code into a segment editor effect then you can call its methods from outside.
If you want to write a script that is independent from the Segment Editor then the simplest is to export to labelmap volume, apply the image processing operations on it, then import the modified labelmap volume into the segmentation node. I added a complete example that demonstrates this to the script repository: Script repository â 3D Slicer documentation
Thank you a lot, it worked!
I have another question: is it not possible to expand the segment with a float margin?
As an example, I want to add these specific margins ([3,483 ; 3,494 ; 6,270] mm) but the kernel size must be integer ([3,3,6] mm).
Is there any way to apply the image processing operations with these float margins?
Segmentation is represented as a binary volume, so you the added margin is always a multiple of the spacing (=voxel size) of this volume. You can change segmentationâs internal volume spacing by clicking on the âSpecify geometryâ button next to the master volume selector.
Hi Andras,
I would like to write a python script that use vtk.vtkImageDilateErode3D() function to dilate my segment size independently from the Segment Editor Module of 3D Slicer.
The link you provided in this comment is no longer available, can you please tell me where I would be able to find the complete example you have cited ?
The script repository was moved to Script repository â 3D Slicer documentation and you can find the relevant section by searching for words in the full link. Iâve updated the link in my post above to point to the new location.
Hi, Andras. I wonder how I can find the source code for erodeDilate this class? That is I want to study source code about expanding margin. It want to learn how it is implemented if I have the point coordinate of the geometry.