From 3fe03259d09ee8bcf4ffd31de066bde285017df1 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Sun, 19 Aug 2012 16:24:12 -0400 Subject: [PATCH] DOC: Combine examples for finding spots and filling holes. --- doc/examples/plot_find_spots.py | 69 ------------------- ..._fill_holes.py => plot_holes_and_peaks.py} | 24 +++++-- 2 files changed, 20 insertions(+), 73 deletions(-) delete mode 100644 doc/examples/plot_find_spots.py rename doc/examples/{plot_fill_holes.py => plot_holes_and_peaks.py} (73%) diff --git a/doc/examples/plot_find_spots.py b/doc/examples/plot_find_spots.py deleted file mode 100644 index ff6e2196..00000000 --- a/doc/examples/plot_find_spots.py +++ /dev/null @@ -1,69 +0,0 @@ -""" -========== -Find spots -========== - -In this example, we find bright spots in an image using morphological -reconstruction by dilation. Dilation expands the maximal values of the seed -image until it encounters a mask image. Thus, the seed image and mask image -represent the minimum and maximum possible values of the reconstructed image. - -We start with an image containing both peaks and holes: -""" -import matplotlib.pyplot as plt - -from skimage import data -from skimage.exposure import rescale_intensity - -image = data.moon() -# Rescale image intensity so that we can see dim features. -image = rescale_intensity(image, in_range=(50, 200)) - -# convenience function for plotting images -def imshow(image, **kwargs): - plt.figure(figsize=(5, 4)) - plt.imshow(image, **kwargs) - plt.axis('off') - -imshow(image) -plt.title('original image') - -""" -.. image:: PLOT2RST.current_figure - -Now we need to create the seed image, where the maxima represent the starting -points for dilation. To find spots, we initialize the seed image to the minimum -value of the original image. Along the borders, however, we use the original -values of the image. These border pixels will be the starting points for the -dilation process. We then limit the dilation by setting the mask to the values -of the original image. -""" - -import numpy as np -from skimage.morphology import reconstruction - -seed = np.copy(image) -seed[1:-1, 1:-1] = image.min() -mask = image - -rec = reconstruction(seed, mask, method='dilation') - -imshow(rec, vmin=image.min(), vmax=image.max()) -plt.title('') - -""" -.. image:: PLOT2RST.current_figure - -As shown above, dilating inward from the edges removes peaks, since (by -definition) peaks are surrounded by pixels of darker value. Finally, we can -isolate the bright spots by subtracting the reconstructed image from the -original image. -""" - -imshow(image - rec) -plt.title('"holes"') -plt.show() - -""" -.. image:: PLOT2RST.current_figure -""" diff --git a/doc/examples/plot_fill_holes.py b/doc/examples/plot_holes_and_peaks.py similarity index 73% rename from doc/examples/plot_fill_holes.py rename to doc/examples/plot_holes_and_peaks.py index 7257d2bb..a9c3a7fe 100644 --- a/doc/examples/plot_fill_holes.py +++ b/doc/examples/plot_holes_and_peaks.py @@ -1,7 +1,7 @@ """ -========== -Fill holes -========== +=============================== +Filling holes and finding peaks +=============================== In this example, we fill holes (i.e. isolated, dark spots) in an image using morphological reconstruction by erosion. Erosion expands the minimal values of @@ -62,7 +62,23 @@ original image. """ imshow(image - filled) -plt.title('dark holes') +plt.title('holes') + +""" +.. image:: PLOT2RST.current_figure + +Alternatively, we can find bright spots in an image using morphological +reconstruction by dilation. Dilation is the inverse of erosion and expands the +*maximal* values of the seed image until it encounters a mask image. Since this +is an inverse operation, we initialize the seed image to the minimum image +intensity instead of the maximum. The remainder of the process is the same. +""" + +seed = np.copy(image) +seed[1:-1, 1:-1] = image.min() +rec = reconstruction(seed, mask, method='dilation') +imshow(image - rec) +plt.title('peaks') plt.show() """