【问题标题】:Convert X,Y floating point coordinates to binary matrix and then perform a Hough line transform将 X,Y 浮点坐标转换为二进制矩阵,然后执行霍夫线变换
【发布时间】:2018-02-01 09:12:31
【问题描述】:

是否可以计算 xy 浮点数组的霍夫线变换,类似于 python 中的 matlab 代码?

BW=full(sparse(x,y,true));

数据看起来像

【问题讨论】:

  • 我曾尝试使用 ransac 来解决这个问题,但由于与 link987654322link987654322link987654322 类似的一些数据中的噪声簇,它的效果不够好
  • 您的问题是如何在 python 中将 X,Y 点转换为二进制矩阵?或者如何进行霍夫变换?
  • 如何在 python 中将 X,Y 点转换为二进制矩阵,但点是浮点而不是整数。我会让问题更清楚。

标签: python matlab numpy image-processing hough-transform


【解决方案1】:

您在 MATLAB 中的示例仅适用于整数 (x,y) 坐标。

例如

% I use a 10x10 identity matrix to simulate a line of points
% And scale the resulting x, y coordinates to be floating point 
[X, Y] = find(eye(10));
X = X * 0.1;
Y = Y * 0.1;
A = full(sparse(X, Y, true));

抛出错误

使用稀疏时出错。矩阵的索引必须是整数。

如果您想将浮点坐标转换为二进制矩阵,我知道的唯一方法是抽取您的空间。

% Precision of the decimated grid
scale = .01;

% Scale the X, Y values to be integers greater than 1
row_indices = round((Y - min(Y))/scale) + 1;    
col_indices = round((X - min(X))/scale) + 1;

% row values also need to be flipped 
% i.e. y = 0 should be the maximum row in the matrix to maintain the same orientation of the coordinate system
row_indices = max(row_indices) -  row_indices + 1;

% Create matrix using your method
A = full(sparse(row_indices, col_indices, true));

% Each row and column in A corresponds to the value in these range vectors
xrange = min(X):scale:max(X);
yrange = max(Y):-scale:min(Y);

测试这些转换是否产生了预期的结果。我绘制了矩阵。

figure; 
subplot(1,2,1); imagesc(A);
xticks(1:20:100); xticklabels(xrange(1:20:end));
yticks(1:20:100); yticklabels(yrange(1:20:end));
subplot(1,2,2); plot(X, Y, 'ko');

而且看起来不错。

使用 numpy 应该很容易实现类似的方法。

【讨论】:

  • 是的,这就是我的想法,但问题是我的点之间的差异非常小,所以最小的差异约为 0.0000001,最大的差异约为 1。所以通过抽取数组它结果是拥有一个包含很少元素的巨大数组,并且由于数组的大小,处理它需要很长时间,这在我的情况下是不可能的。您认为还有其他方法可以解决这个问题吗?
  • 如果您的点数很少,您可以按照this wikipedia example 中的说明实现自己的霍夫变换。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-11-24
  • 1970-01-01
  • 1970-01-01
  • 2022-01-23
  • 1970-01-01
  • 1970-01-01
  • 2018-10-17
相关资源
最近更新 更多