这里只上传源代码吧:http://www.pudn.com/downloads386/sourcecode/graph/texture_mapping/detail1655723.html
clc
close all
clear all
%%%%%%%%%%%%%
I=imread('2.jpg');
figure;imshow(I);
I1=rgb2gray(I);
figure;imshow(I1);
I2=medfilt2(I1,[3,3]);
figure, imshow(I2);
se=strel('disk',1); %采用半径为1的圆作为结构元素
I3=imopen(I2,se);
figure;imshow(I3);
I4=edge(I3,'sobel');
figure;imshow(I4);
[m,n]=size(I4)
num1=sum(sum(I4))
%%%%%%%%%%%
II=imread('5.jpg');
figure;imshow(II);
II1=rgb2gray(II);
figure;imshow(II1);
II2=medfilt2(II1,[3,3]);
figure, imshow(II2);
se=strel('disk',1); %采用半径为1的圆作为结构元素
II3=imopen(II2,se);
figure;imshow(II3);
II4=edge(II3,'sobel');
figure;imshow(II4);
imwrite(II4,'test.bmp');
[m,n]=size(II4)
num2=sum(sum(II4))
if num1>num2
disp('2.jpg 有孔')
else
disp('5.jpg 有孔')
end
%求最窄处
clc;
close all;
clear all;
II=imread('2.jpg');
figure;imshow(II);
II1=rgb2gray(II);
figure;imshow(II1);
II2=medfilt2(II1,[3,3]);
figure, imshow(II2);
se=strel('disk',1); %采用半径为1的圆作为结构元素
II3=imopen(II2,se);
figure;imshow(II3);
II4=edge(II3,'sobel');
figure;imshow(II4);
imwrite(II4,'test.bmp');
[m,n]=size(II4)
sum(m)=0;
for x=1:m
jy(n)=0;j=1;xx=0;
for y=1:n
if II4(x,y)==1
xx=1;
end
if xx==1
jy(j)=y;
j=j+1;
end
end
jy=jy(1);
iy(n)=0;j=1;xx=0;
for y=n:-1:1
if II4(x,y)==1
xx=1;
end
if xx==1
iy(j)=y;
j=j+1;
end
end
iy=iy(1);
sum(x)=iy-jy%扫描每一行的像素区间并显示
end
nmin=sum(20);
for x=1:m%求所有行中间的最小值,就是最短值
if (sum(x)>10) && (sum(x)<100)
%nmin=sum(1)
if sum(x)<nmin
nmin=sum(x)
end
end
end
nmin
disp('最短像素是')
length=nmin/28.346
disp('cm')