Batch segment creation - macro

Dear all,

Is there a way to instruct segment editor to do the following operations with one click ? Let me offer an example:

I have the segment LUNG which comprises the whole lung volume.
I would like with one click to order Slicer do the following operations:

a) Create a new segment “Newsegment”
b) Use the Threshold tool to populate a new segment with the intervals -1000HU-100HU inside LUNG without overwriting other segments.

Is it there an easy way to do it?

Thanks a lot for your help.

It should be pretty easy to do with some python scripting. See lots of examples here:
https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#How_to_run_segment_editor_effects_from_a_script

Once you have a script, if you want it to have its own effect button, then it’s easy to add too.

2 Likes

Hello, thanks for helping and sorry for bothering. I’m really new to python and only have experience on HTML coding. But I’m willing to learn.
I got to the point where I created a test module using the extension manager.
I found a useful example here https://gist.github.com/lassoan/5ad51c89521d3cd9c5faf65767506b37

But I cannot get past the way to use the current volume that I have selected in the drop down menu.
How do I access it in the script?

I need to replace the following line

masterVolumeNode = SampleData.SampleDataLogic().downloadCTChest()

with something that fills the variable masterVolumeNode with the volume currently selected in the InputVolume dropdown menu.
Couldn’t find easy answer until now

These are explained in detail, with examples in Slicer programming tutorials, such as this.

1 Like

Thanks Andras, your work is amazing.
Just wanted to let you know that thanks to your indications I am getting super-close to creating what I need.