Add Image.bbox(), Image.overlaps() and Image.combine().
This commit is contained in:
parent
3407bac38b
commit
5f7e6abcb9
1 changed files with 28 additions and 0 deletions
|
|
@ -167,6 +167,34 @@ class Image(object):
|
||||||
data = np.ma.masked_array(self.data, mask3, fill_value=255).filled()
|
data = np.ma.masked_array(self.data, mask3, fill_value=255).filled()
|
||||||
return Image(data, self.x, self.y)
|
return Image(data, self.x, self.y)
|
||||||
|
|
||||||
|
def bbox(self, other):
|
||||||
|
return (
|
||||||
|
min(self.left, other.left),
|
||||||
|
min(self.top, other.top),
|
||||||
|
max(self.right, other.right),
|
||||||
|
max(self.bottom, other.bottom),
|
||||||
|
)
|
||||||
|
|
||||||
|
def overlaps(self, other):
|
||||||
|
return not (self.right < other.left or other.left < self.right)
|
||||||
|
|
||||||
|
def combine(self, other):
|
||||||
|
if self.overlaps(other):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
left, top, right, bottom = self.bbox(other)
|
||||||
|
width = right - left
|
||||||
|
height = bottom - top
|
||||||
|
selftop = self.top - top
|
||||||
|
othertop = other.top - top
|
||||||
|
selfleft = self.left - left
|
||||||
|
otherleft = other.left - left
|
||||||
|
data = np.zeros((height, width, self.shape[2]), self.data.dtype)
|
||||||
|
data.fill(255)
|
||||||
|
data[selftop:selftop + self.height, selfleft:selfleft + self.width] = self.data
|
||||||
|
data[othertop:othertop + other.height, otherleft:otherleft + other.width] = other.data
|
||||||
|
return Image(data, left, top)
|
||||||
|
|
||||||
def _iter_lines(self, min_space):
|
def _iter_lines(self, min_space):
|
||||||
def iter_lines():
|
def iter_lines():
|
||||||
line_start = None
|
line_start = None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue