【问题标题】:How to calculate signed and unsigned Gradient orientations in Matlab如何在 Matlab 中计算有符号和无符号梯度方向
【发布时间】:2015-10-09 11:29:31
【问题描述】:

在计算用于HOG描述符提取的梯度方向时,我们可以选择使用0-180或0-360之间的梯度方向,我们如何使用Matlab生成这样的角度?我有以下代码:

Im=imread('cameraman.tif'); // reading the image
Im=double(Im);  // converting it to double
hx = [-1,0,1];  // the gradient kernel for x direction
hy = -hx;      // the gradient kernel for y direction
grad_x = imfilter(Im,hx);   //gradient image in x direction
grad_y = imfilter(Im,hy);   // gradient image in y direction

% angles in 0-180:
...
%angles in 0-360:
...

【问题讨论】:

  • 您也可以使用计算机视觉系统工具箱中的extractHOGFeatures函数。

标签: matlab image-processing computer-vision feature-descriptor


【解决方案1】:

通常您可以使用atan2 生成介于-180 和180 之间的角度,给定您的水平和垂直梯度分量,从而产生有符号 角度。但是,如果您想要从 0 到 360 的角度或 无符号 角度,您所要做的就是搜索由 atan2 生成的任何负角度,并为每个角度添加 360。这将允许您获得[0,360) 之间的角度。例如,-5 度的角度实际上是 355 度无符号。因此:

angles = atan2(grad_y, grad_x); %// Signed
angles(angles < 0) = 2*pi + angles(angles < 0); %// Unsigned

这里atan2弧度,所以我们添加2*pi 而不是360 度。如果您想要度数而不是弧度,请使用等效度数调用:atan2d,因此:

angles = atan2d(grad_y, grad_x); %// Signed
angles(angles < 0) = 360 + angles(angles < 0); %// Unsigned

与您的 cmets 一起使用,您也想反其道而行之。基本上,如果给定一个无符号角,我们如何得到一个有符号角?只需做相反的事情。找出所有&gt; 180 的角度,然后用这个角度减去360。例如,182 无符号的角度是-178 有符号,或者182 - 360 = -178。

因此:

弧度

angles(angles > pi) = angles(angles > pi) - (2*pi); 

度数

angles(angles > 180) = angles(angles > 180) - 360;

【讨论】:

  • 非常感谢您的快速回答,我想问如果我想将角度从 0-360 映射到 0-180?
  • @Apastrix - 正好相反 :) 搜索 &gt; 180 的任何角度,然后减去 360 度。
  • @Apastrix - 我已经更新了我的帖子来做相反的事情。看看吧。
  • 在你的双重帮助下我很尴尬地问你这个问题,但在我的评论中我不想反过来,我想从 0-360 的角度开始,然后转到 0 的角度-180,所以我需要一个映射,其中 0 保持为 0,360 变为 180。
  • 如果您从 0-360 转到 0-180,您将忽略构成笛卡尔空间下半部分的角度。角度在 181 到 360(不包括在内)之间会发生什么情况?这些是如何映射的?
猜你喜欢
  • 2015-06-17
  • 1970-01-01
  • 2021-05-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多