-
Notifications
You must be signed in to change notification settings - Fork 0
/
imgrad.m
41 lines (37 loc) · 1.03 KB
/
imgrad.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
% imgrad calculates horizontal and vertical gradients.
%
% [Fh Fv Bh Bv] = imgrad(X)
%
%Output parameters:
% Fh: forward horizontal diference
% Fv: forward vertical diference
% Bh: forward horizontal diference
% Bv: forward vertical diference
%
%
%Input parameters:
% X: input image
%
%
%Example:
% X = imread('img.png');
% [Fh Fv] = imgrad(X);
%
%
%Version: 20120604
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Miscellaneous tools for image processing %
% %
% Copyright (C) 2012 Masayuki Tanaka. All rights reserved. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [Fh Fv Bh Bv] = imgrad(X)
Kh = [ 0,-1, 1 ];
Kv = [ 0;-1; 1 ];
Fh = imfilter(X,Kh,'replicate');
Fv = imfilter(X,Kv,'replicate');
if( nargout >= 3 )
Bh = circshift(Fh,[0,1]);
Bv = circshift(Fv,[1,0]);
end