使用Hough变换检测最佳行数

时间:2017-07-15 03:17:59

标签: matlab hough-transform

我希望我的例程能够准确地检测出图像中可用的许多行。

以下代码可以很好地检测图像中的线条,

clear_all();

image_name = 'hough1.png';
% no of  pixels discarded on border areas
pixel_count = 10;
% select largest 1 peaks
maxPeaks = 1;
% maximum allowed gap between lines
fillgap = 500;
% the minimum length of a line 
minline = 7;

% read image and convert to grayscale
input_image = gray_imread(image_name);
% discard border area
input_image = discard_image_area(input_image, pixel_count);
% create a binary image
binary_image = edge(input_image,'canny');    
% extract Hough Features
[H,T,R] = hough(binary_image); 

% identify peaks in Hough Data
threshPeaks = ceil(0.3*max(H(:)));
P  = houghpeaks(H, maxPeaks, 'threshold', threshPeaks);

% extract lines
hough_lines = houghlines(binary_image,T,R,P,'FillGap',fillgap,'MinLength',minline);   

draw_hough_lines('Detected Hough Lines', input_image, hough_lines);

如果我们使用以下图片作为输入

enter image description here

输出变为,

enter image description here

此例程存在一个很大的问题,即它始终会检测到maxPeaks行数。

假设我们有一张图片(如上所示)我们不知道有多少行。然后,我们如何检测所有行?

例如,如果我们设置maxPeaks = 5,例程将检测以下图像中的2行。

输入

enter image description here

输出

{{3}}

如何解决此问题?

0 个答案:

没有答案