2
$\begingroup$

I have an image with gray-scale anti-aliased text produced by Chromium and need to convert this into pure binary black and white text. Applying a simple binary threshold pass over the image causes artifacts, either missing edges or weird protrusions and text being too bold depending on the chosen threshold.

Below an example of the input, the perfect outcome (as this is how the text would be rendered without AA) and the current outcome based on binary threshold (I think this is a 0.6 threshold). Sadly, it's not possible to instruct Chromium to render the text without anti-aliasing, so a conversion is the only option.

I was wondering if there was an established algorithm for this kind of problem or in what direction I would have to look to find something that could be adapted to work here. Any algorithm would need to be able to run in semi-realtime, no offline solutions.

text rendering example

$\endgroup$
1
  • $\begingroup$ You can try using randomization: a grayscale square which is x% gray becomes black with probability x/100 (or is it 1–x/100 ?). $\endgroup$ Jun 1, 2020 at 16:55

1 Answer 1

1
$\begingroup$

It is possible that the literature on image vectorization might be useful. That basically tries to reconstruct the strokes that produced the image. However, I think this is going to be challenging when the width of the strokes is narrower than two pixels or so, and it is possible that standard techniques might work poorly in that domain. I would recommend that you try increasing the font size or the resolution, and then try standard methods.

For your example image, I get somewhat more reasonable results by using a better threshold (0.8), but I think you'll do a lot better if you can increase the resolution.

If you know in advance what font and font size will be used, it might be feasible to render each possible character and capture an image of the anti-aliased rendered result for each possible character, in a few random locations, and then use simple pattern matching.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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