?? derterd.m
字號:
RGB = imread('tape.png'); %讀取圖片,數據存在RGB變量中;
I = rgb2gray(RGB); %將RGB轉換為灰度圖像數據;
threshold = graythresh(I); %獲取灰度圖像轉換時的閾值;
BW = im2bw(I,threshold); %將圖像轉換位2進制數據
dim = size(BW);
col = round(dim(2)/2)-90;
row = min(find(BW(:,col)));
connectivity = 8;
num_points = 180;
contour = bwtraceboundary(BW, [row, col], 'N', connectivity, num_points);
imshow(RGB);
hold on;
plot(contour(:,2),contour(:,1),'g','LineWidth',2);
x = contour(:,2);
y = contour(:,1);
abc=[x y ones(length(x),1)]\[-(x.^2+y.^2)];
a = abc(1); b = abc(2); c = abc(3);
xc = -a/2;
yc = -b/2;
radius = sqrt((xc^2+yc^2)-c)
plot(xc,yc,'yx','LineWidth',2);
theta = 0:0.01:2*pi;
Xfit = radius*cos(theta) + xc;
Yfit = radius*sin(theta) + yc;
plot(Xfit, Yfit);
message = sprintf('通過計算得到的半徑是 %2.3f pixels', radius);
text(15,15,message,'Color','y','FontWeight','bold');
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -