What is the best approach to a localized threshold restriction function

I would like to take a snapshot of some text and make the text easier to read. The tricky part is that the original photo may have dark areas as well as areas of light, and I want the opengl function to improve the text in all of these areas.

Here is an example. At the top is the original image. At the bottom are processed images.

enter image description here

[edit] I added an example to what is happening. I can improve the text, but in areas where I don’t have text, this simple threshold creates spotty noise (bottom left, bottom). If I return the threshold, I will lose the text in the darker area (bottom right).

Currently, the processed image receives only text, not all text. The original algorithm I used was pretty simple: - a sample of 8 pixels around the current pixel (pixels about 4-5 distant seem to work best) - find out the lightest and darkest pixels from this sample - if the current pixel is closer to the darkest doorstep, then turn black and vice versa

It looked very good for the text around, but when it came to non-text text, it provided a very noisy image (even when I presented the initial rejection threshold)

I modified this algorithm to suggest that the text is always close to black. This provided the bottom image above, but once again I cannot pull out all the text functions that I want.

+4
source share
2 answers

thank you for your help.

In the end, I went for a fairly simple approach.
Selects a sample of the 8 closest pixels defining the maximum and minimum value. The local threshold (max - min) is defined. Then

smooth = dot(vec3(1.0/3.0), smoothstep(currentMin, currentMax, p11).rgb); smooth = (localthreshold < threshold) ? 1.0 : smooth; return vec4(smooth, smooth, smooth, 1); 

This does not show me the text beautifully in both the dark and light areas, which is ideal, but it perfectly clears the text in the lighter area.

Mike

+1
source

Before implementing this as a program, you may want to take the original photo and play with it in GIMP or another editor to see what you can do.

One way to deal with shadows is to run a high-pass filter before deploying it.

Here's how you do it in the image editor (manually, without the "highpass" filter):
1. Convert the image to shades of gray and save it to "layer_A"
2. Make a copy of "layer_A" in "Layer_B"
3. Invert colors to "Layer_B"
4. Gaussian blur "Layer_B" with a radius that is larger than the largest function you want to keep. (blur radius greater than a letter)
5. Merge "Layer_A" with "Layer_B", where result = "Layer_A" * 0.5 + "Layer_B" * 0.5 .
6. Increase the contrast in the resulting image.
7. Run the trophy.


Example

In opengl, this will be done in the same way (and without multiple layers)

This will not work well with strong / sharp shadows (obviously), but it will destroy the huge smooth shadows that result from a bent page, etc.

A technique (high-pass filter) is often used to create seamless textures, and you can find several such tutorials and additional information using google (high GIMP skip or high GIMP skip).

By the way, if you want to improve readability, you might want to keep it in shades of gray (while improving contrast) instead of converting it to black and white (1 bit). Sharp letter boundaries make reading difficult.
+2
source

Source: https://habr.com/ru/post/1388395/


All Articles