end
re=zeros(m+2,n+2);
tmp(2:m+1,2:n+1)=R; bw1_re=zeros(m+2,n+2); bw1_re(2:m+1,2:n+1)=bw1; for i=2:m+1 for j=2:n+1
if tmp(i,j)>0.01*Rmax &&... tmp(i,j)>tmp(i-1,j-1) && tmp(i,j)>tmp(i-1,j) && tmp(i,j)>tmp(i-1,j+1) &&...
tmp(i,j)>tmp(i,j-1) && tmp(i,j)>tmp(i,j+1) &&...
tmp(i,j)>tmp(i+1,j-1) && tmp(i,j)>tmp(i+1,j) && tmp(i,j)>tmp(i+1,j+1) bw1_re(i,j)=255; end end end
figure,imshow(mat2gray(bw1_re(2:m+1,2:n+1))
);
5、分别统计出大齿轮和小齿轮上面齿的个数和每个齿轮上齿之间的角度
[labeled,numobjects]=bwlabel(mat2gray(bw1_re(2:m+1,2:n+1)),8);%大轮90度的数目
>> j=numobjects*4 %大齿轮总数目
cropimg1 = imcrop(mat2gray(bw1_re(2:m+1,2:n+1)));%裁剪90度
imshow(cropimg1)
[r,c]=find(cropimg1==1); num1=length(r); >> num1
num1 =
27 %小齿轮90度的齿数
>> j1=(num1-2)/2 j1 =
12.5000
>> min=j1*4 %小齿轮总的齿数
min =
50
6、结束语:
在传统的检测像素的82邻域点优化轮廓