0
$\begingroup$

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

For example, this one:

face

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.

$\endgroup$
0
$\begingroup$

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.

$\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.