Fit_Ellipse
This program fits an ellipse to an ROI given by a vector of ROI indices.
FANNING SOFTWARE CONSULTING David Fanning, Ph.D. 1645 Sheely Drive Fort Collins, CO 80526 USA Phone: 970-221-0438 E-mail: david@idlcoyote.com Coyote's Guide to IDL Programming: http://www.idlcoyote.com
Graphics, math.
ellipsePts = Fit_Ellipse(indices)
indices - A 1D vector of pixel indices that describe the ROI. For example, the indices may be returned as a result of the WHERE function.
ellipsePts - A 2-by-npoints array of the X and Y points that describe the fitted ellipse. The points are in the device coodinate system.
NPOINTS - The number of points in the fitted ellipse. Set to 120 by default. SCALE - A two-element array that gives the scaling parameters for each X and Y pixel, respectively. Set to [1.0,1.0] by default. XSIZE - The X size of the window or array from which the ROI indices are taken. Set to !D.X_Size by default. YSIZE - The Y size of the window or array from which the ROI indices are taken. Set to !D.Y_Size by default.
CENTER -- Set to a named variable that contains the X and Y location of the center of the fitted ellipse in device coordinates. ORIENTATION - Set to a named variable that contains the orientation of the major axis of the fitted ellipse. The direction is calculated in degrees counter-clockwise from the X axis. AXES - A two element array that contains the length of the major and minor axes of the fitted ellipse, respectively. SEMIAXES - A two element array that contains the length of the semi-major and semi-minor axes of the fitted ellipse, respectively. (This is simple AXES/2.) LE: LoadCT, 0, /Silent image = BytArr(400, 300)+125 image[180:245, 125:175] = 255B indices = Where(image EQ 255) Window, XSize=400, YSize=300 TV, image PLOTS, Fit_Ellipse(indices, XSize=400, YSize=300), /Device, Color=cgColor('red')
Written by David W. Fanning, April 2002. Based on algorithms provided by Craig Markwardt and Wayne Landsman in his TVEllipse program. Added SCALE keyword and modified the algorithm to use memory more efficiently. I no longer have to make huge arrays. The arrays are only as big as the blob being fitted. 17 AUG 2008. DWF. Fixed small typo that caused blobs of indices with a longer X axis than Y axis to misrepresent the center of the ellipse. 23 February 2009.