Skip to content

Commit

Permalink
Fix inconsistencies in examples and many more improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ahojnnes committed Apr 27, 2013
1 parent 41007b4 commit d0ee6ad
Show file tree
Hide file tree
Showing 40 changed files with 138 additions and 132 deletions.
14 changes: 7 additions & 7 deletions doc/examples/applications/plot_coins_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down Expand Up @@ -108,9 +108,8 @@
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.
"""

Expand Down Expand Up @@ -142,7 +141,8 @@
"""
.. 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)
Expand All @@ -155,8 +155,8 @@
"""
.. 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.
"""

Expand Down
4 changes: 3 additions & 1 deletion doc/examples/plot_canny.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
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
Expand Down Expand Up @@ -52,6 +55,5 @@
plt.subplots_adjust(wspace=0.02, hspace=0.02, top=0.9,
bottom=0.02, left=0.02, right=0.98)


plt.show()

3 changes: 1 addition & 2 deletions doc/examples/plot_circular_hough_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
Its size is extended by two times the larger radius.
"""


import numpy as np
import matplotlib.pyplot as plt

Expand All @@ -39,6 +37,7 @@
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)
Expand Down
5 changes: 2 additions & 3 deletions doc/examples/plot_contours.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
(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]
Expand All @@ -39,4 +39,3 @@
plt.xticks([])
plt.yticks([])
plt.show()

2 changes: 1 addition & 1 deletion doc/examples/plot_convex_hull.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
<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],
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/plot_corner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
.. [2] http://en.wikipedia.org/wiki/Interest_point_detection
"""

from matplotlib import pyplot as plt

from skimage import data
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))
Expand Down
1 change: 0 additions & 1 deletion doc/examples/plot_daisy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
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
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/plot_denoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
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]

Expand Down
1 change: 1 addition & 0 deletions doc/examples/plot_edge_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from skimage.data import camera
from skimage.filter import roberts, sobel


image = camera()
edge_roberts = roberts(image)
edge_sobel = sobel(image)
Expand Down
18 changes: 9 additions & 9 deletions doc/examples/plot_entropy.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
"""
===================
=======
Entropy
===================
=======
"""
import numpy as np
import matplotlib.pyplot as plt

from skimage import data
from skimage.filter.rank import entropy
from skimage.morphology import disk
import numpy as np
import matplotlib.pyplot as plt


# 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))
Expand All @@ -41,4 +42,3 @@
plt.xlabel('entropy*1000')
plt.colorbar()
plt.show()

5 changes: 2 additions & 3 deletions doc/examples/plot_equalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
.. [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.
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/plot_gabor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
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
Expand Down
1 change: 0 additions & 1 deletion doc/examples/plot_gabors_from_lena.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
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
Expand Down
3 changes: 2 additions & 1 deletion doc/examples/plot_glcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
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

Expand Down
7 changes: 4 additions & 3 deletions doc/examples/plot_hog.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
r'''
"""
===============================
Histogram of Oriented Gradients
===============================
Expand Down Expand Up @@ -77,12 +77,13 @@
.. [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())

Expand Down
1 change: 1 addition & 0 deletions doc/examples/plot_holes_and_peaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
image.
We start with an image containing both peaks and holes:
"""
import matplotlib.pyplot as plt

Expand Down
67 changes: 32 additions & 35 deletions doc/examples/plot_hough_transform.py
Original file line number Diff line number Diff line change
@@ -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`.
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
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
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
----------
Expand All @@ -57,7 +54,7 @@
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)
Expand Down
7 changes: 4 additions & 3 deletions doc/examples/plot_ihc_color_separation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -15,6 +15,7 @@
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

Expand Down
Loading

0 comments on commit d0ee6ad

Please sign in to comment.