[英]Convert X,Y floating point coordinates to binary matrix and then perform a Hough line transform
您在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可以輕松實現類似的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.