Segmentation Recipes
Recipes capture complete segmentation workflows that can be replayed, tested, and optimized. They record click locations, parameters, and expected results for reproducible segmentation.
What is a Recipe?
A recipe is a saved sequence of segmentation actions:
# Example recipe structure
{
"name": "Brain Tumor Segmentation",
"sample_data": "MRBrainTumor1",
"gold_standard": "MRBrainTumor1_tumor",
"actions": [
{
"type": "adaptive_brush",
"ras": [-5.31, 34.77, 20.83],
"params": {
"algorithm": "watershed",
"brush_radius_mm": 25.0,
"edge_sensitivity": 65
}
},
# ... more actions
]
}
Using Recipes
Loading a Recipe
Open the SegmentEditorAdaptiveBrushReviewer module
Click Load Recipe
Select a
.jsonrecipe file
Replaying a Recipe
The Reviewer module provides step-by-step replay:
Button |
Action |
|---|---|
Play |
Run all steps automatically |
Step |
Execute one action at a time |
Reset |
Return to initial state |
Comparing to Gold Standard
When a recipe has an associated gold standard:
The gold standard loads automatically (shown in green)
Your segmentation shows in red
Overlap shows in yellow
Dice coefficient displays in real-time
Creating Recipes
From the Recorder
Open SegmentEditorAdaptiveBrushReviewer
Click Start Recording
Perform your segmentation in Segment Editor
Click Stop Recording
Save the recipe
From Python
from SegmentEditorAdaptiveBrushTesterLib import Recipe, Action
recipe = Recipe(
name="My Segmentation",
sample_data="MRBrainTumor1",
gold_standard="MRBrainTumor1_tumor"
)
# Add actions
recipe.add_action(Action(
action_type="adaptive_brush",
ras=[-5.31, 34.77, 20.83],
params={
"algorithm": "watershed",
"brush_radius_mm": 25.0,
}
))
# Save
recipe.save("my_recipe.json")
From Optimization Results
After running optimization, the best trial can be converted to a recipe:
# In Slicer Python console
from SegmentEditorAdaptiveBrushTesterLib import Recipe
import json
# Load optimization results
with open("optimization_results/2026-01-26_.../results.json") as f:
results = json.load(f)
best = results["best_trial"]
# Create recipe from best trial
recipe = Recipe(
name="Optimized Brain Tumor",
sample_data="MRBrainTumor1",
gold_standard="MRBrainTumor1_tumor"
)
for click in best["user_attrs"]["click_locations"]:
recipe.add_action(Action(
action_type="adaptive_brush",
ras=click["ras"],
params=click["params"]
))
recipe.save("optimized_recipe.json")
Recipe File Format
Recipes are stored as JSON:
{
"version": "1.0",
"name": "Brain Tumor Segmentation",
"description": "5-click tumor segmentation using watershed",
"sample_data": "MRBrainTumor1",
"gold_standard": "MRBrainTumor1_tumor",
"created": "2026-01-26T06:20:00",
"actions": [
{
"type": "adaptive_brush",
"ras": [-5.31, 34.77, 20.83],
"params": {
"algorithm": "watershed",
"brush_radius_mm": 25.0,
"edge_sensitivity": 65,
"threshold_zone": 60
}
}
],
"metadata": {
"author": "optimization",
"dice": 0.9991,
"notes": "Best result from 50-trial optimization"
}
}
Gold Standards
What is a Gold Standard?
A gold standard is a reference segmentation used to:
Measure recipe quality (Dice coefficient)
Test for regressions
Optimize parameters
Gold Standard Structure
GoldStandards/
└── MRBrainTumor1_tumor/
├── gold.seg.nrrd # The segmentation
├── metadata.json # Parameters, clicks, etc.
└── reference_screenshots/
Creating a Gold Standard
From the Reviewer module:
Create a high-quality segmentation
Click Save as Gold Standard
Enter a name and description
The gold standard is saved with metadata
From Python:
from SegmentEditorAdaptiveBrushTesterLib import GoldStandardManager
manager = GoldStandardManager()
manager.save_as_gold(
segmentation_node=seg_node,
volume_node=vol_node,
segment_id="Segment_1",
name="MRBrainTumor1_tumor",
click_locations=clicks,
description="Reference tumor segmentation",
algorithm="watershed",
parameters={"brush_radius_mm": 25.0}
)
Testing Recipes
Running Regression Tests
# From command line
Slicer --python-script scripts/run_regression.py recipes/brain_tumor_1.py
In Python
from SegmentEditorAdaptiveBrushTesterLib import RecipeTestRunner
runner = RecipeTestRunner()
result = runner.run_recipe("recipes/brain_tumor_1.py")
print(f"Dice: {result.dice:.4f}")
print(f"Passed: {result.passed}")
Best Practices
Recipe Design
Use consistent click locations that capture the structure well
Start from the center of the structure
Add boundary clicks for edges that need attention
Document the purpose in the recipe description
Gold Standard Quality
Manual refinement - Correct any errors before saving
Include edge cases - Test challenging boundaries
Document parameters - Record what worked
Version Control
Store recipes in version control
Gold standards can be regenerated from recipes
Track parameter changes over time