Recognize White Text with Black Shadow on White Background
Recognize White Text with Black Shadow on White Background
I'm trying to extract text from images. The text is always white, but the background can vary and also be white, resulting in the following output when only considering pixel color:

As you can see, the white background will "eat up" the letter it surrounds, as is particularly the case with the first "G" and the second to last "go".
Now my idea to tackle this problem was to take the black shadow of the text into consideration, which after all also seems to be the reason why the "G" is still readable to us humans. However, I don't know how to go about this, and I also can't find any ressources online.
This is what I've tried so far: Since the shadow is to the lower right, I check if there are black pixels within the three pixels down or to the right. This gives us the following result:

It's already better than the first output, but there are still many false positives, that seem to be quite obvious to the human eye:
Some pixels under the "G" remain white (highlighted in red in the image below) because there are black pixels to their right. The algorithm treats the black pixels as their shadow, even though they are actually the shadow of the "G".

How can I improve my algorithm so it knows the shadow belongs to the pixels above (the "G") and not to the pixels on the left (the red pixels)?
My first thought about it is that the shadow of the "G" seems more horizontal than vertical, so it's likely it's the shadow of something above and not to the side.
Any thoughts?
P.S.: I'm not asking for a ready-made solution in a specific language, but for a general approach to the problem. As long as I'm directed to the right direction, I'll be able to implement the approach into the language myself. :)
EDIT
Here is the original image:

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
can you show the original image? Is there a general difference between the shadow of letters and the rest of the background? Human cognition is very good in filling in unrepresented parts of geometries, you'll probably not find any easy solution or maybe even no solution at all. If you know all kind of objects/fonts that could appear, you could try quite simple object detection techniques like chamfer matching to get a "there could be a 'G'" answers. Especially if you already found some other letters and a stroke width.
– Micka
49 mins ago