gpt4 book ai didi

matlab - 广义 Hough R 表

转载 作者:太空宇宙 更新时间:2023-11-03 20:02:57 26 4
gpt4 key购买 nike

我正在尝试实现 this paper 中介绍的广义 Hough 变换在 MATLAB 中。我也试过使用 this document理解算法。我一直在研究如何计算梯度角以找到要在 R 表中使用的 Φ。

我试过运行这个 matlab implementation ,但轮廓函数试图访问负索引。缺少的功能如下。

距离.m

function [ d ] = distance( x1, y1, x2, y2 )
d = sqrt( (x2-x1)^2 + (y2-y1)^2 );
end

重心.m

function [ xo, yo ] = barycenter( img )
% gravitational center coordinates of a shape

[rows, cols] = size(img);
x = ones(rows, 1)*(1:cols);
y = (1:rows)'*ones(1,cols);
area = sum(sum(img));
xo = sum(sum(double(img) .* x)) / area;
yo = sum(sum(double(img) .* y)) / area;

end

模型Hough.m

function [H]=ModelHough(imgRGB)
% Generalized Hough Transform Modeling

% Image Binarization
imgBW = rgb2gray(imgRGB);
imgBI = imgBW < 255;

% Retrieving information about the contour: points and number (N)
N = contour(imgBI);

% Model initialization:
% row = beta value * 100
% column = number of the couple (alpha, distance)
% 3rd dimension: 1 = alpha, 2 = distance
H=zeros(round(100*2*pi),N,2);

% Compute of the barycenter coordinates
[ xo, yo ] = barycenter(imgBI);

% for each contour point
for i=1:N

% beta compute for ith contour point
b = beta(N, imgBI, i);

% research of the first column
k=1;
while H(b+1,k,2)~=0
k=k+1;
end

% compute of the alpha value
H(b+1, k, 1) = alpha(N, i, imgBI);

% compute of the distance value
H(b+1, k, 2) = distance( xo, yo, i, b );

end

最佳答案

使用合适的边缘检测器。您可以从 Sobel operator 开始.如维基文章中所述,梯度角为 atan(Gy/Gx)。

关于matlab - 广义 Hough R 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10176157/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com