1
$\begingroup$

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?

$\endgroup$
1
  • $\begingroup$ It's called morphological erosion. Most graphic apps know how to do this out of the box. $\endgroup$
    – joojaa
    Oct 30 '20 at 14:12
3
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.