INNER CODE UNIT · Python
mask_bounding_box
allenai/ai2thor · ai2thor/server.py:215
def mask_bounding_box(self, mask: np.ndarray) -> Optional[Tuple[int, int, int, int]]:
rows = np.any(mask, axis=1)
cols = np.any(mask, axis=0)
rw = np.where(rows)
if len(rw[0]) == 0:
return None
rmin, rmax = map(int, rw[0][[0, -1]])
cmin, cmax = map(int, np.where(cols)[0][[0, -1]])
return cmin, rmin, cmax, rmax
def __contains__(self, key: object) -> bool:
return key in self.instance_masks
def __eq__(self, other: object):
if isinstance(other, self.__class__):
return self.instance_masks == other.instance_masks