0

Image with text to be recognized

How is it possible to process this image so that text can be recognized. I have tried to convert the image in several ways that can be summarized like this:

converted1=ColorConvert[![\[][1]][1],"Grayscale"]
converted2=TextRecognize[converted1]

But I only get gibberish. These letters are "filled" so they have to be transformed to something that Mathematica can do. The question is how.I would prefer to do it with Mathematica, but I only see posts recommending other tools. Any pointers would be greatly appreciated.

JSP
  • 145
  • 7
  • Did you preprocess it? – pjpj Jan 03 '18 at 08:31
  • Thank you. Converting the image to gray (and to other spaces) is the only preprocessing I could think of. What do you have in mind? – JSP Jan 03 '18 at 08:59
  • Do you just want to detect the position of each letter or do you also want to know what each of the letter implies? Also will the format of the image and letters in it always the same? – janu777 Jan 03 '18 at 09:47
  • The goal is to detect the letters (kind of OCR) and put the letters in a table (grid, array, matrix). – JSP Jan 03 '18 at 09:55
  • Will the format of the image and the format(shape and size) of the letters be the same? – janu777 Jan 03 '18 at 10:42
  • Maybe you can try some machine learning libs instead of Mathematica. – pjpj Jan 03 '18 at 13:09
  • @janu777, thank you. Yes, the format is always exactly the same. – JSP Jan 03 '18 at 13:11
  • @Wending Peng, I do not know much about Machine Learning in this context (only with numbers). – JSP Jan 03 '18 at 13:18
  • It is a typical image classification problem. – pjpj Jan 03 '18 at 14:25

1 Answers1

1

You are trying to do character recognition where the template or font of each character will not change.

To solve this you can simply use template matching algorithm.

1) Save all your template images(Characters to be recognized) and their corresponding key as to what each template is representing. (EX: If Template Image has the character 'A', it's key should be given as 'A')

2) Mathematica has image correlate function. check here. This function takes image and kernel as inputs. So pass every character template to this function. If there is high correlation value, then that particular character is present in the image.

3)Now use the key value of the template to recognize which character it is.

4) Finally based on where local maxima or local minima (depending on your template matching algorithm)is present in the image, you will get the location of the character with which you can save all the characters into a grid in a preferred order.

Check this to learn more about template matching.

Hope this works!

janu777
  • 1,940
  • 11
  • 26
  • Wow, thank you very much. I have much to learn. So I will start by deciphering (!!) what you write, most of it is completely new to me. I am not sure that I will succeed but I will certainly try hard.After I read the comments, I went on to read about Classification and saw the examples but Wolfram refers to a MNIST database that I do not know how to download. Will be back! – JSP Jan 04 '18 at 19:52
  • OK, I have tried with some success. I started with 'letters = {imageA->A,imageB->B,imageC->C}' 'Classify[letters,imageX]' and got X. Correct! Is this the way to start? I am sorry but I cannot write code here, only in new posts. – JSP Jan 04 '18 at 20:26
  • Great! This is a good way to start. But now as given in the question.You wont have cropped out images. Your image can contain several letters. So you must find the location of each letter and what it represents. – janu777 Jan 05 '18 at 04:59
  • Also MNIST dataset is good to go. Using MNIST dataset you can train a deep learning model which will be able to get good predictions. But since you have stated that the format and size of each letter won't change in anyway. I wanted you to go for image correlate function. – janu777 Jan 05 '18 at 05:06
  • The problem is that I cannot find how to download the MNIST. I found a way to work with it in the cloud but I would like to have it on my desktop. But How? – JSP Jan 05 '18 at 23:02
  • "size of each letter will not change" yes it is true, you can see that in the picture and I had success as stated above. Next step Correlation; I read the article you pointed to and tried the functions in the Manual (the photograph and the eyes seemed most appropriate). I must design a function that loops though all the squares above; you speak of maxima and minima, is that it? – I do not understand that part. Thank you for your patience, Happy New Year! – JSP Jan 05 '18 at 23:09
  • https://docs.opencv.org/2.4/doc/tutorials/imgproc/histograms/template_matching/template_matching.html – janu777 Jan 08 '18 at 09:24
  • Go through the above article. It explains how to find local maxima/minima and the whole template matching procedure. – janu777 Jan 08 '18 at 09:25
  • In OpenCV, the function is straightforward. But I think you will have to implement your our function in Mathematica. – janu777 Jan 08 '18 at 09:26