Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I was going to suggest cleaning up your lines like Ian said, but if you don't want to do that, you might also look into doing some variant of a hough transform.</p> <p><a href="http://en.wikipedia.org/wiki/Hough_transform" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Hough_transform</a></p> <p>You should be able to get the actual equation for the line from this, so you can make it as thin or as thick as you like. The only tricky part is figuring out where the line ends.</p> <p>Here's the code I wrote for a hough transform a few years ago, written in MATLAB. I'm not sure how well it works anymore, but it should give you a general idea. It will find all the lines (not segments) in an image</p> <pre><code>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 &lt; 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&lt;0)) = 0; accumMax = imregionalmax(accumThresh); imagesc(accumMax); %% calculate radius &amp; 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); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload