我打算像伊恩所说的那样清理你的线条,但如果你不想这样做,你也可以考虑做一些霍夫变换的变体。
http://en.wikipedia.org/wiki/Hough_transform
您应该能够从中获得该线的实际方程式,因此您可以根据需要使其变细或变粗。唯一棘手的部分是弄清楚线路的结束位置。
这是我几年前用 MATLAB 编写的霍夫变换代码。我不确定它的效果如何,但它应该给你一个大致的想法。它将找到图像中的所有线(不是线段)
im = imread('cube.tif');
[bin1,bin2,bin3] = canny(im);
%% define constants
binary = bin1;
distStep = 10; % in pixels
angStep = 6; % in degrees
thresh = 50;
%% vote
maxDist = sqrt((size(binary,1))^2+(size(binary,2))^2);
angLoop = 0:angStep*pi/180:pi;
origin = size(binary)/2;
accum = zeros(ceil(maxDist/distStep)+1,ceil(360/angStep)+1);
for y=1:size(binary,2)
for x=1:size(binary,1)
if binary(x,y)
for t = angLoop
dx = x-origin(1);
dy = y-origin(2);
r = x*cos(t)+y*sin(t);
if r < 0
r = -r;
t = t + pi;
end
ri = round(r/distStep)+1;
ti = round(t*180/pi/angStep)+1;
accum(ri,ti) = accum(ri,ti)+1;
end
end
end
end
imagesc(accum);
%% find local maxima in accumulator
accumThresh = accum - thresh;
accumThresh(logical(accumThresh<0)) = 0;
accumMax = imregionalmax(accumThresh);
imagesc(accumMax);
%% calculate radius & angle of lines
dist = [];
ang = [];
for t=1:size(accumMax,2)
for r=1:size(accumMax,1)
if accumMax(r,t)
ang = [ang;(t-1)*angStep/180*pi];
dist = [dist;(r-1)*distStep];
end
end
end
scatter(ang,dist);