<p>A kernel can (probably) not help you, because they are very localized. However, you need to know, where a line is, and that may be out of the reach of a kernel (e.g. a 3x3 Pixel kernel would only be able to detect a line 3 pixels wide. Is that meeting your demands of being a line?)</p>

<p>Rather you need to define, when a line is a line with the information you have. For simplicity you could say "Having at least 5 pixels in either X or Y direction black next to each other, but not having any pixels black in any other direction makes a line". Then you can scan the image for those lines and store them in some data structure. </p>

<p>Now that you have your lines figured out, you need to define what to do with them, e.g. "Every line longer than 20 pixels needs to be dashed, every other line dotted". 
Also "A dashed line has a white pixel at every third and fourth pixel, except the first and last pixel may not be white" and "A dotted line has a white pixel at every other pixel, except the first and last pixel may not be white". Since you know the lines, you either know or can check the lines, and therefore you can edit them one by one to be dotted or dashed.</p>

<p>This is of course a pretty high level description, but you don't give much to go on with your question. Perhaps though, this suffices for you to get started.</p>

<p>The hard part of course is to identify lines. Try to think what makes a line for you (e.g. direction, thickness/width vs height), what edge cases you may have (a single pixel or square block of pixels) and then you can go about finding them in your image. Note that in a rasterized image, non horizontal and non vertical lines will have "strange" patterns of how they fill the image and you will have to decide how to treat those on your own. 
Also, make sure to not have any lines stored twice (or more) when scanning, because your dotting / dashing process could possibly lead to an unwanted outcome.</p>

CC BY-SA 4.0
2019-05-29T09:35:39.567Z
2019-05-29T09:35:39.567Z
Tare
<p>Let's say I had a binary image (i.e. only contains black and white pixels). </p>

<p>For example, this one:</p>

<p><a href="https://i.sstatic.net/Zbw7g.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Zbw7g.png" alt="face"></a></p>

<p>How would I make all the lines in this image dotted or dashed?</p>

<p>In other words, the eyes would be left alone, but everything else (including the circle on the nose) would become dotted or dashed.</p>

<p>I know that, for example, kernels can be used to blur, sharpen, etc - but I don't know if a kernel could do this. </p>

<image-processing><2d>
How to make the lines of a (binary) image dotted or dashed?
Joshua Mitchell
# How to make the lines of a (binary) image dotted or dashed?

(Asked by: username_0 on 2019-05-28)

Let's say I had a binary image (i.e. only contains black and white pixels).

For example, this one:

[![face](https://i.sstatic.net/Zbw7g.png)](https://i.sstatic.net/Zbw7g.png)

How would I make all the lines in this image dotted or dashed?

In other words, the eyes would be left alone, but everything else (including the circle on the nose) would become dotted or dashed.

I know that, for example, kernels can be used to blur, sharpen, etc - but I don't know if a kernel could do this.

**Tags:** image-processing, 2d


---

## 1 answers

### Answer by username_1 on 2019-05-29. Score: 0 | Accepted answer

A kernel can (probably) not help you, because they are very localized. However, you need to know, where a line is, and that may be out of the reach of a kernel (e.g. a 3x3 Pixel kernel would only be able to detect a line 3 pixels wide. Is that meeting your demands of being a line?)

Rather you need to define, when a line is a line with the information you have. For simplicity you could say "Having at least 5 pixels in either X or Y direction black next to each other, but not having any pixels black in any other direction makes a line". Then you can scan the image for those lines and store them in some data structure.

Now that you have your lines figured out, you need to define what to do with them, e.g. "Every line longer than 20 pixels needs to be dashed, every other line dotted".
Also "A dashed line has a white pixel at every third and fourth pixel, except the first and last pixel may not be white" and "A dotted line has a white pixel at every other pixel, except the first and last pixel may not be white". Since you know the lines, you either know or can check the lines, and therefore you can edit them one by one to be dotted or dashed.

This is of course a pretty high level description, but you don't give much to go on with your question. Perhaps though, this suffices for you to get started.

The hard part of course is to identify lines. Try to think what makes a line for you (e.g. direction, thickness/width vs height), what edge cases you may have (a single pixel or square block of pixels) and then you can go about finding them in your image. Note that in a rasterized image, non horizontal and non vertical lines will have "strange" patterns of how they fill the image and you will have to decide how to treat those on your own.
Also, make sure to not have any lines stored twice (or more) when scanning, because your dotting / dashing process could possibly lead to an unwanted outcome.


---

