Code covered by the BSD License  

Highlights from
Detect circles with various radii in grayscale image via Hough Transform

image thumbnail

Detect circles with various radii in grayscale image via Hough Transform

by

 

27 Nov 2005 (Updated )

Detect circular shapes in a grayscale image. Resolve their center positions and radii.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

DrawCircle(x, y, r, nseg, S)
function DrawCircle(x, y, r, nseg, S)
% Draw a circle on the current figure using ploylines
%
%  DrawCircle(x, y, r, nseg, S)
%  A simple function for drawing a circle on graph.
%
%  INPUT: (x, y, r, nseg, S)
%  x, y:    Center of the circle
%  r:       Radius of the circle
%  nseg:    Number of segments for the circle
%  S:       Colors, plot symbols and line types
%
%  OUTPUT: None
%
%  BUG REPORT:
%  Please send your bug reports, comments and suggestions to
%  pengtao@glue.umd.edu . Thanks.

%  Author:  Tao Peng
%           Department of Mechanical Engineering
%           University of Maryland, College Park, Maryland 20742, USA
%           pengtao@glue.umd.edu
%  Version: alpha       Revision: Jan. 10, 2006


theta = 0 : (2 * pi / nseg) : (2 * pi);
pline_x = r * cos(theta) + x;
pline_y = r * sin(theta) + y;

plot(pline_x, pline_y, S);

Contact us