Ask Your Question

Fitting lines on small pixel clusters

asked 2015-12-09 13:15:34 -0500

batlike gravatar image

Is there an existing function in OpenCV that allows line-fitting across the major axis of bright pixel clusters? (see below) I want to automate the detection of short filaments in a series of images.

I have tried fitting the minimum bounding box around these features, but with little accuracy. I also found skeletonizing (using the Zhang-Suen method) these features quite difficult, as it seems to connect what used to be distinct pixel clusters.

image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-12-12 21:47:09 -0500

Tetragramm gravatar image

Am I correct that what you want is a few dozen line segments connecting the nearby dots?

Assuming I am correct, you should try the Line Segment detector and the Probabilistic Hough Transform. It's possible that the skeletonization method could help, if what it's connecting is the parts of the line. If not, you can try connecting them yourself by doing a Morphology Closing operation with an appropriately sized and shaped kernel.

A suggested set of functions is this:

  • Threshold the image to binary values (OTSU should pick a good threshold on this image)
  • Morphology Close (You'll need to experiment to find a kernel that works reasonably well, possible a circle that's 5x5?)
  • OR Run the skeletonizing method here, if it's working.
  • Line Segment Detector or Probabilistic Hough Transform outputs a set of line segments.

Of course, you'll want to play around with the settings to try and get a good set of line candidates. I would start by forgoing the middle steps and seeing if the LSD or Hough can give you good results. The LSD seems to produce far more than the Probablistic Hough, but of course, that can mean more false hits.

edit flag offensive delete link more


No, the difficult lies in recognizing that what appears to be dots are in fact "segments" a few pixels in length. I want to fit lines across each tiny pixel cluster

batlike gravatar imagebatlike ( 2015-12-14 00:37:46 -0500 )edit

So the lower right where you have 3 dots in a row is actually three lines?

Hmm, that's actually easier. Ok.

  • Binarize the image
  • Connected Components
  • For each component, go to the original image and calculate the centroid
    • X_centroid = Sum(Pixel_intensity*X_loc)/Sum(Pixel_intensity), you can guess the Y formula
  • Calculate the Covariance Matrix for the X and Y as per these slides.
  • The long axis is, as best we can tell, the direction of the segment, and the length along that axis from edge to edge is your length.

Does that work?

Tetragramm gravatar imageTetragramm ( 2015-12-14 18:11:56 -0500 )edit
Login/Signup to Answer

Question Tools



Asked: 2015-12-09 13:12:30 -0500

Seen: 276 times

Last updated: Dec 12 '15