Looking for Fast Marching segmentation Python Batch Script

Hello,
I work for DICOM Director, a company that uses slicer modules such as Grow From Seed and Thresholding in our own platform, outside of the Slicer UI. Currently I am looking to integrate the Fast Marching segmentation method into our system. I have the Fast Marching python code, here, that works within the 3D Slicer UI, but I am looking for a script of this module that we can use on our own.

Does anyone know how to apply this existing code through python, in order to evoke the method externally (Python or Batch script)? As I said, we know how to call Grow From Seed from external sources, but are looking to do the same with Fast Marching.

Looking at the UI code available does anyone know where it is catching the inputs from the user? For example, we know that the Grow From Seed method accepts seeds as an array of coordinates.

I have already checked here but I do not think this is what I am looking for.

Any information or a direction to look in would be a huge help.

Thank you in advance!
-Ethan

It’s great that you find Slicer useful in your product.

Fast marching can be used the same way as Thresholding and Grow from seeds. You generate preview by calling onMarch, you can then adjust the volume, and when you like the result, write it to the segment by calling onApply.

Note that Fast marching method is not that great, because it is prone to leaking and you cannot do easily fix the leak (you need to adjust your segment and/or lower the volume). Instead, you will find that Local thresholding effect works much robustly. It requires just an intensity range and a single point as input.

Thank you @lassoan. Do you know how I might begin to write an external script for this module though? I was told that you can take what you are doing in the interactive tool and run it as the batch scripting, but I am not sure how to get a batch script from this.

Do you mean that my script should include the parts of the code I have linked that define onMarch and onApply? I’m new to script writing so I’m confused about the steps of taking the code that works within Slicer and altering it to work within our own portal. Again, any suggestion or resources would be a huge help.

I would also like to do the same thing for the Watershed method, if it is possible. Is this the correct code to start with if I would like to create a script for external use?

You can look at the source code of a segment editor effect to see its API, but the easiest to get started is to use the segmentation examples in the script repository. For example, brain tumor segmentation using grow from seeds effect example shows how to use “Grow from seeds” effect, which has almost the same API as Watershed (probably it is enough to replace the “Grow from seeds” effect name by “Watershed”).

1 Like

Thank you again. So do onApply and passing seeds work similar with watershed? Also, do you know if Watershed requires less seeds than Grow from Seeds?

The main difference between “grow from seeds” and “watershed” that watershed can enforce a spatial smoothness constrain. In some cases, this might help in getting better segmentation result with smaller or less seeds.