%%Sobel&prewitt&Roberts边缘检测器
%%
clear all;
close all;
f=imread('D:\1.jpg');
%[gv,t]=edge(f,'sobel','vertical');
%imshow(gv)
I=rgb2gray(f);
J1=edge(I,'Sobel');
J2=edge(I,'prewitt');
J3=edge(I,'Roberts');
figure;
subplot(221),imshow(I);
subplot(222),imshow(J1);title('Sobel');
subplot(223),imshow(J2);title('prewitt');
subplot(224),imshow(J3);title('Roberts');
imhist(I); % 观察灰度直方图, 灰度140处有谷,确定阈值T=140
I1=im2bw(I,140/255); % im2bw函数需要将灰度值转换到[0,1]范围内
figure,imshow(I1);