1
$\begingroup$

Here is the test image:

testcase

You might recognize this as a Boggle board. I want to translate the image into a 4x4 array of letters. Not quite sure how to deal with rotated letters and ambiguous letters yet ('M' vs. 'W') but one problem at a time. Here's what I've done.

testcaseEASY = my_img.jpg
bin = ChanVeseBinarize[testcaseEASY]
imgs = Flatten[ImagePartition[bin, ImageDimensions[bin][[1]]/4]];

Dividing the screen up into a 4x4 array manually is pretty dumb, it seems to work. So now I have a list of the letters, and they look pretty decent.

O_unclean

I try to make them look a bit better:

cleaner[img_] := ColorNegate[RemoveBackground[DeleteSmallComponents[img, 1000]]]
imgsCLEANED = Map[cleaner,imgs]

Now I get this:

O_clean

Why the ColorNegate? Not sure, it just gave the best results. Finally, I do

letters = {}; 
Do[AppendTo[letters, TextRecognize[imgsCLEANED[[i]], RecognitionPrior -> "Character"]], {i, 1, 16}];
MatrixForm[ArrayReshape[letters, {4, 4}]]

The output is

l   A   A   W
H   S   A   R
Y   T   H   B
    C   L   u

So it's pretty close but I'm obviously not quite there yet. Any ideas on how to improve this? I'm using Mathematica 12.0 if that's relevant.

$\endgroup$

1 Answer 1

2
$\begingroup$

I got a decent result like this, but I had to replace "1" with "I" as TextRecognize has some difficulty with this font.

img = Import["https://i.sstatic.net/0QkgN.jpg"];
adj = ImageResize[img, 256];
parts = ImagePartition[adj, 64];
extracted = Map[ColorNegate[DeleteBorderComponents[ColorNegate@Binarize[#]]] &, parts, {2}];
ImageAssemble[extracted]
Map[ToUpperCase[
    First[Characters[
       TextRecognize[#, RecognitionPrior -> "Character"]]] /. "1" -> "I"] &, extracted, {2}]//Grid

boggle letters

O   A   A   V
H   S   A   R
Y   T   H   B
I   C   L   U
$\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.