基于Hough变换的Matlab图像投影

时间:2014-04-08 11:21:14

标签: matlab hough-transform

我使用Matlab输入一个4x4网格的彩色方块,并输出一个颜色列表。我的程序适用于正方形,但我无法将其调整为旋转图像:

Rotated 1

Rotated 2

和投影图像:

Projected


我被建议使用 Hough变换,我可以使用它来使用以下代码访问图像中的行:

[H, theta, rho] = hough(image,'RhoResolution',0.1,'Theta',-90:0.5:89.5);    
peaks = houghpeaks(H,4);    
lines = houghlines(dilated, theta, rho, peaks, 'MinLength', 40)

figure, imshow(dilated), hold on;

max_len = 0;

for k = 1:length(lines)

   xy = [lines(k).point1; lines(k).point2];

   plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');

   % Plot beginnings and ends of lines
   plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');    
   plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');

   angle = atand(((xy(1,1)-xy(2,1))/(xy(1,2)-xy(2,2))));  

end

所以现在我想使用这些线条,并相应地拉直我的图像,使图像边缘与这些线条平行。但是,我不知道该怎么做。我很感激如何做到这一点的建议。感谢。

1 个答案:

答案 0 :(得分:0)

dilated来自哪里?如何计算黑白图像及其边缘?精明?索贝尔?蒲瑞维特?

也许你正在使用衍生滤镜,它取决于边缘的角度,因此你可能无法获得良好的边缘图像,这会使Houghtransformation失败,因为它只能在良好的图像上工作包含明确定义的边缘,边缘可能封闭(或至少有小间隙)。

作为提示:只需通过imshow(dilated)输出您的黑白图像并查看它,看看边缘的定义有多好,特别是与没有旋转的图像边缘相比。