diff --git a/06_advanced_registration.ipynb b/06_advanced_registration.ipynb index ef981a8..7706e5b 100644 --- a/06_advanced_registration.ipynb +++ b/06_advanced_registration.ipynb @@ -596,26 +596,26 @@ "for i, seg in enumerate(segmentations):\n", " # Overlap measures\n", " overlap_measures_filter.Execute(reference_segmentation, seg)\n", - " overlap_results[\n", - " i, OverlapMeasures.jaccard.value\n", - " ] = overlap_measures_filter.GetJaccardCoefficient()\n", - " overlap_results[\n", - " i, OverlapMeasures.dice.value\n", - " ] = overlap_measures_filter.GetDiceCoefficient()\n", - " overlap_results[\n", - " i, OverlapMeasures.volume_similarity.value\n", - " ] = overlap_measures_filter.GetVolumeSimilarity()\n", - " overlap_results[\n", - " i, OverlapMeasures.false_negative.value\n", - " ] = overlap_measures_filter.GetFalseNegativeError()\n", - " overlap_results[\n", - " i, OverlapMeasures.false_positive.value\n", - " ] = overlap_measures_filter.GetFalsePositiveError()\n", + " overlap_results[i, OverlapMeasures.jaccard.value] = (\n", + " overlap_measures_filter.GetJaccardCoefficient()\n", + " )\n", + " overlap_results[i, OverlapMeasures.dice.value] = (\n", + " overlap_measures_filter.GetDiceCoefficient()\n", + " )\n", + " overlap_results[i, OverlapMeasures.volume_similarity.value] = (\n", + " overlap_measures_filter.GetVolumeSimilarity()\n", + " )\n", + " overlap_results[i, OverlapMeasures.false_negative.value] = (\n", + " overlap_measures_filter.GetFalseNegativeError()\n", + " )\n", + " overlap_results[i, OverlapMeasures.false_positive.value] = (\n", + " overlap_measures_filter.GetFalsePositiveError()\n", + " )\n", " # Hausdorff distance\n", " hausdorff_distance_filter.Execute(reference_segmentation, seg)\n", - " surface_distance_results[\n", - " i, SurfaceDistanceMeasures.hausdorff_distance.value\n", - " ] = hausdorff_distance_filter.GetHausdorffDistance()\n", + " surface_distance_results[i, SurfaceDistanceMeasures.hausdorff_distance.value] = (\n", + " hausdorff_distance_filter.GetHausdorffDistance()\n", + " )\n", " # Symmetric surface distance measures\n", " segmented_distance_map = sitk.Abs(\n", " sitk.SignedMaurerDistanceMap(seg, squaredDistance=False)\n", @@ -649,18 +649,18 @@ "\n", " all_surface_distances = seg2ref_distances + ref2seg_distances\n", "\n", - " surface_distance_results[\n", - " i, SurfaceDistanceMeasures.mean_surface_distance.value\n", - " ] = np.mean(all_surface_distances)\n", + " surface_distance_results[i, SurfaceDistanceMeasures.mean_surface_distance.value] = (\n", + " np.mean(all_surface_distances)\n", + " )\n", " surface_distance_results[\n", " i, SurfaceDistanceMeasures.median_surface_distance.value\n", " ] = np.median(all_surface_distances)\n", - " surface_distance_results[\n", - " i, SurfaceDistanceMeasures.std_surface_distance.value\n", - " ] = np.std(all_surface_distances)\n", - " surface_distance_results[\n", - " i, SurfaceDistanceMeasures.max_surface_distance.value\n", - " ] = np.max(all_surface_distances)\n", + " surface_distance_results[i, SurfaceDistanceMeasures.std_surface_distance.value] = (\n", + " np.std(all_surface_distances)\n", + " )\n", + " surface_distance_results[i, SurfaceDistanceMeasures.max_surface_distance.value] = (\n", + " np.max(all_surface_distances)\n", + " )\n", "\n", "import pandas as pd\n", "from IPython.display import display, HTML\n", diff --git a/09_segmentation_evaluation.ipynb b/09_segmentation_evaluation.ipynb index a70d49e..7613f1a 100644 --- a/09_segmentation_evaluation.ipynb +++ b/09_segmentation_evaluation.ipynb @@ -248,27 +248,27 @@ "for i, seg in enumerate(segmentations):\n", " # Overlap measures\n", " overlap_measures_filter.Execute(reference_segmentation, seg)\n", - " overlap_results[\n", - " i, OverlapMeasures.jaccard.value\n", - " ] = overlap_measures_filter.GetJaccardCoefficient()\n", - " overlap_results[\n", - " i, OverlapMeasures.dice.value\n", - " ] = overlap_measures_filter.GetDiceCoefficient()\n", - " overlap_results[\n", - " i, OverlapMeasures.volume_similarity.value\n", - " ] = overlap_measures_filter.GetVolumeSimilarity()\n", - " overlap_results[\n", - " i, OverlapMeasures.false_negative.value\n", - " ] = overlap_measures_filter.GetFalseNegativeError()\n", - " overlap_results[\n", - " i, OverlapMeasures.false_positive.value\n", - " ] = overlap_measures_filter.GetFalsePositiveError()\n", + " overlap_results[i, OverlapMeasures.jaccard.value] = (\n", + " overlap_measures_filter.GetJaccardCoefficient()\n", + " )\n", + " overlap_results[i, OverlapMeasures.dice.value] = (\n", + " overlap_measures_filter.GetDiceCoefficient()\n", + " )\n", + " overlap_results[i, OverlapMeasures.volume_similarity.value] = (\n", + " overlap_measures_filter.GetVolumeSimilarity()\n", + " )\n", + " overlap_results[i, OverlapMeasures.false_negative.value] = (\n", + " overlap_measures_filter.GetFalseNegativeError()\n", + " )\n", + " overlap_results[i, OverlapMeasures.false_positive.value] = (\n", + " overlap_measures_filter.GetFalsePositiveError()\n", + " )\n", " # Hausdorff distance\n", " hausdorff_distance_filter.Execute(reference_segmentation, seg)\n", "\n", - " surface_distance_results[\n", - " i, SurfaceDistanceMeasures.hausdorff_distance.value\n", - " ] = hausdorff_distance_filter.GetHausdorffDistance()\n", + " surface_distance_results[i, SurfaceDistanceMeasures.hausdorff_distance.value] = (\n", + " hausdorff_distance_filter.GetHausdorffDistance()\n", + " )\n", " # Symmetric surface distance measures\n", " segmented_distance_map = sitk.Abs(\n", " sitk.SignedMaurerDistanceMap(seg, squaredDistance=False, useImageSpacing=True)\n", @@ -305,18 +305,18 @@ " # The maximum of the symmetric surface distances is the Hausdorff distance between the surfaces. In\n", " # general, it is not equal to the Hausdorff distance between all voxel/pixel points of the two\n", " # segmentations, though in our case it is. More on this below.\n", - " surface_distance_results[\n", - " i, SurfaceDistanceMeasures.mean_surface_distance.value\n", - " ] = np.mean(all_surface_distances)\n", + " surface_distance_results[i, SurfaceDistanceMeasures.mean_surface_distance.value] = (\n", + " np.mean(all_surface_distances)\n", + " )\n", " surface_distance_results[\n", " i, SurfaceDistanceMeasures.median_surface_distance.value\n", " ] = np.median(all_surface_distances)\n", - " surface_distance_results[\n", - " i, SurfaceDistanceMeasures.std_surface_distance.value\n", - " ] = np.std(all_surface_distances)\n", - " surface_distance_results[\n", - " i, SurfaceDistanceMeasures.max_surface_distance.value\n", - " ] = np.max(all_surface_distances)\n", + " surface_distance_results[i, SurfaceDistanceMeasures.std_surface_distance.value] = (\n", + " np.std(all_surface_distances)\n", + " )\n", + " surface_distance_results[i, SurfaceDistanceMeasures.max_surface_distance.value] = (\n", + " np.max(all_surface_distances)\n", + " )\n", "\n", "# Print the matrices\n", "np.set_printoptions(precision=3)\n", diff --git a/gui.py b/gui.py index 6619954..ae50f23 100644 --- a/gui.py +++ b/gui.py @@ -59,17 +59,21 @@ def __init__( # Display the data and the controls, first time we display the images is outside the "update_display" method # as that method relies on the previous zoom factor which doesn't exist yet. self.fixed_axes.imshow( - self.fixed_npa[self.fixed_slider.value, :, :] - if self.fixed_slider - else self.fixed_npa, + ( + self.fixed_npa[self.fixed_slider.value, :, :] + if self.fixed_slider + else self.fixed_npa + ), cmap=plt.cm.Greys_r, vmin=self.fixed_min_intensity, vmax=self.fixed_max_intensity, ) self.moving_axes.imshow( - self.moving_npa[self.moving_slider.value, :, :] - if self.moving_slider - else self.moving_npa, + ( + self.moving_npa[self.moving_slider.value, :, :] + if self.moving_slider + else self.moving_npa + ), cmap=plt.cm.Greys_r, vmin=self.moving_min_intensity, vmax=self.moving_max_intensity, @@ -164,9 +168,11 @@ def update_display(self): # Draw the fixed image in the first subplot and the localized points. self.fixed_axes.clear() self.fixed_axes.imshow( - self.fixed_npa[self.fixed_slider.value, :, :] - if self.fixed_slider - else self.fixed_npa, + ( + self.fixed_npa[self.fixed_slider.value, :, :] + if self.fixed_slider + else self.fixed_npa + ), cmap=plt.cm.Greys_r, vmin=self.fixed_min_intensity, vmax=self.fixed_max_intensity, @@ -209,9 +215,11 @@ def update_display(self): # Draw the moving image in the second subplot and the localized points. self.moving_axes.clear() self.moving_axes.imshow( - self.moving_npa[self.moving_slider.value, :, :] - if self.moving_slider - else self.moving_npa, + ( + self.moving_npa[self.moving_slider.value, :, :] + if self.moving_slider + else self.moving_npa + ), cmap=plt.cm.Greys_r, vmin=self.moving_min_intensity, vmax=self.moving_max_intensity, @@ -1025,9 +1033,11 @@ def get_rois(self): both min/max values. """ return [ - (roi_data[1], roi_data[2], roi_data[3]) - if self.npa.ndim == 3 - else (roi_data[1], roi_data[2]) + ( + (roi_data[1], roi_data[2], roi_data[3]) + if self.npa.ndim == 3 + else (roi_data[1], roi_data[2]) + ) for roi_data in self.rois ]