早教吧 育儿知识 作业答案 考试题库 百科 知识分享

Hough变换对圆的检测运行一直出现Center251radius20InanassignmentA(:,matrix)=B,thenumbclc,clearallI=imread('e:\2.bmp');[m,n,l]=size(I);ifl>1I=rgb2gray(I);endBW=edge(I,'sobel');stepr=1;stepangle=0.1;minr=20;maxr

题目详情
Hough变换对圆的检测 运行一直出现Center 25 1 radius 20 In an assignment A(:,matrix) = B,the numb
clc,clear all
I = imread('e:\2.bmp');
[m,n,l] = size(I);
if l>1
I = rgb2gray(I);
end
BW = edge(I,'sobel');
step_r = 1;
step_angle = 0.1;
minr = 20;
maxr = 30;
thresh = 0.7;
[hough_space,hough_circle,para] = hough_circle(BW,step_r,step_angle,minr,maxr,thresh);
subplot(221),imshow(I),title('原图')
subplot(222),imshow(BW),title('边缘')
subplot(223),imshow(hough_circle),title('检测结果')
function [hough_space,hough_circle,para] = hough_circle(BW,step_r,step_angle,r_min,r_max,p)
% %%%%%%%%%%%%%%%%%%%%%%%%%%
% input
% BW:二值图像;
% step_r:检测的圆半径步长
% step_angle:角度步长,单位为弧度
% r_min:最小圆半径
% r_max:最大圆半径
% p:阈值,0,1之间的数
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% output
% hough_space:参数空间,h(a,b,r)表示圆心在(a,b)半径为r的圆上的点数
% hough_circl:二值图像,检测到的圆
% para:检测到的圆的圆心、半径
[m,n] = size(BW); %求出图像大小
size_r = round((r_max-r_min)/step_r)+1; %round 作用四舍五入 对圆半径步长四舍五入
size_angle = round(2*pi/step_angle); %
hough_space = zeros(m,n,size_r); %创建一个矩阵
[rows,cols] = find(BW); %返回矩阵BW中非零元素的行和列的索引值
ecount = size(rows); %rows 有多少个
% Hough变换
% 将图像空间(x,y)对应到参数空间(a,b,r)
% a = x-r*cos(angle)
% b = y-r*sin(angle)
for i=1:ecount
for r=1:size_r
for k=1:size_angle
a = round(rows(i)-(r_min+(r-1)*step_r)*cos(k*step_angle));
b = round(cols(i)-(r_min+(r-1)*step_r)*sin(k*step_angle));
if(a>0&a0&b=max_ow*p);
length = size(index);
hough_circle = false(m,n);
for i=1:ecount
for k=1:length
par3 = floor(index(k)/(m*n))+1;
par2 = floor((index(k)-(par3-1)*(m*n))/m)+1;
par1 = index(k)-(par3-1)*(m*n)-(par2-1)*m;
if((rows(i)-par1)^2+(cols(i)-par2)^2(r_min+(par3-1)*step_r)^2-5)
hough_circle(rows(i),cols(i)) = true;
end
end
end
% 打印检测结果
for k=1:length
par3 = floor(index(k)/(m*n))+1;
par2 = floor((index(k)-(par3-1)*(m*n))/m)+1;
par1 = index(k)-(par3-1)*(m*n)-(par2-1)*m;
par3 = r_min+(par3-1)*step_r;
fprintf(1,'Center %d %d radius %d\n',par1,par2,par3);
para(:,k) = [par1,par2,par3];
end
网上大家都是用这个程序,但是我的一直运行不了
每次都出现
Center 25 1 radius 20
In an assignment A(:,matrix) = B,the number of elements in the subscript of A and the number
of columns in B must be the same.
万分感激.
▼优质解答
答案和解析
[hough_space,hough_circle,para] = hough_circle(BW,step_r,step_angle,minr,maxr,thresh);
运行这一句的时候显示 ? Undefined function or method 'hough_circle'
for input arguments of type 'double'.应该怎么改正啊 ?