hough 变换检测圆的 matlab 程序 1hough 变换检测圆的 matlab 程序 1 function [y0detect, x0detect, Accumulator] = houghcircle(Imbinary, r, thresh) %HOUGHCIRCLEdetects circles with specific radius in a binary image. % %Comments: % Function uses Standard Hough Transform to detect circles in a binary image. % According to the Hough Transform for circles, each pixel in image space % corresponds to a circle in Hough space and vise versa. % upper left corner of image is the origin of coordinate system. % %Usage: [y0detect, x0detect, Accumulator] = houghcircle(Imbinary, r, thresh) % %Arguments: % Imbinarya binary image. image pixels that have value equal to 1 are % interested pixels for HOUGHLINE function. % rradius of circles. % thresha threshold value that determines the minimum number of % pixels that belong to a circle in image space. threshold must be % bigger than or equal to 4(default) . % %Returns: % y0detectrow coordinates of detected circles. % x0detectcolumn coordinates of detected circles. % Accumulatorthe accumulator array in Hough space. % %Written by : % Amin Sarafraz % Photogrammetry elseif thresh size(Imbinary, 2) ) high=size(Imbinary, 2) ; end for x0 = low:high y01 = ysqrt(r^2(xx0) ^2) ; y02 = y+sqrt(r^2(xx0) ^2) ; y01 = round(y01) ; y02 = round(y02) ; if y01 = 1 Accumulator(y01, x0) = Accumulator(y01, x0) +1; end if y02 = 1 Accumulator(y02, x0) = Accumulator(y02, x0) +1; end end % % low=xIndex(cnt) r; % high=xIndex(cnt) +r; % if (lowsize(Imbinary, 2) ) high=size(Imbinary, 2) ; end % for x0 = low:high % y01 = yIndex(cnt) sqrt(r^2(xIndex(cnt) x0) ^2) ; % y02 = yIndex(cnt) +sqrt(r^2(xIndex(cnt) x0) ^2) ; % y01 = round(y01) ; y02 = round(y02) ; % if y01 = 1 % Accumulator(y01, x0) = Accumulator(y01, x0) +1; % end % if y02 = 1 % Accumulator(y02, x0) = Accumulator(y02, x0) +1; % end % end end % Finding local maxima in Accumulator y0detect = [] ; x0detect = []; AccumulatorbinaryMax = imregionalmax(Accumulator) ; [Potential_y0 Potential_x0] = find(AccumulatorbinaryMax == 1) ; Accumulatortemp = Accumulatorthresh; for cnt = 1:length(Potential_y0) if Accumulatortemp(Potential_y0(cnt) , Potential_x0(cnt) ) >= 0 y0detect = [y0detect; Potential_y0(cnt) ] ; x0detect = [x0detect; Potential_x0(cnt) ] ; end end