边缘检测

2019-04-15 12:43发布

1.一阶边缘检测

newpic(i, j) = |2*pic(i, j) - pic(i+1,j) - pic(i, j+1)| pic = imread('C:UserslenovoDesktop素材ea2f2780b0ca47909964541cf58a076e.jpg'); pic = rgb2gray(pic); figure; imshow(pic); figure; [m n] = size(pic); newPic = zeros(m, n); for i = 1 : m-1 for j = 1 : n-1 newPic(i, j) = 2*pic(i, j) - pic(i, j+1) - pic(i+1, j); if newPic(i, j) < 0 newPic(i, j) = -newPic(i, j); end; %fprintf('%d ', newPic(i, j)); end; end; %newPic = uint8(newPic); disp(newPic); imshow(newPic); 效果图            

2.Roberts交叉算子

pic = imread('C:UserslenovoDesktop素材ea2f2780b0ca47909964541cf58a076e.jpg'); pic = rgb2gray(pic); figure; imshow(pic); figure; [m n] = size(pic); newPic = zeros(m, n); for i = 1 : m-1 for j = 1 : n-1 temp1 = abs(pic(i, j) - pic(i+1, j+1)); temp2 = abs(pic(i+1, j) - pic(i, j+1)); if temp1 > temp2 newPic(i, j) = temp1; else newPic(i, j) = temp2; end; end; end; %disp(newPic); %newPic = uint8(newPic); imshow(newPic);