by:黄光耀
主函数:
% 文件2 main.m
clc,clear all
circleParaXYR=[];
I = imread(’.\裁剪\裁剪\51.jpg’);
[m,n,l] = size(I);
if l>1
I = rgb2gray(I);
end
BW = edge(I,‘sobel’);
step_r = 1;
step_angle = 0.1;
minr = 80;
maxr = 130;
thresh = 0.51;
[hough_space,hough_circle,para] = hough_circle(BW,step_r,step_angle,minr,maxr,thresh);
figure(1),imshow(I),title(‘原图’)
figure(2),imshow(BW),title(‘边缘’)
figure(3),imshow(hough_circle),title(‘检测结果’)
circleParaXYR=para;
%输出
fprintf(1,’\n---------------圆统计----------------\n’);
[r,c]=size(circleParaXYR);%r=size(circleParaXYR,1);
fprintf(1,’ 检测出%d个圆\n’,r);%圆的个数
fprintf(1,’ 圆心 半径\n’);%圆的个数
for n=1:r
fprintf(1,’%d (%d,%d) %d\n’,n,floor(circleParaXYR(n,1)),floor(circleParaXYR(n,2)),floor(circleParaXYR(n,3)));
end
%标出圆
figure(4),imshow(I),title(‘检测出图中的圆’)
hold on;
plot(circleParaXYR(:,2), circleParaXYR(:,1), ‘r+’);
for