I = imread(‘einstein.bmp‘); I = rgb2gray(I); N = [1, 2, 1 0, 0, 0 -1,-2,-1]; edge_n = imfilter(I,N,‘symmetric‘,‘conv‘); imwrite(edge_n, ‘edge_n.jpg‘);
P160
I = rgb2gray(imread(‘lena.jpg‘)); M = [1,1,1 1,-8,1 1,1,1]; img=imfilter(I,M); [x,y]=size(I); img2 = img; for i = 2:x-1 for j = 2:y-1 a = [img(i,j+1),img(i,j-1),img(i+1,j+1),img(i+1,j-1), ... img(i-1,j+1),img(i-1,j-1),img(i+1,j),img(i-1,j)]; if ( (max(a)-min(a))>64 && max(a)>img(i,j) && min(a)<img(i,j)) img2(i,j)=255; else img2(i,j)=0; end end end