SegmentationMetrics

Segmentation quality metrics computation.

Computes Dice coefficient, Hausdorff distance, and other metrics for comparing test segmentations against reference (gold standard) segmentations.

Classes

class MetricsResult

Result of comparing two segmentations.

Methods:

to_dict()

Convert to dictionary for JSON serialization.

class SegmentationMetrics

Compute comparison metrics between segmentations.

Uses SimpleITK for Dice, Hausdorff, and overlap metrics.

Usage:
metrics = SegmentationMetrics.compute(

test_seg_node, test_segment_id, ref_seg_node, ref_segment_id, volume_node

) print(f”Dice: {metrics.dice:.3f}”) print(f”Hausdorff 95%: {metrics.hausdorff_95:.1f}mm”)

Methods:

compute()

Compute Dice and Hausdorff between test and reference segmentations.

compute_dice_only()

Compute Dice coefficient only (faster than full metrics).

class StrokeRecord

Record of a single stroke’s metrics.

Methods:

to_dict()

Convert to dictionary for JSON serialization.

class StrokeMetricsTracker

Track how metrics improve with each stroke.

Usage:

tracker = StrokeMetricsTracker(gold_seg, gold_id, volume)

for stroke_params in stroke_list:

# Apply stroke to test_seg… record = tracker.record_stroke(test_seg, test_id, stroke_params) print(f”Stroke {record.stroke}: Dice={record.dice:.3f}”)

summary = tracker.get_summary() print(f”Strokes to 90% Dice: {summary[‘strokes_to_90pct’]}”)

Methods:

__init__()

Initialize tracker.

record_stroke()

Record metrics after a stroke.

get_summary()

Summarize stroke progression.

reset()

Clear stroke history for a new trial.

Functions

to_dict()

Convert to dictionary for JSON serialization.

compute()

Compute Dice and Hausdorff between test and reference segmentations.

Args:

test_seg_node: Test segmentation MRML node. test_segment_id: Segment ID within test segmentation. reference_seg_node: Reference (gold) segmentation MRML node. reference_segment_id: Segment ID within reference segmentation. volume_node: Volume node providing geometry (spacing).

Returns:

MetricsResult with all computed metrics.

compute_dice_only()

Compute Dice coefficient only (faster than full metrics).

Args:

test_seg_node: Test segmentation MRML node. test_segment_id: Segment ID within test segmentation. reference_seg_node: Reference (gold) segmentation MRML node. reference_segment_id: Segment ID within reference segmentation. volume_node: Volume node providing geometry.

Returns:

Dice coefficient (0-1).

to_dict()

Convert to dictionary for JSON serialization.

record_stroke()

Record metrics after a stroke.

Args:

test_seg_node: Test segmentation MRML node. test_segment_id: Segment ID within test segmentation. stroke_params: Parameters used for this stroke.

Returns:

StrokeRecord with computed metrics.

get_summary()

Summarize stroke progression.

Returns:

Dictionary with summary statistics.

reset()

Clear stroke history for a new trial.