( These notes are based on: https://github.com/tmbdev/ocropy/blob/758e023f808d88e5995af54034c155621eb087b2/OLD/normalization-api.ipynb from 2014 )
The line normalization is performed before the actual text recognition and before the actual training. Therefore, the same line normalization should be used in the recognition as it is used in the training. The line normalization tries to dewarp the line image and normalize its height. Previously different methods were explored, but nowadays the default method should work well. This notes will give some background information.
In [1]:
%pylab inline
from pylab import imshow
from scipy.ndimage import filters,interpolation
import ocrolib
from ocrolib import lineest
#Configure the size of the inline figures
figsize(8,8)
In [2]:
image = 1-ocrolib.read_image_gray("../tests/010030.bin.png")
image = interpolation.affine_transform(image,array([[0.5,0.015],[-0.015,0.5]]),offset=(-30,0),output_shape=(200,1400),order=0)
imshow(image,cmap=cm.gray)
print image.shape
In [3]:
#reload(lineest)
mv = ocrolib.lineest.CenterNormalizer()
mv.measure(image)
print mv.r
plot(mv.center)
plot(mv.center+mv.r)
plot(mv.center-mv.r)
imshow(image,cmap=cm.gray)
Out[3]:
In [4]:
dewarped = mv.dewarp(image)
print dewarped.shape
imshow(dewarped,cmap=cm.gray)
Out[4]:
In [5]:
imshow(dewarped[:,:320],cmap=cm.gray,interpolation='nearest')
Out[5]:
In [6]:
normalized = mv.normalize(image,order=0)
print normalized.shape
imshow(normalized,cmap=cm.gray)
Out[6]:
In [ ]: