Python Script for segment growing and Logical operations

Hi all,

I want to write a python code to grow a segment margin. (need to overlap and also grow in to a specified intensity only)

Then i want to subtract the newly grown segment from the original.

How do i do that ?

I tried to look for simpleITK documentation at but it is not working.

It would be great if some

Thank you

These examples should help you getting started:

Thank you Prof Lasso,

I looked at them also but i could not find how to grow and subtract segments.

Is there any documentation for simpleITK like a handbook available ?

i looked at but the link is not working.

There are no examples for using all the effects, but you can start from those examples and just change the effect name and input parameters if you want to use different effects.

You can post questions about SimpleITK to the ITK forum.

1 Like

Thank Prof Lasso. I will try to work with this information.

I have a question slightly related to this. I am referring to the code in this link.

To set the active effect and change some parameters this following code is used:

# Thresholding
effect = segmentEditorWidget.activeEffect()

I see the setParameter() method takes a string input (to select the parameter) and a value input (to define the value of that parameter). Is there any documentation anywhere that lists what the names of all the parameters are for a given active effect? I have been just trying to guess what the parameters are called but not having much luck.

I think I answered my own question.

Found this link:

I found the slicer segment editor effect code in the Slicer core code here

I should be able to find the parameter names which I need by sifting through the code.

1 Like

It would be nice to extract the parameter names from the code and present it in a developer documentation page instead of requiring developers to mine it from the source code.

However, for this we would need much tighter integration between source code and documentation. Currently they are stored in two separate systems (svn and wiki), but soon both will be managed in git. When the transition completes, in a few weeks or worst case months, we can start working on improving the developer documentation with such details.

1 Like

Thank you @Juicy and @lassoan

This has been super helpful for me as i try to work on the code. What i was trying to ask for was what @Juicy asked even though i failed to put it in that way, instead of having to come back here and asking is there any documentation related to 3DSlicer python interactor that gives functions/methods and what inputs they take etc… so we can easily go through and write the code…I find good documents on C++ but i don’t know it.

The PerkLab Scripting and module development tutorial contains links to API documentation sites and example of how to use Python help command to get Python-style manual for a specific command or class in the console.

I see how argument type information specified in C++ may look alien to Python developers, but it is just a small syntax difference that can be “translated” by a number of simple rules. I give a few examples here how a mapping could look like and if you find it useful then let me know and I’ll consider creating a more comprehensive documentation page:

C++ Python
nullptr None
Q(some-class-name)* qt.Q(some-class-name) QWidget* qt.QWidget
Qt::(some-type) qt.Qt.(some-type) Qt::WindowFlags qt.Qt.WindowFlags
qMRML(some-class-name)* slicer.qMRML(some-class-name) qMRMLTableWidget* slicer.qMRMLTableWidget

Syntax differences:

  • type before the method name specifies what type of data the method returns; void means that the method does not return any data
  • const before an argument type means that the called method will not change that input argument
1 Like