Skip to content

Commit

Permalink
Update formatting.
Browse files Browse the repository at this point in the history
New version of black changes the formatting slightly.
  • Loading branch information
zivy committed Feb 1, 2024
1 parent 224f6e6 commit 864fbcc
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 69 deletions.
54 changes: 27 additions & 27 deletions 06_advanced_registration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
54 changes: 27 additions & 27 deletions 09_segmentation_evaluation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
40 changes: 25 additions & 15 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
]

Expand Down

0 comments on commit 864fbcc

Please sign in to comment.