【发布时间】:2018-02-09 21:20:25
【问题描述】:
附加的图像有一条线,其中有一个中断。
我的代码使用导致r=32 和theta=2.3213 的霍夫变换找到该行。霍夫变换并不完美,角度(尤其是更复杂的图像)总是偏离一点点,在这种情况下,由于边缘检测,线是偏移的。我想跨行读取值以找到其中的中断。为了做到这一点,我需要能够对线条两侧的值进行采样,以找出线条的最大密度在哪里。
进一步的解释(如果你想要的话): 如果您仔细观察图像,您会看到线条与像素相交的区域几乎完全死角,导致值接近 1/white。其他区域有两个并排的像素,其值约为 0.5/灰度。我需要找到一种解决方案,考虑到线条的抗锯齿,并允许我提取其中的中断。
%Program Preparation
clear ; close all; clc %clearing command window
pkg load image %loading image analyzation suite
pkg load optim
%Import Image
I_original = imread("C:/Users/3015799/Desktop/I.jpg");
%Process Image to make analysis quicker and more effective
I = mat2gray(I_original); %convert to black and white
I = edge(I, 'sobel');
%Perform Hough Transform
angles = pi*[-10:189]/180;
hough = houghtf(I,"line",angles);
%Detect hot spots in hough transform
detect = hough>.5*max(hough(:));
%Shrink hotspots to geometric center, and index
detect = bwmorph(detect,'shrink',inf);
[ii, jj] = find(detect);
r = ii - (size(hough,1)-1)/2;
theta = angles(jj);
%Cull duplicates. i.e outside of 0-180 degrees
dup = theta<-1e-6 | theta>=pi-1e-6;
r(dup) = [];
theta(dup) = [];
%Compute line parameters (using Octave's implicit singleton expansion)
r = r(:)'
theta = theta(:)'
x = repmat([1;1133],1,length(r)); % 2xN matrix, N==length(r)
y = (r - x.*cos(theta))./sin(theta); % solve line equation for y
%The above goes wrong when theta==0, fix that:
horizontal = theta < 1e-6;
x(:,horizontal) = r(horizontal);
y(:,horizontal) = [1;:];
%Plot
figure
imshow(I)
hold on
plot(y,x,'r-','linewidth',2)
【问题讨论】:
-
停止删除和重复同样的问题。您上一个问题→stackoverflow.com/q/48708998
-
你知道这个突破有多大吗?我会尝试扩张和侵蚀以缩小差距,然后找到它的确切位置和进一步的过程
-
图片中是否只有两行(一行有断线),以便您可以找到这两行并从那里开始工作?
标签: matlab octave hough-transform