【问题标题】:Range of atan2, confusion when using coordinates of a photoatan2的范围,使用照片坐标时的混乱
【发布时间】:2013-09-24 08:36:35
【问题描述】:

我在黑白图像中有一些点。我有质心的坐标 x,y,我想顺时针排列它们。为此,我想使用角度。但是我有一个很大的困惑:我假设 atan2 的坐标轴在我照片的中心。然后,我使用其中一个点作为偏移来使那里的角度为零。

我对此完全感到困惑吗?这有那么难实现吗?我只想得到所有点的角度,角度零是我选择的一个点,然后使用这些角度以顺时针方向(增加角度方向)对质心进行排序。

希望能在您的帮助下解决这个问题!非常感谢, 赫克托

【问题讨论】:

  • 这应该不会太难。但是请给我们一些代码和一个好的错误报告(你期望什么?发生了什么?)示例图像连同代码和预期结果也会有所帮助。 (另外,atan2 的原点在 0|0)

标签: matlab image-processing geometry


【解决方案1】:

例子:

% some random 2D points coordinates
xy = rand(10,2);

% zero-centered
xy_ = bsxfun(@minus, xy, mean(xy));

% compute angles
theta = atan2(xy_(:,2), xy_(:,1));

% sort points clockwise
[~,ord] = sort(theta, 'descend');
xy = xy(ord,:);

% plot newly arranged points and labels
scatter(xy(:,1), xy(:,2), 'filled')
text(xy(:,1), xy(:,2), num2str((1:10)'), 'VerticalAlign','bottom')

% show radius lines
cx = zeros(2,size(xy,1));
cy = zeros(2,size(xy,1));
cx(1,:) = mean(xy(:,1)); cx(2,:) = xy(:,1);
cy(1,:) = mean(xy(:,2)); cy(2,:) = xy(:,2);
line(cx, cy)

请注意,atan2 在区间内逆时针返回角度:[-pi,pi]。这实际上也被cart2pol 函数使用(查看其源代码)。

【讨论】:

  • 复数也用它来计算phase angle,所以你可以写:theta = angle(complex(xy_(:,1),xy_(:,2)))
猜你喜欢
  • 2023-04-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-24
  • 1970-01-01
  • 2018-08-15
  • 2012-04-10
  • 1970-01-01
相关资源
最近更新 更多