houghcircles matlab,hough变换检测圆的matlab程序 1

function [y0detect,x0detect,Accumulator] = houghcircle(Imbinary,r,thresh)

%HOUGHCIRCLE - detects 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:

% Imbinary - a binary image. image pixels that have value equal to 1 are

% interested pixels for HOUGHLINE function.

% r - radius of circles.

% thresh - a 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:

% y0detect - row coordinates of detected circles.

% x0detect - column coordinates of detected circles.

% Accumulator - the accumulator array in Hough space.

%

%Written by :

% Amin Sarafraz

% Photogrammetry & Computer Vision Devision

% Geomatics Department,Faculty of Engineering

% University of Tehran,Iran

% sarafraz@geomatics.ut.ac.ir

%

%May 5,2004 - Original version

%November 24,2004 - Modified version,faster and better performance

if nargin == 2

thresh = 4;

elseif thresh < 4

error('treshold value must be bigger or equal to 4');

return

end

%Voting

Accumulator = zeros(size(Imbinary));

[yIndex xIndex] = find(Imbinary);

for cnt = 1:length(xIndex)

low=x-r;

high=x+r;

if (low<1) low=1; end

if (high>size(Imbinary,2)) high=size(Imbinary,2); end

for x0 = low:high

y01 = y-sqrt(r^2-(x-x0)^2);

y02 = y+sqrt(r^2-(x-x0)^2);

y01 = round(y01); y02 = round(y02);

if y01 < size(Imbinary,1) & y01 >= 1

Accumulator(y01,x0) = Accumulator(y01,x0)+1;

end

if y02 < size(Imbinary,1) & y02 >= 1

Accumulator(y02,x0) = Accumulator(y02,x0)+1;

end

end

%

% low=xIndex(cnt)-r;

% high=xIndex(cnt)+r;

% if (low<1) low=1; end

% if (high>size(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 < size(Imbinary,1) & y01 >= 1

% Accumulator(y01,x0) = Accumulator(y01,x0)+1;

% end

% if y02 < size(Imbinary,1) & y02 >= 1

% Accumulator(y02,x0) = Accumulator(y02,x0)+1;

% end

% end

end

% Finding local maxima in Accumulator

y0detect = []; x0detect = [];

AccumulatorbinaryMax = imregionalma

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值