1
$\begingroup$

I want to find areas in a binary image that correspond to long and thin curves. In the example below, structures thinner than 3 pixels but longer than 20 pixels are highlighted. Observe that the bottom-most line is split because it locally comes in contact with the Data Matrix code. The structures need not be straight, they can have a curvature.

I am quite familiar with the standard morphology operators, but they are usually isotropic and won't solve this. Is there any classical solution ? How would you solve that problem ?

enter image description here

enter image description here


Update:

I am thinking of this method:

  1. perform thinning (erasing layers of pixels one after the other but avoiding that the connexity be altered; at least as many layers as the maximum thickness); what remains is a skeleton;

  2. find the portions of the skeleton that are exactly one pixel wide; in other terms, only the pixels that have at most two neighbors. Keep the portions that have a sufficient length;

  3. finally select all pixels that are closer than the maximum thickness to a long portion.

The step 2 the key to selecting thin curves and avoiding junctions. The step 3 is the most difficult.

I am still hoping that a simpler, more integrated solution is possible.

$\endgroup$
5
  • $\begingroup$ Perhaps you can calculate for each point its distance to the nearest black pixel, and to the farthest black pixel it can go to by only moving on white points (or perhaps even only points whose nearest black pixel is at most X). The first value could help you detect the curves being thin, while the second one could help you avoid small spots. $\endgroup$ Commented May 29, 2023 at 16:27
  • $\begingroup$ @CommandMaster: indeed, there must be a solution that goes in that way. Finding the closest pixel is relatively easy and fast. As far as I know, the farthest is more costly (and it is not completely clear what farthest means in this context). $\endgroup$ Commented May 29, 2023 at 16:42
  • $\begingroup$ I'm also not sure what I meant by farthest. What about the size of the white component, perhaps limited/weighted based on the closest black pixel? $\endgroup$ Commented May 29, 2023 at 17:37
  • $\begingroup$ @CommandMaster: the size does not capture the shape. $\endgroup$ Commented May 29, 2023 at 18:31
  • $\begingroup$ @D.W.: I have added a case. And in the update I mention the topological skeleton. Line and edge detection are not relevant here. $\endgroup$ Commented May 29, 2023 at 21:57

0