【发布时间】:2013-12-16 08:56:16
【问题描述】:
我从书 Feature Extraction & Image Processing 中得到了一个代码。
由于我是 Matlab 的初学者,我不知道如何运行这些代码来查看结果。
它们是否完整?
第一个:线的霍夫变换
%Polar Hough Transform for Lines
function HTPLine(inputimage)
%image size
[rows,columns]=size(inputimage);
%accumulator
rmax=round(sqrt(rows^2+columns^2));
acc=zeros(rmax,180);
%image
for x=1:columns
for y=1:rows
if(inputimage(y,x)==0)
for m=1:180
r=round(x*cos((m*pi)/180)+y*sin(m*pi)/180);
if(r0) acc(r,m)=acc(r,m)+1; end
end
end
end
end
第二个:圆的霍夫变换
%Hough Transform for Circles
function HTCircle(inputimage,r)
%image size
[rows,columns]=size(inputimage);
%accumulator
acc=zeros(rows,columns);
%image
for x=1:columns
for y=1:rows
if(inputimage(y,x)==0)
for ang=0:360
t=(ang*pi)/180;
x0=round(x-r*cos(t));
y0=round(y-r*sin(t));
if(x00 & y00)
acc(y0,x0)=acc(y0,x0)+1;
end
end
end
end
end
第三个:省略的霍夫变换
%Hough Transform for Ellipses
function HTEllipse(inputimage,a,b)
%image size
[rows,columns]=size(inputimage);
%accumulator
acc=zeros(rows,columns);
%image
for x=1:columns
for y=1:rows
if(inputimage(y,x)==0)
for ang=0:360
t=(ang*pi)/180;
x0=round(x-a*cos(t));
y0=round(y-b*sin(t));
if(x00 & y0< rows & y0>0)
acc(y0,x0)=acc(y0,x0)+1;
end
end
end
end
end
我有运行这些程序所需的图像 (png)。 但我似乎无法运行它。 我创建新脚本,粘贴代码,保存它并在主窗口中运行函数名称发送图像路径作为参数。它什么都不做,没有消息。
【问题讨论】: