1

I'm trying to reduce a thick line, in raster space, down to a thin line, preferably one pixel wide (or thick).

Does anybody know of an algorithm that can do this?

Imagine you draw with a marker on a piece of paper, scribbling here and there. Then you scan this paper into a grey-scale or black-and-white raster image. How can I produce another black-and-white image the same size but the lines you drew are very thin instead of thick?

Surely this must be a solved problem, right?

Magmatic
  • 111
  • 1

1 Answers1

3

the canny algorithm is a great start.

it takes a sobel input like so. enter image description here

Computes its gradient. Then depending on the gradient orientation it compares all neighbouring pixels aligned with it. If its a local maximum the pixel remains black otherwise it is set to white.

this article will probably explain it a lot better. https://towardsdatascience.com/canny-edge-detection-step-by-step-in-python-computer-vision-b49c3a2d8123

Ive tried to implement my own version using the algorithm provided however I'm struggling to port it to glsl as I think the interpolation might be causing an issue.

here is a working one in shatertoy though, just a beginner though so a bit complex for me.

https://www.shadertoy.com/view/wl2cW3

Paul Goux
  • 31
  • 3