Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
|
![]() |
#1 |
初级会员
注册日期: 2007-05-30
帖子: 3
声望力: 0 ![]() |
![]()
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'); 谢谢先! |
![]() |
![]() |