Module Expr Str Import alias identifier Import alias identifier ImportFrom alias alias ImportFrom alias ImportFrom alias alias ImportFrom alias ImportFrom alias Assign NameStore Call NameLoad SubscriptLoad Call AttributeLoad NameLoad attr ExtSlice Slice Num Num Slice Num Num Assign NameStore Call NameLoad NameLoad keyword Num keyword Num keyword Num Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr keyword Num keyword Num keyword TupleLoad Num Num Assign NameStore Call AttributeLoad NameLoad attr Num Num Num Assign NameStore Call NameLoad NameLoad NameLoad Assign NameStore ListLoad Assign NameStore ListLoad Assign NameStore ListLoad For TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad body Assign NameStore Num Assign NameStore Call NameLoad NameLoad keyword NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Index TupleLoad SubscriptLoad NameLoad ExtSlice Slice Index Num SubscriptLoad NameLoad ExtSlice Slice Index Num Expr Call AttributeLoad NameLoad attr BinOpMult ListLoad NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad For NameStore SubscriptLoad SubscriptLoad Call AttributeLoad NameLoad attr NameLoad Slice Num Slice Num body Assign TupleStore NameStore NameStore SubscriptLoad NameLoad Index NameLoad Assign NameStore SubscriptLoad NameLoad Index NameLoad Assign TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad NameLoad Assign SubscriptStore NameLoad Index TupleLoad NameLoad NameLoad TupleLoad Num Num Num Expr Call AttributeLoad NameLoad attr NameLoad keyword AttributeLoad AttributeLoad NameLoad attr attr Expr Str Import alias identifier ImportFrom alias alias ImportFrom alias ImportFrom alias ImportFrom alias Assign NameStore SubscriptLoad Call AttributeLoad NameLoad attr ExtSlice Slice Num Num Slice Num Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call NameLoad NameLoad keyword Num keyword Num keyword Num Assign NameStore Call NameLoad NameLoad keyword Num keyword Num keyword Num keyword Num Expr Call AttributeLoad NameLoad attr keyword Str Assign NameStore Call NameLoad SubscriptLoad NameLoad Index Num Assign TupleStore NameStore NameStore NameStore NameStore ListComp Call NameLoad Call NameLoad NameLoad comprehension NameStore SubscriptLoad NameLoad Slice Num Num Assign NameStore SubscriptLoad NameLoad Index Num Assign TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad NameLoad NameLoad NameLoad Assign SubscriptStore NameLoad Index TupleLoad NameLoad NameLoad TupleLoad Num Num Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign SubscriptStore NameLoad Index TupleLoad NameLoad NameLoad TupleLoad Num Num Num Assign TupleStore NameStore TupleStore NameStore NameStore Call AttributeLoad NameLoad attr keyword Num keyword Num keyword TupleLoad Num Num keyword NameLoad keyword NameLoad keyword Dict Str Str Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr Expr Str
N/A N/A 
========================================
Circular and Elliptical Hough Transforms
========================================

The Hough transform in its simplest form is a `method to detect
straight lines <http://en.wikipedia.org/wiki/Hough_transform>`__
but it can also be used to detect circles or ellipses.
The algorithm assumes that the edge is detected and it is robust against
noise or missing points.

Circle detection
================

In the following example, the Hough transform is used to detect
coin positions and match their edges. We provide a range of
plausible radii. For each radius, two circles are extracted and
we finally keep the five most prominent candidates.
The result shows that coin positions are well-detected.


Algorithm overview
------------------

Given a black circle on a white background, we first guess its
radius (or a range of radii) to construct a new circle.
This circle is applied on each black pixel of the original picture
and the coordinates of this circle are voting in an accumulator.
From this geometrical construction, the original circle center
position receives the highest score.

Note that the accumulator size is built to be larger than the
original picture in order to detect centers outside the frame.
Its size is extended by two times the larger radius.

 N/A numpy np N/A matplotlib.pyplot plt skimage data color skimage.transform hough_circle skimage.feature peak_local_max canny skimage.draw circle_perimeter skimage.util img_as_ubyte N/A image N/A img_as_ubyte N/A N/A N/A data coins N/A N/A 0 95 N/A 70 370 N/A edges N/A canny image sigma 3 low_threshold 10 high_threshold 50 N/A N/A fig ax N/A N/A plt subplots ncols 1 nrows 1 figsize N/A 5 2 N/A hough_radii N/A N/A np arange 15 30 2 N/A hough_res N/A hough_circle edges hough_radii N/A centers N/A N/A accums N/A N/A radii N/A N/A N/A radius h N/A zip hough_radii hough_res N/A N/A num_peaks 2 N/A peaks N/A peak_local_max h num_peaks num_peaks N/A N/A N/A centers extend peaks N/A N/A N/A accums extend N/A h N/A N/A N/A peaks N/A N/A N/A 0 N/A peaks N/A N/A N/A 1 N/A N/A N/A radii extend N/A N/A radius num_peaks N/A image N/A N/A color gray2rgb image N/A idx N/A N/A N/A N/A np argsort accums N/A -1 N/A 5 N/A N/A N/A center_x center_y N/A centers N/A idx N/A radius N/A radii N/A idx N/A N/A cx cy N/A circle_perimeter center_y center_x radius N/A N/A image N/A N/A cy cx N/A 220 20 20 N/A N/A N/A ax imshow image cmap N/A N/A plt cm gray N/A 
.. image:: PLOT2RST.current_figure

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 because 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.

A full description of the algorithm can be found in reference [1]_.

References
----------
.. [1] Xie, Yonghong, and Qiang Ji. "A new efficient ellipse detection
       method." Pattern Recognition, 2002. Proceedings. 16th International
       Conference on. Vol. 2. IEEE, 2002
 N/A matplotlib.pyplot plt skimage data color skimage.feature canny skimage.transform hough_ellipse skimage.draw ellipse_perimeter N/A image_rgb N/A N/A N/A data coffee N/A N/A 0 220 N/A 160 420 N/A image_gray N/A N/A color rgb2gray image_rgb N/A edges N/A canny image_gray sigma 2.0 low_threshold 0.55 high_threshold 0.8 N/A result N/A hough_ellipse edges accuracy 20 threshold 250 min_size 100 max_size 120 N/A N/A N/A result sort order accumulator N/A best N/A list N/A result N/A -1 N/A N/A yc xc a b N/A N/A int N/A round x N/A x N/A best N/A 1 5 N/A orientation N/A best N/A 5 N/A N/A cy cx N/A ellipse_perimeter yc xc a b orientation N/A N/A image_rgb N/A N/A cy cx N/A 0 0 255 N/A edges N/A N/A color gray2rgb edges N/A N/A edges N/A N/A cy cx N/A 250 0 0 N/A N/A fig2 N/A ax1 ax2 N/A N/A plt subplots ncols 2 nrows 1 figsize N/A 8 4 sharex True sharey True subplot_kw N/A adjustable box-forced N/A N/A N/A ax1 set_title Original picture N/A N/A N/A ax1 imshow image_rgb N/A N/A N/A ax2 set_title Edge (white) and result (red) N/A N/A N/A ax2 imshow edges N/A N/A N/A plt show N/A 
.. image:: PLOT2RST.current_figure

