(self, mask_or_polygons, height, width)
| 65 | """ |
| 66 | |
| 67 | def __init__(self, mask_or_polygons, height, width): |
| 68 | self._mask = self._polygons = self._has_holes = None |
| 69 | self.height = height |
| 70 | self.width = width |
| 71 | |
| 72 | m = mask_or_polygons |
| 73 | if isinstance(m, dict): |
| 74 | # RLEs |
| 75 | assert "counts" in m and "size" in m |
| 76 | if isinstance(m["counts"], list): # uncompressed RLEs |
| 77 | h, w = m["size"] |
| 78 | assert h == height and w == width |
| 79 | m = mask_util.frPyObjects(m, h, w) |
| 80 | self._mask = mask_util.decode(m)[:, :] |
| 81 | return |
| 82 | |
| 83 | if isinstance(m, list): # list[ndarray] |
| 84 | self._polygons = [np.asarray(x).reshape(-1) for x in m] |
| 85 | return |
| 86 | |
| 87 | if isinstance(m, np.ndarray): # assumed to be a binary mask |
| 88 | assert m.shape[1] != 2, m.shape |
| 89 | assert m.shape == ( |
| 90 | height, |
| 91 | width, |
| 92 | ), f"mask shape: {m.shape}, target dims: {height}, {width}" |
| 93 | self._mask = m.astype("uint8") |
| 94 | return |
| 95 | |
| 96 | raise ValueError("GenericMask cannot handle object {} of type '{}'".format(m, type(m))) |
| 97 | |
| 98 | @property |
| 99 | def mask(self): |
nothing calls this directly
no outgoing calls
no test coverage detected