1.点检测
f=imread('point.tif');
w=[-1,-2,-1;0,0,0;1,2,1];
g=abs(imfilter(double(f),w));
T=max(g(:));
g1=g>=0.2*T;
subplot 121,imshow(f);title('原图')
subplot 122,imshow(g1);title('点检测')
g2=imsubtract(ordfilt2(f,1*5,ones(1,5)),ordfilt2(f,1,ones(1,5)));
T=max(g2(:));
g3=g2>=0.3*T;
subplot 121,imshow(f);title('原图')
subplot 122,imshow(g3);title('最大值与最小值检测')
2.线检测
f=imread('line.tif');
w=[2,-1,-1;-1,2,-1;-1,2,-1];%检测-45°直线
g=abs(imfilter(double(f),w));%double(f)防止截断
subplot 121,imshow(f);title('原图')
subplot 122,imshow(g,[]);title('线检测')
gtop=g(1:120,1:120);
%gtop=pixeldup(gtop,4);
gbot=g(end-119:end,end-119:end);
%gbot=pixeldup(gbot,4);
g=abs(g);
T=max(max(g));
g2=g>=0.6*T;
figure,
subplot 321,imshow(f);title('原图')
subplot 322,imshow(g);title('线检测')
subplot 323,imshow(gtop);title('顶部')
subplot 324,imshow(gbot);title('底部')
subplot 325,imshow(g2,[]);title('阈值')
3.边缘检测
f=imread('edge.tif');
[gv,t]=edge(f,'sobel','vertical');%垂直方向sobel
g=edge(f,'sobel',0.1,'vertical');
g1=edge(f,'sobel',0.1);
w=[-2,-1,0;-1,0,1;0,1,2];%检测45
g45=imfilter(double(f),w,'replicate');
T=0.2*max(abs(g45(:)));
g451=g45>=T;
subplot 321,imshow(f);title('原图')
subplot 322,imshow(gv);title('sobel默认阈值检测')
subplot 323,imshow(g);title('sobel大阈值垂直检测')
subplot 324,imshow(g1);title('sobel大阈值检测')
subplot 325,imshow(g45);title('45滤波')
subplot 326,imshow(g451,[]);title('45滤波阈值')