Improve the quality of the letters in a image
<p>I'm working with images that have text. The problem is that these images are receipts, and after a lot of transformations, the text lost quality. 
I'm using python and opencv.
I was trying with a lot of combinations of morphological transformations from the doc <a href="http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_morphological_ops/py_morphological_ops.html" rel="nofollow">Morphological Transformations</a>, but I don't get satisfactory results. </p>

<p>I'm doing this right now (I'll comment what I've tried, and just let uncommented what I'm using):</p>

<pre><code>kernel = np.ones((2, 2), np.uint8)
# opening = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel)
# closing = cv2.morphologyEx(img, cv2.MORPH_CLOSE, kernel)
# dilation = cv2.dilate(opening, kernel, iterations=1)
# kernel = np.ones((3, 3), np.uint8)
erosion = cv2.erode(img, kernel, iterations=1)
# gradient = cv2.morphologyEx(img, cv2.MORPH_GRADIENT, kernel)
#
img = erosion.copy()
</code></pre>

<p>With this, from this original image:</p>

<p><a href="http://i.stack.imgur.com/fKJkH.png" rel="nofollow"><img src="http://i.stack.imgur.com/fKJkH.png" alt="enter image description here"></a></p>

<p>I get this:</p>

<p><a href="http://i.stack.imgur.com/Hvmvk.png" rel="nofollow"><img src="http://i.stack.imgur.com/Hvmvk.png" alt="enter image description here"></a></p>

<p>It's a little bit better, as you can see. But it still too bad. The OCR (tesseract) doesn't recognize the characters here very well. I've trained, but as you can note, every "e" is different, and so on. </p>

<p>I get good results, but I think, if I resolve this problem, they would be even better. </p>

<p>Maybe I can do another thing, or use a better combination of the morphological transformations. If there is another tool (PIL, imagemagick, etc..) that I could use, I can use it. </p>

<p>Here's the whole image, so you can see how it looks:</p>

<p><a href="http://i.stack.imgur.com/AorH6.png" rel="nofollow"><img src="http://i.stack.imgur.com/AorH6.png" alt="enter image description here"></a></p>

<p>As I said, it's not so bad, but a little be more "optimization" of the letters would be perfect. </p>

<p>In my experience erode impairs OCR quality. If you have grayscale image (not binary) you can use better binarization algorithm. I use SAUVOLA algorithm for binarization.  If you have only binary image the best thing you can do is removing the noise (remove all small dots). </p>

python image opencv letters