-
Notifications
You must be signed in to change notification settings - Fork 2
/
GradientMethod.m
48 lines (44 loc) · 1.22 KB
/
GradientMethod.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
% GradientMethod.m
% -------------------------------------------------------------------
%
% Authors: Sun Li
% Date: 14/03/2013
% Last modified: 2/04/2013
% -------------------------------------------------------------------
function [dx, dy] = GradientMethod(img, meth)
if ~exist('meth', 'var'),
meth = 'defaute';
end
if strcmp(meth, 'sobel'),
disp('Sobel Gradient');
Sv = [-1 -2 -1;...
0 0 0;...
1 2 1];
Sh = [-1 0 1;
-2 0 2;
-1 0 1];
dx=conv2(img, -Sh/8,'same'); % ¾í»ý¼Ó¸ö¸ººÅ
dy=conv2(img, -Sv/8,'same');
elseif strcmp(meth, 'zhou')
fx=[ 0, 0, 0;...
-1, 1, 0;...
0, 0, 0];
fy=[0, -1, 0;...
0, 1, 0;...
0, 0 0];
dx = imfilter(img, fx, 0, 'corr');
dy = imfilter(img, fy, 0, 'corr');
else
disp('The default gradient ...');
[dx, dy] = gradient(img);
end
step = 1;
dx(1:step, :) = 0;
dx(end-step+1:end, :) = 0;
dx(:, 1:step) = 0;
dx(:, end-step+1:end) = 0;
dy(1:step, :) = 0;
dy(end-step+1:end, :) = 0;
dy(:, 1:step) = 0;
dy(:, end-step+1:end) = 0;
end