Algorithm Profiles
This document describes the algorithm profiling system used to optimize segmentation parameters.
Overview
Algorithm profiles provide data-driven recommendations for algorithm and parameter selection based on:
Automated optimization - Optuna-based parameter search against gold standards
Modality characteristics - Known imaging physics and typical intensity patterns
Structure properties - Shape, size, and boundary characteristics
Profile Data Structure
Algorithm profiles are stored in algorithm_profiles.json at the project root.
Parameter Importance
From optimization studies, we found:
Parameter |
Importance |
|---|---|
Algorithm choice |
73.1% |
Brush radius |
18.6% |
Threshold zone |
5.1% |
Edge sensitivity |
3.2% |
Key insight: Algorithm selection is by far the most important parameter.
Algorithm Characteristics
Each algorithm has profiled characteristics:
{
"watershed": {
"speed": "medium",
"precision": "high",
"boundary_adherence": "excellent",
"recommended_for": ["tumor", "lesion", "brain_tissue"],
"parameters": {
"gradient_scale": {"range": [0.5, 3.0], "optimal": 1.1},
"smoothing": {"range": [0.1, 1.0], "optimal": 0.78}
}
}
}
Modality Recommendations
Recommendations are organized by imaging modality and structure:
{
"ct": {
"bone": {
"primary": "threshold_brush",
"alternatives": ["connected_threshold"],
"preset": "ct_bone"
}
}
}
Using Profiles Programmatically
Loading Profiles
import json
from pathlib import Path
profiles_path = Path(__file__).parent / "algorithm_profiles.json"
with open(profiles_path) as f:
profiles = json.load(f)
Getting Recommendations
def get_recommendation(modality: str, structure: str) -> dict:
"""Get algorithm recommendation for modality/structure pair."""
mod_recs = profiles.get("modality_recommendations", {})
if modality in mod_recs and structure in mod_recs[modality]:
return mod_recs[modality][structure]
return profiles.get("structure_recommendations", {}).get(structure, {})
# Example usage
rec = get_recommendation("ct", "bone")
print(f"Primary algorithm: {rec['primary']}") # threshold_brush
print(f"Preset to apply: {rec['preset']}") # ct_bone
Applying Recommendations
def apply_recommendation(effect, modality: str, structure: str):
"""Apply algorithm recommendation to effect."""
rec = get_recommendation(modality, structure)
# Apply the preset (sets common parameters)
if "preset" in rec:
effect.applyPreset(rec["preset"])
# Algorithm is selected via UI - log the recommendation
print(f"Recommended algorithm: {rec.get('primary', 'watershed')}")
Generating New Profiles
Running Optimization
Use the optimization script to generate benchmark data:
Slicer --python-script scripts/run_optimization.py
This runs Optuna optimization against gold standards and outputs:
results.json- Full trial dataparameter_importance.json- Relative parameter importanceScreenshots and segmentations for each trial
Adding Benchmarks
After running optimization, add benchmark results to the profile:
{
"algorithms": {
"watershed": {
"benchmarks": {
"MRBrainTumor1_tumor": {
"dice": 0.9991,
"edge_sensitivity": 70,
"threshold_zone": 60,
"brush_radius_mm": 25.0
}
}
}
}
}
Profile Evolution
Adding New Modalities
Create recipes for the new modality
Run optimization with gold standards
Analyze results and add to
modality_recommendationsUpdate documentation
Refining Recommendations
Collect user feedback on segmentation quality
Run A/B tests with alternative algorithms
Update primary/alternative recommendations based on results
Integration with Presets
Presets define common parameters (edge sensitivity, sampling method, etc.) that work well for a modality/structure combination.
Algorithm selection is independent of presets - users choose the algorithm via the UI dropdown based on:
Speed requirements - Fast vs. precise
Boundary characteristics - Sharp vs. diffuse
Algorithm profiles - Data-driven recommendations
Preset to Algorithm Mapping
While presets don’t force an algorithm, there are natural pairings:
Preset |
Recommended Algorithm |
|---|---|
|
Threshold Brush |
|
Watershed |
|
Connected Threshold |
|
Geodesic Distance |
|
Watershed |
|
Watershed |
Future Work
Auto-selection - Automatically suggest algorithm based on modality detection
Online learning - Update profiles based on user corrections
Per-structure profiles - Build profiles for specific anatomical structures
Multi-algorithm fusion - Combine results from multiple algorithms