資源簡介
MATLAB實現鋼銷直徑測量,并達到一定精度,附實驗報告

代碼片段和文件信息
function?D=Measure_sun(img)
image_gray=?rgb2gray(img);?%?圖像轉灰度
figure(1)subplot(121)imshow(img)title(‘原始圖像‘);
subplot(122)imshow(image_gray)title(‘灰度圖像‘);
[xy]=size(image_gray);????????????%?求出圖象大小
image_bw=~im2bw(image_gray0.5);????%二值化并取反
figure(2)imshow(image_bw)title(‘二值化并取反圖像‘);
image_cut=image_bw(600:x-600600:y-600);?%圖像截取
image_cut=?bwareaopen(image_cut10);?????%去除連通域小于10個像素的區域
[Lnum]?=?bwlabel(image_cut8);
s=zeros(size(image_cut));
s(find(L==2))=1;??%提取第二個連通域,并計算第二個連通域的像素值
sm=sum(sum(s));
figure(3)imshow(s)title(‘連通域圖‘);
image_edge=?edge(s‘canny‘);????????????????%?調用canny函數??
figure(4)imshow(image_edge)title(‘邊緣檢測圖像‘);
%-----------------------------擬合直線并求d---------------------------%
[uv]=size(image_edge);
[mn]=find(image_edge==1);
n_mean=mean(n);
image_edge(1:un_mean:v)=zeros();
figure(5)imshow(image_edge)title(‘一側邊緣‘);
[m1n1]=find(image_edge==1);
p1?=?polyfit(m1n11);
z=polyval(p1m1);?
figure(6)plot(m1z)title(‘直線擬合‘);
k1=p1(1);?%斜率
theta=atan(k1);
b1=p1(2);%截距
D=(sm./u)*cos(theta);%直徑
%?end
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1195??2015-11-30?10:16??機器視覺期末作業\Measure_sun.m
?????文件????????360??2015-11-30?10:19??機器視覺期末作業\Unti
?????文件?????299008??2015-11-30?10:15??機器視覺期末作業\實驗報告.doc
?????目錄??????????0??2015-11-30?10:18??機器視覺期末作業
-----------?---------??----------?-----??----
???????????????300563????????????????????4
- 上一篇:adaboost詳解及matlab
- 下一篇:MATLAB風機的demo
評論
共有 條評論