-
Notifications
You must be signed in to change notification settings - Fork 1
/
gradient2.m
executable file
·35 lines (34 loc) · 1.22 KB
/
gradient2.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
function [Gx,Gy] = gradient2( I )
% Compute numerical gradients along x and y directions.
%
% For 2D arrays identical to Matlab's gradient() with a spacing value of
% h=1 but ~10-20x faster (due to mexed implementation). Like gradient(),
% computes centered derivatives in interior of image and uncentered
% derivatives along boundaries. For 3D arrays computes x and y gradient
% separately for each channel and concatenates the results.
%
% This code requires SSE2 to compile and run (most modern Intel and AMD
% processors support SSE2). Please see: http://en.wikipedia.org/wiki/SSE2.
%
% USAGE
% [Gx,Gy] = gradient2( I )
%
% INPUTS
% I - [hxwxk] input k channel single image
%
% OUTPUTS
% Gx - [hxwxk] x-gradient (horizontal)
% Gy - [hxwxk] y-gradient (vertical)
%
% EXAMPLE
% I=single(imread('peppers.png'))/255;
% tic, [Gx1,Gy1]=gradient(I,1); toc
% tic, [Gx2,Gy2]=gradient2(I); toc
% isequal(Gx1,Gx2), isequal(Gy1,Gy2)
%
% See also gradient, gradientMag
%
% Piotr's Computer Vision Matlab Toolbox Version 3.00
% Copyright 2014 Piotr Dollar & Ron Appel. [pdollar-at-gmail.com]
% Licensed under the Simplified BSD License [see external/bsd.txt]
[Gx,Gy]=gradientMex('gradient2',I);