mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-11 03:36:25 +08:00
PEP8
This commit is contained in:
@@ -83,16 +83,16 @@ Ellipse detection
|
||||
|
||||
In this second example, the aim is to detect the edge of a coffee cup.
|
||||
Basically, this is a projection of a circle, i.e. an ellipse.
|
||||
The problem to solve is much more difficult bacause five parameters have to be determined,
|
||||
instead of three for circles.
|
||||
The problem to solve is much more difficult bacause five parameters have to be
|
||||
determined, instead of three for circles.
|
||||
|
||||
|
||||
Algorithm overview
|
||||
------------------
|
||||
|
||||
The algorithm takes two different points belonging to the ellipse. It assumes that it is
|
||||
the main axis. A loop on all the other points determines how much an ellipse passes to
|
||||
them. A good match corresponds to high accumulator values.
|
||||
The algorithm takes two different points belonging to the ellipse. It assumes
|
||||
that it is the main axis. A loop on all the other points determines how much
|
||||
an ellipse passes to them. A good match corresponds to high accumulator values.
|
||||
|
||||
A full description of the algorithm can be found in reference [1].
|
||||
|
||||
@@ -103,7 +103,6 @@ References
|
||||
method." Pattern Recognition, 2002. Proceedings. 16th International
|
||||
Conference on. Vol. 2. IEEE, 2002
|
||||
"""
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from skimage import data, filter, color
|
||||
@@ -113,7 +112,8 @@ from skimage.draw import ellipse_perimeter
|
||||
# Load picture, convert to grayscale and detect edges
|
||||
image_rgb = data.load('coffee.png')[100:240, 110:250]
|
||||
image_gray = color.rgb2gray(image_rgb)
|
||||
edges = filter.canny(image_gray, sigma=2.0, low_threshold=0.1, high_threshold=0.6)
|
||||
edges = filter.canny(image_gray, sigma=2.0,
|
||||
low_threshold=0.1, high_threshold=0.6)
|
||||
|
||||
# Perform a Hough Transform
|
||||
# The accuracy corresponds to the bin size of a major axis.
|
||||
@@ -128,17 +128,18 @@ yradius = int(accum[0][4])
|
||||
angle = accum[0][5]
|
||||
|
||||
# Draw the ellipse on the original image
|
||||
cx, cy = ellipse_perimeter(center_y, center_x, yradius, xradius, orientation=angle)
|
||||
cx, cy = ellipse_perimeter(center_y, center_x,
|
||||
yradius, xradius, orientation=angle)
|
||||
image_rgb[cy, cx] = (0, 0, 220)
|
||||
# Draw the edge (white) and the resulting ellipse (red)
|
||||
edges = color.gray2rgb(edges)
|
||||
edges[cy, cx] = (250, 0, 0)
|
||||
|
||||
fig = plt.subplots(figsize=(10, 6))
|
||||
plt.subplot(1,2,1)
|
||||
plt.subplot(1, 2, 1)
|
||||
plt.title('Original picture')
|
||||
plt.imshow(image_rgb)
|
||||
plt.subplot(1,2,2)
|
||||
plt.subplot(1, 2, 2)
|
||||
plt.title('Edge (white) and result (red)')
|
||||
plt.imshow(edges)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user