%% edgedet.m %% demonstrate edge detection %% S. Allen Broughton - 7 Mar 01 % get image from MATLAB image load('trees'); % show original image figure(1); imshow(real(X),[]); title('original image'); drawnow; % construct convolution functions [m,n] = size(X); g = [1 -1]; h = [1; -1]; % construct convolution matrices as sparse matrices Wg = circconv2(X,g); Wh = circconv2(X,h); % show transformed images figure(2); imshow(Wg,[]); title('horizontal difference filtering'); drawnow; figure(3) imshow(Wh,[]); title('vertical difference filtering'); drawnow; figure(4) imshow(abs(Wg)+abs(Wh),[]); title('edges'); drawnow; % truncate and show edges figure(5) W = abs(Wg)+abs(Wh); Y = zeros(size(W)); M = max(W(:)); J = find(W > .2*M); Y(J) = W(J); imshow(Y,[]); title('edges after thresholding truncation'); drawnow;