SegmentEditorEffect
Adaptive Brush Segment Editor Effect.
This effect provides an adaptive brush that automatically segments regions based on image intensity similarity, adapting to image features (edges, boundaries) rather than using a fixed geometric shape.
Classes
- class BrushOutlinePipeline
VTK pipeline for brush outline visualization in a slice view.
Shows two circle outlines: - Outer circle (yellow): Maximum brush extent - Inner circle (cyan): Threshold sampling zone - Preview overlay (green, semi-transparent): Segmentation preview - Crosshair (optional): Center crosshair lines
Methods:
- __init__()
Initialize the brush outline pipeline.
- setSliceWidget()
Attach the pipeline to a slice widget’s renderer.
- updateOutline()
Update the brush outline position and size.
- setCrosshairSettings()
Update crosshair settings.
- updatePreview()
Update the preview overlay with a 2D mask.
- hidePreview()
Hide only the preview overlay (keep circles visible).
- hide()
Hide the brush outlines and preview.
- cleanup()
Remove the actors from the renderer and clean up.
Functions
- setSliceWidget()
Attach the pipeline to a slice widget’s renderer.
- Args:
sliceWidget: The qMRMLSliceWidget to attach to.
- updateOutline()
Update the brush outline position and size.
- Args:
xyPosition: Center position in slice XY coordinates (x, y). radiusPixels: Outer brush radius in pixels. innerRadiusRatio: Inner circle as fraction of outer (0.0-1.0).
- setCrosshairSettings()
Update crosshair settings.
- Args:
enabled: Whether crosshair is shown. size: Size in pixels. thickness: Line width. style: One of CROSSHAIR_STYLE_* constants. color: RGB tuple (0-1 range).
- updatePreview()
Update the preview overlay with a 2D mask.
- Args:
mask2D: 2D numpy array (height, width) with 0/1 values. originXY: Origin of the mask in slice XY coordinates (x, y). spacingXY: Pixel spacing in XY (sx, sy).
- hidePreview()
Hide only the preview overlay (keep circles visible).
- hide()
Hide the brush outlines and preview.
- cleanup()
Remove the actors from the renderer and clean up.
- register()
Register the effect with the segment editor effect factory.
This method is copied from AbstractScriptedSegmentEditorEffect since we don’t inherit from it (to avoid recursion issues).
- clone()
Create a copy of this effect.
- Returns:
New effect instance.
- icon()
Return the effect icon.
- Returns:
QIcon for the effect toolbar button.
- helpText()
Return help text for the effect.
- Returns:
HTML string with usage instructions. First line before <br>. shown as collapsed summary.
- setupOptionsFrame()
Create the effect options UI.
- onCrosshairColorPicker()
Open color picker dialog for crosshair color.
- onCrosshairSettingsChanged()
Handle crosshair settings changes.
- onPresetChanged()
Handle preset selection change.
- onResetPreset()
Reset all parameters to the currently selected preset.
- applyPreset()
Apply a parameter preset.
- Args:
preset_id: Preset name (e.g., “tumor_lesion”, “bone_ct”, “default”).
- Available presets:
“default”: Balanced settings for general use
“bone_ct”: High contrast bone in CT
“soft_tissue_ct”: Organs/soft tissue in CT
“lung_ct”: Lung parenchyma in CT
“brain_mri”: Brain tissue in MRI
“tumor_lesion”: Tumors with irregular boundaries
“vessel”: Blood vessels
“smooth_edge”: Smooth-edged structures
“sharp_edge”: Sharp-edged structures
“fast_rough”: Quick rough segmentation
- paintAt()
Apply a brush stroke at the given RAS coordinates.
This is the main method for programmatic painting. It navigates to the location, applies the brush with current parameters, and updates the segmentation.
- Args:
r: Right coordinate (mm). a: Anterior coordinate (mm). s: Superior coordinate (mm). erase: If True, erase instead of add.
- Example:
effect.applyPreset(“tumor_lesion”) effect.brushRadiusMm = 20.0 effect.paintAt(-5.31, 34.77, 20.83)
- brushRadiusMm()
Get/set the brush radius in millimeters.
- brushRadiusMm()
- edgeSensitivityValue()
Get/set edge sensitivity (0-100).
- edgeSensitivityValue()
- onRadiusChanged()
Handle radius slider change.
- onSensitivityChanged()
Handle edge sensitivity change.
- onZoneChanged()
Handle threshold zone size change.
- onSamplingMethodChanged()
Handle sampling method change.
- onAdvancedParamChanged()
Handle any advanced parameter change.
- onSphereModeChanged()
Handle 3D mode toggle.
- onPreviewModeChanged()
Handle preview mode toggle.
- onModeChanged()
Handle add/erase mode toggle.
- Args:
checked: True if the “Add” radio button is checked.
- onWizardClicked()
Launch the Quick Select Parameters wizard.
- setAlgorithm()
Set the current algorithm.
- Args:
algorithm: Algorithm identifier string.
- setRadiusMm()
Set the brush radius.
- Args:
radius_mm: Brush radius in millimeters (clamped to 1.0-100.0).
- setEdgeSensitivity()
Set the edge sensitivity.
- Args:
sensitivity: Edge sensitivity value (clamped to 0-100).
- setThresholdRange()
Set the threshold range for threshold-based algorithms.
- Args:
lower: Lower threshold value. upper: Upper threshold value.
- onAlgorithmChanged()
Handle algorithm selection change.
- onThresholdChanged()
Handle manual threshold slider change.
- onAutoThresholdChanged()
Toggle between auto and manual threshold modes.
- onThresholdMethodChanged()
Handle threshold method change.
- onSetFromSeedClicked()
Handle set from seed button click.
- onCachingChanged()
Handle threshold caching toggle.
- onBackendChanged()
Handle backend selection change.
- activate()
Called when the effect is selected.
- deactivate()
Called when the effect is deselected.
- setMRMLDefaults()
Called to set default MRML parameters. No-op for this effect.
- updateGUIFromMRML()
Called to sync GUI from MRML parameters. No-op for this effect.
- updateMRMLFromGUI()
Called to sync MRML from GUI. No-op for this effect.
- interactionNodeModified()
Called when the interaction node changes. No-op for this effect.
- layoutChanged()
Called when the application layout changes. No-op for this effect.
- processViewNodeEvents()
Called to process view node events. No-op for this effect.
- cleanup()
Clean up resources to prevent memory leaks.
Disconnects all signal/slot connections and cleans up VTK pipelines. This method is called by Slicer before the effect is deleted.
- sourceVolumeNodeChanged()
Called when the source volume node changes.
Updates threshold slider ranges to match the new volume’s intensity range.
- masterVolumeNodeChanged()
Called when the master volume node changes (deprecated name).
Delegates to sourceVolumeNodeChanged for backward compatibility.
- referenceGeometryChanged()
Called when the reference geometry changes.
No-op for this effect - we handle volume changes in sourceVolumeNodeChanged.
- processInteractionEvents()
Handle mouse interaction events.
- Args:
callerInteractor: VTK interactor that triggered the event. eventId: VTK event ID. viewWidget: The view widget where the event occurred.
- Returns:
True if the event was handled, False otherwise.
- processPoint()
Process a single point interaction.
- Args:
xy: Screen coordinates (x, y). viewWidget: The slice view widget.
- computeAdaptiveMask()
Compute the adaptive segmentation mask.
- Args:
sourceVolumeNode: The source volume MRML node. seedIjk: Seed point in IJK coordinates. viewWidget: The slice view widget.
- Returns:
numpy array with binary mask, or None on failure.
- applyMaskToSegment()
Apply the computed mask to the current segment.
- Args:
mask: Binary mask numpy array (z, y, x ordering). erase: If True, remove mask from segment. If False, add to segment.