image - 如何自动识别图像中的多行?

标签 image matlab image-processing

给定包含斜线的二值图像,我如何自动识别尽可能多的线?使用 Matlab 中的 bwtraceboundary 函数,我已经能够识别其中之一,手动提供识别线的起始坐标。

谁能指出一种循环 1 和 0 矩阵以自动识别尽可能多的方法?

这是一个示例图片:

enter image description here

% Read the image
I = imread('./synthetic.jpg');


figure(1)
BW = im2bw(I, 0.7);
imshow(BW2,[]);
c = 255; % X coordinate of a manually identified line
r = 490; % Y coordinate of a manually identified line
contour = bwtraceboundary(BW,[c r],'NE',8, 1000,'clockwise');
imshow(BW,[]);
hold on;
plot(contour(:,2),contour(:,1),'g','LineWidth',2); 

从上面的代码我们得到:

enter image description here

最佳答案

这是一个小示例,说明如何在 MATLAB 中对线条使用霍夫变换,并对图像进行一些先验降噪。

此代码不会检测所有行,您可能需要对其进行调整/稍微更改,这将需要了解正在发生的事情,这超出了 StackOverflow 的范围。也许有更多知识的人可以找到更好的方法:

I=rgb2gray(imread('/image/fTWHh.jpg'));

I = imgaussfilt(I,1);
I=I([90:370],:);
BW = edge(I,'canny');
[H,T,R] = hough(BW);
P  = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
lines = houghlines(BW,T,R,P,'FillGap',5,'MinLength',3);

figure, imshow(I), 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');

   % Determine the endpoints of the longest line segment
   len = norm(lines(k).point1 - lines(k).point2);
   if ( len > max_len)
      max_len = len;
      xy_long = xy;
   end
end

enter image description here

关于image - 如何自动识别图像中的多行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49492530/

相关文章:

arrays - Matlab中两个字符串元胞数组的区别

python - 有没有办法获得 numpy 中的最大值矩阵?

python - 图像处理: Import stills from video into python/matplotlib?

javascript - 清除浏览器缓存以加载重命名的文件

matlab - 用对角矩阵替换矩阵中的每个元素

image - 通过代码在ImageView中加载图片

Matlab strsplit 在非键盘字符处

animation - 如何从服务器上带有动画的照片生成视频?

css - 使用 CSS 调整 div 背景图像的大小

html - 如何实现背景图片