边缘检测 matlab 代码,matlab边缘检测代码(包含roberts,sobel,prewitt三种算子)

代码

I=a;

BW1=edge(I,'roberts');

[BW1,thresh1]=edge(I,'roberts');

figure;

%subplot(1,2,1);

imshow(BW1);

BW1=edge(I,'roberts',0.05);

figure;

%subplot(1,2,2);

imshow(BW1);

BW2=edge(I,'sobel');

figure;

%subplot(1,3,1);

imshow(BW2);

[BW2,thresh2]=edge(I,'sobel');

BW2=edge(I,'roberts',0.05,'horizontal');

figure;

%subplot(1,3,2);

imshow(BW2);

BW2=edge(I,'roberts',0.05,'vertical');

%subplot(1,3,3);

imshow(BW2);

BW3=edge(I,'prewitt');

figure;

subplot(1,3,1);imshow(BW3);

[BW3,thresh3]=edge(I,'prewitt');

BW3=edge(I,'roberts',0.05,'horizontal');

subplot(1,3,2);imshow(BW3);

BW3=edge(I,'prewitt',0.05,'vertical');

subplot(1,3,3);imshow(BW3);

效果如下

原图:

0818b9ca8b590ca3270a3433284dd417.png

边缘检测:

0818b9ca8b590ca3270a3433284dd417.png