MATLAB中的Hough变换
是否有人知道如何使用Hough变换检测二值图像中最强的线条:MATLAB中的Hough变换,matlab,image-processing,hough-transform,Matlab,Image Processing,Hough Transform,是否有人知道如何使用Hough变换检测二值图像中最强的线条: A = zeros(7,7); A([6 10 18 24 36 38 41]) = 1; 使用(ρ;θ)格式,θ从-45°到90°以45°为步长。以及如何在MATLAB中显示累加器阵列 有什么帮助或提示吗 谢谢大家! 每个像素(x,y)映射到一组穿过它的线(ρ,θ) 构建一个索引为(ρθ)的累加器矩阵 对于打开的每个点(x,y),生成对应于(x,y)的所有量化(rho,θ)值,并增加累加器中的对应点 找到最强的线对应于在累加器中找
A = zeros(7,7);
A([6 10 18 24 36 38 41]) = 1;
使用(ρ;θ)格式,θ从-45°到90°以45°为步长。以及如何在MATLAB中显示累加器阵列
有什么帮助或提示吗
谢谢大家! 每个像素(x,y)映射到一组穿过它的线(ρ,θ)
accum = zeros(360,100);
[y,x] = find(binaryImage);
y = y - size(binaryImage,1)/2; % use locations offset from the center of the image
x = x - size(binaryImage,2)/2;
npts = length(x);
for i = 1:npts
for theta = 1:360 % all possible orientations
rho = %% use trigonometry to find minimum distance between origin and theta oriented line passing through x,y here
q_rho = %% quantize rho so that it fits neatly into the accumulator %%
accum(theta,rho) = accum(theta,rho) + 1;
end
end
如果您有权访问图像处理工具箱,则可以使用以下函数:
谢谢你!!!你知道如何显示累加器阵列吗?我是否使用
imshow(accum)代码>?您知道如何显示图像中最强的线吗?最强的线是与累加器中证据最多的点对应的线。[best_th,best_rho]=ind2sub(size(acum),max(acum(:));您不应该检查所有360度。您只需要180度。
%# your binary image
BW = false(7,7);
BW([6 10 18 24 36 38 41]) = true;
%# hough transform, detect peaks, then get lines segments
[H T R] = hough(BW);
P = houghpeaks(H, 4);
lines = houghlines(BW, T, R, P, 'MinLength',2);
%# show accumulator matrix and peaks
imshow(H./max(H(:)), [], 'XData',T, 'YData',R), hold on
plot(T(P(:,2)), R(P(:,1)), 'gs', 'LineWidth',2);
xlabel('\theta'), ylabel('\rho')
axis on, axis normal
colormap(hot), colorbar
%# overlay detected lines over image
figure, imshow(BW), hold on
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1), xy(:,2), 'g.-', 'LineWidth',2);
end
hold off