<p>the canny algorithm is a great start.</p>
<p>it takes a sobel input like so.
<a href="https://i.sstatic.net/HeYpF.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/HeYpF.jpg" alt="enter image description here" /></a></p>
<p>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.</p>
<p>this article will probably explain it a lot better.
<a href="https://towardsdatascience.com/canny-edge-detection-step-by-step-in-python-computer-vision-b49c3a2d8123" rel="nofollow noreferrer">https://towardsdatascience.com/canny-edge-detection-step-by-step-in-python-computer-vision-b49c3a2d8123</a></p>
<p>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.</p>
<p>here is a working one in shatertoy though, just a beginner though so a bit complex for me.</p>
<p><a href="https://www.shadertoy.com/view/wl2cW3" rel="nofollow noreferrer">https://www.shadertoy.com/view/wl2cW3</a></p>

CC BY-SA 4.0
2020-10-30T16:02:36.283Z
2020-10-30T16:25:59.520Z
2020-10-30T16:25:59.520Z
Paul Goux
<p>I'm trying to reduce a thick line, in raster space, down to a thin line, preferably one pixel wide (or thick).</p>
<p>Does anybody know of an algorithm that can do this?</p>
<p>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?</p>
<p>Surely this must be a solved problem, right?</p>

CC BY-SA 4.0
2020-10-30T14:12:43.797Z
It's called morphological erosion. Most graphic apps know how to do this out of the box.
joojaa
<2d-graphics><pixel-graphics><bitmap-graphics>
Algorithm for thinning a thick line
Magmatic
# Algorithm for thinning a thick line

(Asked by: username_0 on 2020-10-30)

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?

**Tags:** 2d-graphics, pixel-graphics, bitmap-graphics

> **Comments:**
> **username_1**: It's called morphological erosion. Most graphic apps know how to do this out of the box.  

---

## 1 answers

### Answer by username_2 on 2020-10-30. Score: 3

the canny algorithm is a great start.

it takes a sobel input like so.
[![enter image description here](https://i.sstatic.net/HeYpF.jpg)](https://i.sstatic.net/HeYpF.jpg)

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>


---

