hog算子matlab实现程序,HOG Matlab实现

看SURF结果把HOG看的太细了 都是学习 就记一下HOG的matlab实现  方便以后学习

function [gMag,gDir] = computeGradient(img)

gx = zeros(size(img),class(img));

gy = zeros(size(img),class(img));

gx(:,2:end-1) = conv2(img, [1 0 -1], 'valid');

gy(2:end-1,:) = conv2(img, [1;0;-1], 'valid');

% forward difference on borders

gx(:,1) = img(:,2) - img(:,1);

gx(:,end) = img(:,end) - img(:,end-1);

gy(1,:) = img(2,:) - img(1,:);

gy(end,:) = img(end,:) - img(end-1,:);

% return magnitude and direction

gMag = hypot(gx,gy);

gDir = atan2d(-gy,gx);

hypot是matlab自带的一个函数  看解释

%HYPOT Robust computation of the square root of the sum of squares

% C = HYPOT(A,B) returns SQRT(ABS(A).^2+ABS(B).^2) carefully computed to

% avoid underflow and overflow.

%

% Example:

% format short e

% a = 3*[1e300 1e-300]

% b = 4*[1e300 1e-300]

% c1 = sqrt(a.^2 + b.^2)

% c2 = hypot(a,b)

%

% x = 1.271161e308

% y = hypot(x,x)

%

% Class support for inputs A, B:

% float: double, single

%

% See also ABS, NORM, SQRT.

% Copyright 1984-2008 The MathWorks, Inc.

% $Revision: 1.1.6.2 $ $Date: 2008/03/13 17:32:00 $

% Built-in function.

然后ATAN2D(Y,X)也是

%ATAN2D Four quadrant inverse tangent, result in degrees.

% ATAN2D(Y,X) is the four quadrant arctangent of the elements

% of X and Y. -180 <= ATAN2D(Y,X) <= 180.

%

% See also ATAND, ATAN2.

% Copyright 1984-2011 The MathWorks, Inc.

% $Revision: 1.1.6.1 $ $Date: 2011/12/16 16:32:53 $

% Built-in function. 以上工作都是为了计算梯度,那HOG到底是什么呢,往下看

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值