Use x, y, top, bottom instead of x1, y1, x2, y2. Add aliases: left=x, top=y.

This commit is contained in:
Andrey Golovizin 2014-08-13 22:43:55 +02:00
parent 360ed844c2
commit 4ff37720d9
3 changed files with 45 additions and 29 deletions

View file

@ -31,10 +31,10 @@ def _is_nonblank(bitmap):
class Image(object):
"""Basic image class."""
def __init__(self, data, y1=0, x1=0):
def __init__(self, data, x=0, y=0):
self.data = data
self.y1 = y1
self.x1 = x1
self.x = x
self.y = y
def __getitem__(self, key):
"""Return an Image for the specified region."""
@ -59,12 +59,12 @@ class Image(object):
else:
yslice, xslice = key
ystart, yend = indices(yslice, self.height)
xstart, xend = indices(xslice, self.width)
ystart, yend = indices(yslice, self.height)
y1 = self.y1 + ystart
x1 = self.x1 + xstart
return Image(self.data[key], y1, x1)
x = self.x + xstart
y = self.y + ystart
return Image(self.data[key], x, y)
def _repr_png_(self):
buf = BytesIO()
@ -76,12 +76,20 @@ class Image(object):
return cls(imread(filename))
@property
def y2(self):
return self.y1 + self.height
def left(self):
return self.x
@property
def x2(self):
return self.x1 + self.width
def right(self):
return self.x + self.width
@property
def top(self):
return self.y
@property
def bottom(self):
return self.y + self.height
@property
def shape(self):
@ -97,7 +105,7 @@ class Image(object):
@cached_property
def T(self):
return type(self)(self.data.swapaxes(0, 1), y1=self.x1, x1=self.y1)
return type(self)(self.data.swapaxes(0, 1), x=self.y, y=self.x)
@cached_property
def bitmap(self):
@ -175,8 +183,8 @@ class Image(object):
if prev_line is None:
prev_line = line
else:
if line.y1 - prev_line.y2 < min_space:
prev_line = self[prev_line.y1:line.y2]
if line.top - prev_line.bottom < min_space:
prev_line = self[prev_line.top:line.bottom]
else:
yield prev_line
prev_line = line