Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 工程数学软件 > MATLAB论坛
MATLAB论坛 一切MATLAB相关问题在此讨论。
回复
 
主题工具 显示模式
旧 2007-06-13, 19:55   #1
firefly
初级会员
 
注册日期: 2007-05-30
帖子: 3
声望力: 0
firefly 正向着好的方向发展
默认 【求助】关于Demos里的一个程序!

Image Processing Toolbox Demos里面的Measuring Image Features里的例子Measuring the Radius of a Role of Tape的程序有一处看不太明白,程序如下:
RGB = imread('tape.png');
imshow(RGB);
text(15,15,'Estimate radius of the roll of tape',...
'FontWeight','bold','Color','y');
I = rgb2gray(RGB);
threshold = graythresh(I);
BW = im2bw(I,threshold);
imshow(BW);
dim = size(BW);
col = round(dim(2)/2)-90;---?此处为什么要减90?什么意思啊?
row = min(find(BW(:,col)));
connectivity = 8;
num_points = 180;-
---?此两处的赋值为什么是8和180?可以是别的吗?
contour = bwtraceboundary(BW, [row, col], 'N', connectivity, num_points);

imshow(RGB);
hold on;----?hold on 什么意思?

plot(contour(:,2),contour(:,1),'g','LineWidth',2);
x = contour(:,2);
y = contour(:,1);

% solve for parameters a, b, and c in the least-squares sense by
% using the backslash operator
abc=[x y ones(length(x),1)]\[-(x.^2+y.^2)];
a = abc(1); b = abc(2); c = abc(3);

% calculate the location of the center and the radius
xc = -a/2;
yc = -b/2;
radius = sqrt((xc^2+yc^2)-c)

% display the calculated center
plot(xc,yc,'yx','LineWidth',2);

% plot the entire circle
theta = 0:0.01:2*pi;

% use parametric representation of the circle to obtain coordinates
% of points on the circle
Xfit = radius*cos(theta) + xc;
Yfit = radius*sin(theta) + yc;

plot(Xfit, Yfit);

message = sprintf('The estimated radius is %2.3f pixels', radius);
text(15,15,message,'Color','y','FontWeight','bold');


谢谢先!
firefly 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码



所有时间均为北京时间。现在的时间是 08:36


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.