mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-06 05:16:40 +08:00
Fix inconsistencies in examples and many more improvements
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
Comparing edge-based segmentation and region-based segmentation
|
||||
===============================================================
|
||||
|
||||
In this example, we will see how to segment objects from a background. We use
|
||||
In this example, we will see how to segment objects from a background. We use
|
||||
the ``coins`` image from ``skimage.data``, which shows several coins outlined
|
||||
against a darker background.
|
||||
"""
|
||||
@@ -108,9 +108,8 @@ closed are not filled correctly, as is the case for one unfilled coin above.
|
||||
Region-based segmentation
|
||||
=========================
|
||||
|
||||
We therefore try a region-based method using the
|
||||
watershed transform. First, we find an elevation map using the Sobel gradient of the
|
||||
image.
|
||||
We therefore try a region-based method using the watershed transform. First, we
|
||||
find an elevation map using the Sobel gradient of the image.
|
||||
|
||||
"""
|
||||
|
||||
@@ -142,7 +141,8 @@ plt.title('markers')
|
||||
"""
|
||||
.. image:: PLOT2RST.current_figure
|
||||
|
||||
Finally, we use the watershed transform to fill regions of the elevation map starting from the markers determined above:
|
||||
Finally, we use the watershed transform to fill regions of the elevation map
|
||||
starting from the markers determined above:
|
||||
|
||||
"""
|
||||
segmentation = morphology.watershed(elevation_map, markers)
|
||||
@@ -155,8 +155,8 @@ plt.title('segmentation')
|
||||
"""
|
||||
.. image:: PLOT2RST.current_figure
|
||||
|
||||
This last method works even better, and the coins can be segmented and
|
||||
labeled individually.
|
||||
This last method works even better, and the coins can be segmented and labeled
|
||||
individually.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
@@ -13,12 +13,15 @@ thresholding on the gradient magnitude.
|
||||
The Canny has three adjustable parameters: the width of the Gaussian (the
|
||||
noisier the image, the greater the width), and the low and high threshold for
|
||||
the hysteresis thresholding.
|
||||
|
||||
"""
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from scipy import ndimage
|
||||
|
||||
from skimage import filter
|
||||
|
||||
|
||||
# Generate noisy image of a square
|
||||
im = np.zeros((128, 128))
|
||||
im[32:-32, 32:-32] = 1
|
||||
@@ -52,6 +55,5 @@ plt.title('Canny filter, $\sigma=3$', fontsize=20)
|
||||
plt.subplots_adjust(wspace=0.02, hspace=0.02, top=0.9,
|
||||
bottom=0.02, left=0.02, right=0.98)
|
||||
|
||||
|
||||
plt.show()
|
||||
|
||||
|
||||
@@ -29,8 +29,6 @@ original picture in order to detect centers outside the frame.
|
||||
Its size is extended by two times the larger radius.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
@@ -39,6 +37,7 @@ from skimage.transform import hough_circle
|
||||
from skimage.feature import peak_local_max
|
||||
from skimage.draw import circle_perimeter
|
||||
|
||||
|
||||
# Load picture and detect edges
|
||||
image = data.coins()[0:95, 70:370]
|
||||
edges = filter.canny(image, sigma=3, low_threshold=10, high_threshold=50)
|
||||
|
||||
@@ -15,12 +15,12 @@ Cubes: A High Resolution 3D Surface Construction Algorithm. Computer Graphics
|
||||
(SIGGRAPH 87 Proceedings) 21(4) July 1987, p. 163-170).
|
||||
|
||||
"""
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from skimage import data
|
||||
from skimage import measure
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Construct some test data
|
||||
x, y = np.ogrid[-np.pi:np.pi:100j, -np.pi:np.pi:100j]
|
||||
@@ -39,4 +39,3 @@ plt.axis('image')
|
||||
plt.xticks([])
|
||||
plt.yticks([])
|
||||
plt.show()
|
||||
|
||||
|
||||
@@ -13,12 +13,12 @@ A good overview of the algorithm is given on `Steve Eddin's blog
|
||||
<http://blogs.mathworks.com/steve/2011/10/04/binary-image-convex-hull-algorithm-notes/>`__.
|
||||
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from skimage.morphology import convex_hull_image
|
||||
|
||||
|
||||
image = np.array(
|
||||
[[0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 1, 0, 0, 0, 0],
|
||||
|
||||
@@ -10,7 +10,6 @@ position of corners.
|
||||
.. [2] http://en.wikipedia.org/wiki/Interest_point_detection
|
||||
|
||||
"""
|
||||
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
from skimage import data
|
||||
@@ -18,6 +17,7 @@ from skimage.feature import corner_harris, corner_subpix, corner_peaks
|
||||
from skimage.transform import warp, AffineTransform
|
||||
from skimage.draw import ellipse
|
||||
|
||||
|
||||
tform = AffineTransform(scale=(1.3, 1.1), rotation=1, shear=0.7,
|
||||
translation=(210, 50))
|
||||
image = warp(data.checkerboard(), tform.inverse, output_shape=(350, 350))
|
||||
|
||||
@@ -11,7 +11,6 @@ representations.
|
||||
In this example a limited number of DAISY descriptors are extracted at a large
|
||||
scale for illustrative purposes.
|
||||
"""
|
||||
|
||||
from skimage.feature import daisy
|
||||
from skimage import data
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
@@ -25,13 +25,13 @@ A bilateral filter is an edge-preserving and noise reducing filter. It averages
|
||||
pixels based on their spatial closeness and radiometric similarity.
|
||||
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from skimage import data, color, img_as_float
|
||||
from skimage.filter import denoise_tv_chambolle, denoise_bilateral
|
||||
|
||||
|
||||
lena = img_as_float(data.lena())
|
||||
lena = lena[220:300, 220:320]
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import matplotlib.pyplot as plt
|
||||
from skimage.data import camera
|
||||
from skimage.filter import roberts, sobel
|
||||
|
||||
|
||||
image = camera()
|
||||
edge_roberts = roberts(image)
|
||||
edge_sobel = sobel(image)
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
"""
|
||||
===================
|
||||
=======
|
||||
Entropy
|
||||
===================
|
||||
|
||||
=======
|
||||
|
||||
"""
|
||||
from skimage import data
|
||||
from skimage.filter.rank import entropy
|
||||
from skimage.morphology import disk
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from skimage import data
|
||||
from skimage.filter.rank import entropy
|
||||
from skimage.morphology import disk
|
||||
|
||||
|
||||
# defining a 8- and a 16-bit test images
|
||||
a8 = data.camera()
|
||||
a16 = data.camera().astype(np.uint16)*4
|
||||
a16 = a8.astype(np.uint16) * 4
|
||||
|
||||
ent8 = entropy(a8,disk(5)) # pixel value contain 10x the local entropy
|
||||
ent16 = entropy(a16,disk(5)) # pixel value contain 1000x the local entropy
|
||||
ent8 = entropy(a8, disk(5)) # pixel value contain 10x the local entropy
|
||||
ent16 = entropy(a16, disk(5)) # pixel value contain 1000x the local entropy
|
||||
|
||||
# display results
|
||||
plt.figure(figsize=(10, 10))
|
||||
@@ -41,4 +42,3 @@ plt.imshow(ent16, cmap=plt.cm.jet)
|
||||
plt.xlabel('entropy*1000')
|
||||
plt.colorbar()
|
||||
plt.show()
|
||||
|
||||
|
||||
@@ -17,13 +17,12 @@ that fall within the 2nd and 98th percentiles [2]_.
|
||||
.. [2] http://homepages.inf.ed.ac.uk/rbf/HIPR2/stretch.htm
|
||||
|
||||
"""
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
from skimage import data, img_as_float
|
||||
from skimage import exposure
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
|
||||
def plot_img_and_hist(img, axes, bins=256):
|
||||
"""Plot an image along with its histogram and cumulative histogram.
|
||||
|
||||
@@ -12,11 +12,11 @@ kernels. The mean and variance of the filtered images are then used as features
|
||||
for classification, which is based on the least squared error for simplicity.
|
||||
|
||||
"""
|
||||
|
||||
import matplotlib
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from scipy import ndimage as nd
|
||||
|
||||
from skimage import data
|
||||
from skimage.util import img_as_float
|
||||
from skimage.filter import gabor_kernel
|
||||
|
||||
@@ -35,7 +35,6 @@ is not rocket science.
|
||||
Interaction, and Functional Architecture in the Cat's Visual Cortex,
|
||||
J. Physiol. 160 pp. 106-154 1962
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
from scipy.cluster.vq import kmeans2
|
||||
from scipy import ndimage as ndi
|
||||
|
||||
@@ -19,10 +19,11 @@ this example) would be to train a classifier, such as logistic
|
||||
regression, to label image patches from new images.
|
||||
|
||||
"""
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from skimage.feature import greycomatrix, greycoprops
|
||||
from skimage import data
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
PATCH_SIZE = 21
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
r'''
|
||||
"""
|
||||
===============================
|
||||
Histogram of Oriented Gradients
|
||||
===============================
|
||||
@@ -77,12 +77,13 @@ References
|
||||
.. [2] David G. Lowe, "Distinctive image features from scale-invariant
|
||||
keypoints," International Journal of Computer Vision, 60, 2 (2004),
|
||||
pp. 91-110.
|
||||
'''
|
||||
|
||||
"""
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from skimage.feature import hog
|
||||
from skimage import data, color, exposure
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
image = color.rgb2gray(data.lena())
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ image represent the maximum and minimum possible values of the reconstructed
|
||||
image.
|
||||
|
||||
We start with an image containing both peaks and holes:
|
||||
|
||||
"""
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
@@ -1,50 +1,47 @@
|
||||
'''
|
||||
"""
|
||||
===============
|
||||
Hough transform
|
||||
===============
|
||||
|
||||
The Hough transform in its simplest form is a `method to detect
|
||||
straight lines <http://en.wikipedia.org/wiki/Hough_transform>`__.
|
||||
The Hough transform in its simplest form is a `method to detect straight lines
|
||||
<http://en.wikipedia.org/wiki/Hough_transform>`__.
|
||||
|
||||
In the following example, we construct an image with a line
|
||||
intersection. We then use the Hough transform to explore a parameter
|
||||
space for straight lines that may run through the image.
|
||||
In the following example, we construct an image with a line intersection. We
|
||||
then use the Hough transform to explore a parameter space for straight lines
|
||||
that may run through the image.
|
||||
|
||||
Algorithm overview
|
||||
------------------
|
||||
|
||||
Usually, lines are parameterised as :math:`y = mx + c`, with a
|
||||
gradient :math:`m` and y-intercept `c`. However, this would mean that
|
||||
:math:`m` goes to infinity for vertical lines. Instead, we therefore
|
||||
construct a segment perpendicular to the line, leading to the origin.
|
||||
The line is represented by the length of that segment, :math:`r`, and
|
||||
the angle it makes with the x-axis, :math:`\theta`.
|
||||
Usually, lines are parameterised as :math:`y = mx + c`, with a gradient
|
||||
:math:`m` and y-intercept `c`. However, this would mean that :math:`m` goes to
|
||||
infinity for vertical lines. Instead, we therefore construct a segment
|
||||
perpendicular to the line, leading to the origin. The line is represented by the
|
||||
length of that segment, :math:`r`, and the angle it makes with the x-axis,
|
||||
:math:`\theta`.
|
||||
|
||||
The Hough transform constructs a histogram array representing the
|
||||
parameter space (i.e., an :math:`M \times N` matrix, for :math:`M`
|
||||
different values of the radius and :math:`N` different values of
|
||||
:math:`\theta`). For each parameter combination, :math:`r` and
|
||||
:math:`\theta`, we then find the number of non-zero pixels in the
|
||||
input image that would fall close to the corresponding line, and
|
||||
The Hough transform constructs a histogram array representing the parameter
|
||||
space (i.e., an :math:`M \times N` matrix, for :math:`M` different values of the
|
||||
radius and :math:`N` different values of :math:`\theta`). For each parameter
|
||||
combination, :math:`r` and :math:`\theta`, we then find the number of non-zero
|
||||
pixels in the input image that would fall close to the corresponding line, and
|
||||
increment the array at position :math:`(r, \theta)` appropriately.
|
||||
|
||||
We can think of each non-zero pixel "voting" for potential line
|
||||
candidates. The local maxima in the resulting histogram indicates the
|
||||
parameters of the most probably lines. In our example, the maxima
|
||||
occur at 45 and 135 degrees, corresponding to the normal vector
|
||||
angles of each line.
|
||||
We can think of each non-zero pixel "voting" for potential line candidates. The
|
||||
local maxima in the resulting histogram indicates the parameters of the most
|
||||
probably lines. In our example, the maxima occur at 45 and 135 degrees,
|
||||
corresponding to the normal vector angles of each line.
|
||||
|
||||
Another approach is the Progressive Probabilistic Hough Transform
|
||||
[1]_. It is based on the assumption that using a random subset of
|
||||
voting points give a good approximation to the actual result, and that
|
||||
lines can be extracted during the voting process by walking along
|
||||
connected components. This returns the beginning and end of each
|
||||
line segment, which is useful.
|
||||
Another approach is the Progressive Probabilistic Hough Transform [1]_. It is
|
||||
based on the assumption that using a random subset of voting points give a good
|
||||
approximation to the actual result, and that lines can be extracted during the
|
||||
voting process by walking along connected components. This returns the beginning
|
||||
and end of each line segment, which is useful.
|
||||
|
||||
The function `probabilistic_hough` has three parameters: a general
|
||||
threshold that is applied to the Hough accumulator, a minimum line
|
||||
length and the line gap that influences line merging. In the example
|
||||
below, we find lines longer than 10 with a gap less than 3 pixels.
|
||||
The function `probabilistic_hough` has three parameters: a general threshold
|
||||
that is applied to the Hough accumulator, a minimum line length and the line gap
|
||||
that influences line merging. In the example below, we find lines longer than 10
|
||||
with a gap less than 3 pixels.
|
||||
|
||||
References
|
||||
----------
|
||||
@@ -57,7 +54,7 @@ References
|
||||
Detect Lines and Curves in Pictures," Comm. ACM, Vol. 15,
|
||||
pp. 11-15 (January, 1972)
|
||||
|
||||
'''
|
||||
"""
|
||||
|
||||
from skimage.transform import (hough_line, hough_line_peaks,
|
||||
probabilistic_hough_line)
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
Immunohistochemical staining colors separation
|
||||
==============================================
|
||||
|
||||
In this example we separate the immunohistochemical (IHC) staining
|
||||
from the hematoxylin counterstaining. The separation is achieved with the
|
||||
method described in [1]_, known as "color deconvolution".
|
||||
In this example we separate the immunohistochemical (IHC) staining from the
|
||||
hematoxylin counterstaining. The separation is achieved with the method
|
||||
described in [1]_, known as "color deconvolution".
|
||||
|
||||
The IHC staining expression of the FHL2 protein is here revealed with
|
||||
Diaminobenzidine (DAB) which gives a brown color.
|
||||
@@ -15,6 +15,7 @@ Diaminobenzidine (DAB) which gives a brown color.
|
||||
staining by color deconvolution.," Analytical and quantitative
|
||||
cytology and histology / the International Academy of Cytology [and]
|
||||
American Society of Cytology, vol. 23, no. 4, pp. 291-9, Aug. 2001.
|
||||
|
||||
"""
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ segmentations. The `skimage.segmentation.join_segmentations` function
|
||||
computes the join of two segmentations, in which a pixel is placed in
|
||||
the same segment if and only if it is in the same segment in _both_
|
||||
segmentations.
|
||||
"""
|
||||
|
||||
"""
|
||||
import numpy as np
|
||||
from scipy import ndimage as nd
|
||||
import matplotlib.pyplot as plt
|
||||
@@ -18,9 +18,9 @@ import matplotlib as mpl
|
||||
from skimage.filter import sobel
|
||||
from skimage.segmentation import slic, join_segmentations
|
||||
from skimage.morphology import watershed
|
||||
|
||||
from skimage import data
|
||||
|
||||
|
||||
coins = data.coins()
|
||||
|
||||
# make segmentation using edge-detection and watershed
|
||||
|
||||
@@ -12,7 +12,6 @@ steps are applied:
|
||||
4. Measure image regions to filter small objects
|
||||
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib.patches as mpatches
|
||||
|
||||
@@ -7,8 +7,8 @@ In this example, we will see how to classify textures based on LBP (Local
|
||||
Binary Pattern). The histogram of the LBP result is a good measure to classify
|
||||
textures. For simplicity the histogram distributions are then tested against
|
||||
each other using the Kullback-Leibler-Divergence.
|
||||
"""
|
||||
|
||||
"""
|
||||
import numpy as np
|
||||
import matplotlib
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
"""
|
||||
===============================
|
||||
============================
|
||||
Local Histogram Equalization
|
||||
===============================
|
||||
============================
|
||||
|
||||
This examples enhances an image with low contrast, using a method called
|
||||
*local histogram equalization*, which "spreads out the most frequent intensity
|
||||
values" in an image .
|
||||
The equalized image [1]_ has a roughly linear cumulative distribution function for each pixel neighborhood.
|
||||
The local version [2]_ of the histogram equalization emphasized every local graylevel variations.
|
||||
This examples enhances an image with low contrast, using a method called *local
|
||||
histogram equalization*, which spreads out the most frequent intensity values in
|
||||
an image.
|
||||
|
||||
The equalized image [1]_ has a roughly linear cumulative distribution function
|
||||
for each pixel neighborhood.
|
||||
|
||||
The local version [2]_ of the histogram equalization emphasized every local
|
||||
graylevel variations.
|
||||
|
||||
References
|
||||
----------
|
||||
.. [1] http://en.wikipedia.org/wiki/Histogram_equalization
|
||||
.. [2] http://en.wikipedia.org/wiki/Adaptive_histogram_equalization
|
||||
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
"""
|
||||
=====================
|
||||
====================
|
||||
Local Otsu Threshold
|
||||
=====================
|
||||
This example shows how Otsu's threshold [1]_ method can be applied locally.
|
||||
For each pixel, an "optimal" threshold is determined by maximizing the variance between two classes of pixels
|
||||
of the local neighborhood defined by a structuring element.
|
||||
====================
|
||||
|
||||
This example shows how Otsu's threshold [1]_ method can be applied locally. For
|
||||
each pixel, an "optimal" threshold is determined by maximizing the variance
|
||||
between two classes of pixels of the local neighborhood defined by a structuring
|
||||
element.
|
||||
|
||||
The example compares the local threshold with the global threshold.
|
||||
|
||||
.. note: local threshold is much slower than global one.
|
||||
.. note: local is much slower than global thresholding
|
||||
|
||||
.. [1] http://en.wikipedia.org/wiki/Otsu's_method
|
||||
|
||||
@@ -42,8 +44,8 @@ plt.xlabel('local Otsu ($radius=%d$)' % radius)
|
||||
plt.colorbar()
|
||||
plt.subplot(2, 2, 3)
|
||||
plt.imshow(p8 >= loc_otsu, cmap=plt.cm.gray)
|
||||
plt.xlabel('original>=local Otsu' % t_glob_otsu)
|
||||
plt.xlabel('original >= local Otsu' % t_glob_otsu)
|
||||
plt.subplot(2, 2, 4)
|
||||
plt.imshow(glob_otsu, cmap=plt.cm.gray)
|
||||
plt.xlabel('global Otsu ($t=%d$)' % t_glob_otsu)
|
||||
plt.xlabel('global Otsu ($t = %d$)' % t_glob_otsu)
|
||||
plt.show()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
================================
|
||||
===============================
|
||||
Markers for watershed transform
|
||||
================================
|
||||
===============================
|
||||
|
||||
The watershed is a classical algorithm used for **segmentation**, that
|
||||
is, for separating different objects in an image.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Medial axis skeletonization
|
||||
===========================
|
||||
|
||||
The medial axis of an object is the set of all points having more than one
|
||||
The medial axis of an object is the set of all points having more than one
|
||||
closest point on the object's boundary. It is often called the **topological
|
||||
skeleton**, because it is a 1-pixel wide skeleton of the object, with the same
|
||||
connectivity as the original object.
|
||||
@@ -15,11 +15,11 @@ argument ``return_distance=True``), it is possible to compute the distance to
|
||||
the background for all points of the medial axis with this function. This gives
|
||||
an estimate of the local width of the objects.
|
||||
|
||||
For a skeleton with fewer branches, there exists another skeletonization
|
||||
For a skeleton with fewer branches, there exists another skeletonization
|
||||
algorithm in ``skimage``: ``skimage.morphology.skeletonize``, that computes
|
||||
a skeleton by iterative morphological thinnings.
|
||||
"""
|
||||
|
||||
"""
|
||||
import numpy as np
|
||||
from scipy import ndimage
|
||||
from skimage.morphology import medial_axis
|
||||
@@ -33,7 +33,7 @@ def microstructure(l=256):
|
||||
Parameters
|
||||
----------
|
||||
|
||||
l: int, optional
|
||||
l: int, optional
|
||||
linear size of the returned image
|
||||
|
||||
"""
|
||||
@@ -64,7 +64,5 @@ plt.imshow(dist_on_skel, cmap=plt.cm.spectral, interpolation='nearest')
|
||||
plt.contour(data, [0.5], colors='w')
|
||||
plt.axis('off')
|
||||
|
||||
plt.subplots_adjust(hspace=0.01, wspace=0.01, top=1, bottom=0, left=0,
|
||||
right=1)
|
||||
plt.subplots_adjust(hspace=0.01, wspace=0.01, top=1, bottom=0, left=0, right=1)
|
||||
plt.show()
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ the intra-class variance.
|
||||
.. [1] http://en.wikipedia.org/wiki/Otsu's_method
|
||||
|
||||
"""
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from skimage.data import camera
|
||||
@@ -42,4 +41,3 @@ plt.title('Thresholded')
|
||||
plt.axis('off')
|
||||
|
||||
plt.show()
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
===============================================================================
|
||||
====================
|
||||
Finding local maxima
|
||||
===============================================================================
|
||||
====================
|
||||
|
||||
The ``peak_local_max`` function returns the coordinates of local peaks (maxima)
|
||||
in an image. A maximum filter is used for finding local maxima. This operation
|
||||
@@ -47,4 +47,3 @@ plt.subplots_adjust(wspace=0.02, hspace=0.02, top=0.9,
|
||||
bottom=0.02, left=0.02, right=0.98)
|
||||
|
||||
plt.show()
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ Piecewise Affine Transformation
|
||||
===============================
|
||||
|
||||
This example shows how to use the Piecewise Affine Transformation.
|
||||
"""
|
||||
|
||||
"""
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from skimage.transform import PiecewiseAffineTransform, warp
|
||||
|
||||
@@ -5,8 +5,8 @@ Approximate and subdivide polygons
|
||||
|
||||
This example shows how to approximate (Douglas-Peucker algorithm) and subdivide
|
||||
(B-Splines) polygonal chains.
|
||||
"""
|
||||
|
||||
"""
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from skimage.draw import ellipse
|
||||
|
||||
@@ -9,7 +9,6 @@ implement algorithms for denoising, texture discrimination, and scale- invariant
|
||||
detection.
|
||||
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
@@ -18,13 +18,14 @@ values, and use the random walker for the segmentation.
|
||||
|
||||
.. [1] *Random walks for image segmentation*, Leo Grady, IEEE Trans. Pattern
|
||||
Anal. Mach. Intell. 2006 Nov; 28(11):1768-83
|
||||
"""
|
||||
|
||||
"""
|
||||
import numpy as np
|
||||
from scipy import ndimage
|
||||
from skimage.segmentation import random_walker
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from skimage.segmentation import random_walker
|
||||
|
||||
|
||||
def microstructure(l=256):
|
||||
"""
|
||||
|
||||
@@ -11,14 +11,15 @@ First we try reconstruction by dilation starting at the edges of the image. We
|
||||
initialize a seed image to the minimum intensity of the image, and set its
|
||||
border to be the pixel values in the original image. These maximal pixels will
|
||||
get dilated in order to reconstruct the background image.
|
||||
|
||||
"""
|
||||
import numpy as np
|
||||
from scipy.ndimage import gaussian_filter
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from skimage import data
|
||||
from skimage import img_as_float
|
||||
from skimage.morphology import reconstruction
|
||||
from scipy.ndimage import gaussian_filter
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Convert to float: Important for subtraction later which won't work with uint8
|
||||
image = img_as_float(data.coins())
|
||||
|
||||
@@ -4,8 +4,8 @@ Measure region properties
|
||||
=========================
|
||||
|
||||
This example shows how to measure properties of labelled image regions.
|
||||
"""
|
||||
|
||||
"""
|
||||
import math
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
@@ -4,17 +4,17 @@ Fill shapes
|
||||
===========
|
||||
|
||||
This example shows how to fill several different shapes:
|
||||
|
||||
* line
|
||||
* polygon
|
||||
* circle
|
||||
* ellipse
|
||||
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from skimage.draw import line, polygon, circle, circle_perimeter, ellipse
|
||||
import numpy as np
|
||||
|
||||
|
||||
img = np.zeros((500, 500, 3), 'uint8')
|
||||
|
||||
@@ -30,9 +30,11 @@ image[10:-10, -100:-10] = 1
|
||||
|
||||
# foreground object 2
|
||||
rs, cs = draw.bresenham(250, 150, 10, 280)
|
||||
for i in range(10): image[rs+i, cs] = 1
|
||||
for i in range(10):
|
||||
image[rs + i, cs] = 1
|
||||
rs, cs = draw.bresenham(10, 150, 250, 280)
|
||||
for i in range(20): image[rs+i, cs] = 1
|
||||
for i in range(20):
|
||||
image[rs + i, cs] = 1
|
||||
|
||||
# foreground object 3
|
||||
ir, ic = np.indices(image.shape)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
'''
|
||||
"""
|
||||
===========================
|
||||
Structural similarity index
|
||||
===========================
|
||||
@@ -20,12 +20,13 @@ but with very different mean structural similarity indices.
|
||||
Transactions on Image Processing, vol. 13, no. 4, pp. 600-612,
|
||||
Apr. 2004.
|
||||
|
||||
'''
|
||||
"""
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from skimage import data, color, io, exposure, img_as_float
|
||||
from skimage.measure import structural_similarity as ssim
|
||||
|
||||
import numpy as np
|
||||
|
||||
img = img_as_float(data.camera())
|
||||
rows, cols = img.shape
|
||||
@@ -39,7 +40,6 @@ def mse(x, y):
|
||||
img_noise = img + noise
|
||||
img_const = img + abs(noise)
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
f, (ax0, ax1, ax2) = plt.subplots(1, 3)
|
||||
|
||||
mse_none = mse(img, img)
|
||||
|
||||
@@ -8,7 +8,7 @@ effect. This example describes the implementation of this transform in
|
||||
``skimage``, as well as the underlying warp mechanism.
|
||||
|
||||
Image warping
|
||||
`````````````
|
||||
-------------
|
||||
When applying a geometric transformation on an image, we typically make use of
|
||||
a reverse mapping, i.e., for each pixel in the output image, we compute its
|
||||
corresponding position in the input. The reason is that, if we were to do it
|
||||
@@ -19,7 +19,7 @@ image, and even if that position is non-integer, we may use interpolation to
|
||||
compute the corresponding image value.
|
||||
|
||||
Performing a reverse mapping
|
||||
````````````````````````````
|
||||
----------------------------
|
||||
To perform a geometric warp in ``skimage``, you simply need to provide the
|
||||
reverse mapping to the ``skimage.transform.warp`` function. E.g., consider the
|
||||
case where we would like to shift an image 50 pixels to the left. The reverse
|
||||
@@ -35,7 +35,7 @@ The corresponding call to warp is::
|
||||
warp(image, shift_left)
|
||||
|
||||
The swirl transformation
|
||||
````````````````````````
|
||||
------------------------
|
||||
Consider the coordinate :math:`(x, y)` in the output image. The reverse
|
||||
mapping for the swirl transformation first computes, relative to a center
|
||||
:math:`(x_0, y_0)`, its polar coordinates,
|
||||
@@ -63,12 +63,13 @@ the swirl extent in pixels, and ``rotation`` adds a rotation angle. The
|
||||
transformation of ``radius`` into :math:`r` is to ensure that the
|
||||
transformation decays to :math:`\approx 1/1000^{\mathsf{th}}` within the
|
||||
specified radius.
|
||||
|
||||
"""
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from skimage import data
|
||||
from skimage.transform import swirl
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
image = data.checkerboard()
|
||||
swirled = swirl(image, rotation=0, strength=10, radius=120, order=2)
|
||||
|
||||
@@ -17,13 +17,15 @@ the template.
|
||||
|
||||
.. [1] J. P. Lewis, "Fast Normalized Cross-Correlation", Industrial Light and
|
||||
Magic.
|
||||
"""
|
||||
|
||||
"""
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from skimage import data
|
||||
from skimage.feature import match_template
|
||||
|
||||
|
||||
image = data.coins()
|
||||
coin = image[170:220, 75:130]
|
||||
|
||||
@@ -53,4 +55,3 @@ ax3.autoscale(False)
|
||||
ax3.plot(x, y, 'o', markeredgecolor='r', markerfacecolor='none', markersize=10)
|
||||
|
||||
plt.show()
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ blocks. Then, on each block, we either pool the mean, the max or the
|
||||
median value of that block. The results are displayed altogether, along
|
||||
with a spline interpolation of order 3 rescaling of the original `lena`
|
||||
image.
|
||||
"""
|
||||
|
||||
"""
|
||||
import numpy as np
|
||||
from scipy import ndimage as ndi
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
@@ -24,13 +24,14 @@ See Wikipedia_ for more details on the algorithm.
|
||||
.. _Wikipedia: http://en.wikipedia.org/wiki/Watershed_(image_processing)
|
||||
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
from scipy import ndimage
|
||||
|
||||
from skimage.morphology import watershed
|
||||
from skimage.feature import peak_local_max
|
||||
|
||||
|
||||
# Generate an initial image with two overlapping circles
|
||||
x, y = np.indices((80, 80))
|
||||
x1, y1, x2, y2 = 28, 28, 44, 52
|
||||
@@ -41,7 +42,6 @@ image = np.logical_or(mask_circle1, mask_circle2)
|
||||
|
||||
# Now we want to separate the two objects in image
|
||||
# Generate the markers as local maxima of the distance to the background
|
||||
from scipy import ndimage
|
||||
distance = ndimage.distance_transform_edt(image)
|
||||
local_maxi = peak_local_max(distance, indices=False, footprint=np.ones((3, 3)),
|
||||
labels=image)
|
||||
|
||||
Reference in New Issue
Block a user