mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-02 13:03:48 +08:00
Minor fixes and improvements: PEP8, appearance, etc.
Removed a clumsy workaround (about paths) Fixed links to image files to fix sphinx warning. Removed non-ascii character Another non ascii character And another non-ascii character... (to be squashed later on) Corrected some typos in the docstrings of sphinx-gallery files These corrections have also been submitted as a patch to the original sphinx-gallery project (#121) Corrected the appearance of two examples of the gallery Tweaked CSS for larger images Added sphinx-gallery's license and a README.txt about the origin of this directory. Edited gabor_from_astronaut example for nicer popup PEP 8 + minor fixes Removed commented lines of code
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
Gabors / Primary Visual Cortex "Simple Cells" from an Image
|
||||
============================================================
|
||||
|
||||
How to build a (bio-plausible) "sparse" dictionary (or 'codebook', or
|
||||
How to build a (bio-plausible) *sparse* dictionary (or 'codebook', or
|
||||
'filterbank') for e.g. image classification without any fancy math and
|
||||
with just standard python scientific libraries?
|
||||
|
||||
|
||||
@@ -3,11 +3,10 @@
|
||||
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
|
||||
the seed image until it encounters a mask image. Thus, the seed image and mask
|
||||
image represent the maximum and minimum possible values of the reconstructed
|
||||
image.
|
||||
We fill holes (i.e. isolated, dark spots) in an image using morphological
|
||||
reconstruction by erosion. Erosion expands the minimal values of the seed image
|
||||
until it encounters a mask image. Thus, the seed image and mask image represent
|
||||
the maximum and minimum possible values of the reconstructed image.
|
||||
|
||||
We start with an image containing both peaks and holes:
|
||||
|
||||
@@ -21,14 +20,6 @@ image = data.moon()
|
||||
# Rescale image intensity so that we can see dim features.
|
||||
image = rescale_intensity(image, in_range=(50, 200))
|
||||
|
||||
fig,ax = plt.subplots(2, 2, figsize=(5, 4), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'})
|
||||
ax = ax.ravel()
|
||||
|
||||
|
||||
ax[0].imshow(image)
|
||||
ax[0].set_title('Original image')
|
||||
ax[0].axis('off')
|
||||
|
||||
######################################################################
|
||||
# Now we need to create the seed image, where the minima represent the
|
||||
# starting points for erosion. To fill holes, we initialize the seed image
|
||||
@@ -46,21 +37,12 @@ mask = image
|
||||
|
||||
filled = reconstruction(seed, mask, method='erosion')
|
||||
|
||||
ax[1].imshow(filled)
|
||||
ax[1].set_title('after filling holes')
|
||||
ax[1].axis('off')
|
||||
|
||||
######################################################################
|
||||
# As shown above, eroding inward from the edges removes holes, since (by
|
||||
# definition) holes are surrounded by pixels of brighter value. Finally, we
|
||||
# can isolate the dark regions by subtracting the reconstructed image from
|
||||
# the original image.
|
||||
|
||||
ax[2].imshow(image-filled)
|
||||
ax[2].set_title('holes')
|
||||
ax[2].axis('off')
|
||||
|
||||
######################################################################
|
||||
#
|
||||
# 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.
|
||||
@@ -72,7 +54,23 @@ seed = np.copy(image)
|
||||
seed[1:-1, 1:-1] = image.min()
|
||||
rec = reconstruction(seed, mask, method='dilation')
|
||||
|
||||
ax[3].imshow(image-rec)
|
||||
fig, ax = plt.subplots(2, 2, figsize=(5, 4), sharex=True, sharey=True,
|
||||
subplot_kw={'adjustable': 'box-forced'})
|
||||
ax = ax.ravel()
|
||||
|
||||
ax[0].imshow(image, cmap='gray')
|
||||
ax[0].set_title('Original image')
|
||||
ax[0].axis('off')
|
||||
|
||||
ax[1].imshow(filled, cmap='gray')
|
||||
ax[1].set_title('after filling holes')
|
||||
ax[1].axis('off')
|
||||
|
||||
ax[2].imshow(image-filled, cmap='gray')
|
||||
ax[2].set_title('holes')
|
||||
ax[2].axis('off')
|
||||
|
||||
ax[3].imshow(image-rec, cmap='gray')
|
||||
ax[3].set_title('peaks')
|
||||
ax[3].axis('off')
|
||||
plt.show()
|
||||
|
||||
Reference in New Issue
Block a user