diff --git a/Python/05_Results_Visualization.ipynb b/Python/05_Results_Visualization.ipynb index b63e49bb..d44b3fdf 100644 --- a/Python/05_Results_Visualization.ipynb +++ b/Python/05_Results_Visualization.ipynb @@ -1085,33 +1085,27 @@ " for c in colors:\n", " if c == [0, 0, 0]:\n", " raise ValueError(\"Colors include black [0,0,0], not allowed\")\n", - " empty_image = image * 0\n", - " overlay_boundaries = [\n", - " sitk.LabelMapContourOverlay(\n", - " sitk.Cast(seg, sitk.sitkLabelUInt8),\n", - " empty_image,\n", - " opacity=1,\n", - " contourThickness=thickness,\n", - " dilationRadius=dilation_radius,\n", - " colormap=color,\n", - " )\n", - " for seg, color in zip(binary_segmentations, colors)\n", + "\n", + " # Merge into a single label map (MergeLabelMapFilter's default KEEP method\n", + " # keeps each input's region distinct even though they all use label 1),\n", + " # so LabelMapContourOverlay handles overlapping contours itself in a\n", + " # single pass instead of manually compositing per-segmentation results.\n", + " merged_labels = sitk.MergeLabelMap(\n", + " [sitk.Cast(seg, sitk.sitkLabelUInt8) for seg in binary_segmentations],\n", + " sitk.MergeLabelMapFilter.Keep,\n", + " )\n", + " flat_colormap = [\n", + " channel for color in colors[: len(binary_segmentations)] for channel in color\n", " ]\n", "\n", - " current_image = sitk.Compose([image] * 3)\n", - " for o_image in overlay_boundaries:\n", - " current_mask = (\n", - " sitk.NaryAdd(\n", - " [\n", - " sitk.VectorIndexSelectionCast(o_image, 0),\n", - " sitk.VectorIndexSelectionCast(o_image, 1),\n", - " sitk.VectorIndexSelectionCast(o_image, 2),\n", - " ]\n", - " )\n", - " == 0\n", - " )\n", - " current_image = mask_image_multiply(current_mask, current_image) + o_image\n", - " return current_image\n", + " return sitk.LabelMapContourOverlay(\n", + " merged_labels,\n", + " image,\n", + " opacity=1,\n", + " contourThickness=thickness,\n", + " dilationRadius=dilation_radius,\n", + " colormap=flat_colormap,\n", + " )\n", "\n", "\n", "binary_segmentations = [\n", diff --git a/tests/additional_dictionary.txt b/tests/additional_dictionary.txt index c9ff423d..ca4c45a7 100644 --- a/tests/additional_dictionary.txt +++ b/tests/additional_dictionary.txt @@ -1,3 +1,5 @@ +LabelMapContourOverlay +MergeLabelMapFilter's ipympl ACM ANTSNeighborhoodCorrelation