Skip to content

Commit

Permalink
rework to use affine_transform and add test image
Browse files Browse the repository at this point in the history
  • Loading branch information
danvk committed Jan 12, 2015
1 parent 056e9a8 commit c78354b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions ocrolib/psegutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,14 @@ def extract(image,y0,x0,y1,x1,mode='nearest',cval=0):
try:
r = interpolation.shift(sub,(y-y0,x-x0),mode=mode,cval=cval,order=0)
if cw > w or ch > h:
n = ones((ch, cw), dtype=r.dtype)
pady0, padx0 = max(-y0, 0), max(-x0, 0)
rh, rw = r.shape
n[pady0:rh+pady0,padx0:rw+padx0] = r
r = n
r = interpolation.affine_transform(r, eye(2), offset=(pady0, padx0), cval=1, output_shape=(ch, cw))
return r

except RuntimeError:
# workaround for platform differences between 32bit and 64bit
# workaround for platform differences between 32bit and 64bit
# scipy.ndimage
dtype = sub.dtype
dtype = sub.dtype
sub = array(sub,dtype='float64')
sub = interpolation.shift(sub,(y-y0,x-x0),mode=mode,cval=cval,order=0)
sub = array(sub,dtype=dtype)
Expand Down
Binary file added tests/text-near-edge.bin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c78354b

Please sign in to comment.