www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ExtractEdgesFromRaisedPedestalExample.m

    %% Extract Edges from Raised Pedestal
% In image processing, the Sobel edge finding operation is a
% two-dimensional convolution of an input array with the special matrix:

% Copyright 2015 The MathWorks, Inc.

s = [1 2 1; 0 0 0; -1 -2 -1];

%%
% These commands extract the horizontal edges from a raised pedestal.
A = zeros(10);
A(3:7,3:7) = ones(5);
H = conv2(A,s);
figure, mesh(H)

%%
% Transposing the filter |s| extracts the vertical edges of |A|.
V = conv2(A,s');
figure, mesh(V)

%%
% This figure combines both horizontal and vertical edges.
figure
mesh(sqrt(H.^2 + V.^2))