How to Integrate Threshold Effect from Segment Editor into a Custom Module

Hi everyone,

I am currently working on a custom module in 3D Slicer and would like to incorporate the functionality of the “Threshold” effect from the Segment Editor module.

My main goal is to allow users to:

  1. Set threshold values (e.g., lower and upper bounds).
  2. Preview the thresholded region in real-time on a specific image.

I’ve been trying to achieve this for some time now, but I haven’t been able to figure it out. I don’t need the full functionality of the Segment Editor, just these two features.

Could anyone guide me on how to accomplish this? Are there any Python examples or specific API calls I should look into?

Thank you in advance for your help!

You may get some inspiration from this module.

Thank you for your response! It helped me a lot. Do you happen to have any modules that implement the Flood Filling effect and Keep Selected Island (from the Islands operation) that I could take inspiration from? It would be great to see how others have approached this topic.

For flood filling: 1, 2.

For ‘Keep selected island’: no known reference. The module I linked in my previous post uses KEEP_LARGEST_ISLAND; if you use KEEP_SELECTED_ISLAND, it should do the trick.

I’m unsure how to properly capture the click event and translate it into a flood-filling operation. Could someone guide me on how to:

  1. Detect a user click in the Slice View.
  2. Retrieve the voxel coordinates of the clicked point.
  3. Apply a flood-filling operation (e.g., using ITK or other available methods).

If there are any examples or similar implementations, I would greatly appreciate any references or advice.

But the ‘Flood filling’ effect already does that. Your goal is not very clear. If you don’t plan to use the ‘Segment editor’, you’ll have to rewrite much code, a lot of work to achieve robustness and efficiency.