|
@@ -55,6 +55,18 @@ class Parts(object):
|
|
for i, p in enumerate(self._parts):
|
|
for i, p in enumerate(self._parts):
|
|
p.plot(color=cmap(i/len(self._parts)), **kwargs)
|
|
p.plot(color=cmap(i/len(self._parts)), **kwargs)
|
|
|
|
|
|
|
|
+ def reveal(self, im, ratio, *args, **kwargs):
|
|
|
|
+ res = np.zeros_like(im)
|
|
|
|
+
|
|
|
|
+ for part in self._parts:
|
|
|
|
+ if not part.is_visible: continue
|
|
|
|
+ x, y, crop = part.reveal(im, ratio=ratio, *args, **kwargs)
|
|
|
|
+ h, w, _ = crop.shape
|
|
|
|
+ res[y:y+h, x:x+w] = crop
|
|
|
|
+
|
|
|
|
+ return res
|
|
|
|
+
|
|
|
|
+
|
|
class BasePart(ABC):
|
|
class BasePart(ABC):
|
|
def __init__(self, annotation):
|
|
def __init__(self, annotation):
|
|
super(BasePart, self).__init__()
|
|
super(BasePart, self).__init__()
|
|
@@ -112,6 +124,15 @@ class LocationPart(BasePart):
|
|
return utils.crop(image, self.xy, w, h,
|
|
return utils.crop(image, self.xy, w, h,
|
|
padding_mode, is_location=True)
|
|
padding_mode, is_location=True)
|
|
|
|
|
|
|
|
+
|
|
|
|
+ def reveal(self, im, ratio, *args, **kwargs):
|
|
|
|
+ _h, _w, c = utils.dimensions(im)
|
|
|
|
+ w, h = int(_w * ratio), int(_h * ratio)
|
|
|
|
+ x,y = self.xy
|
|
|
|
+ x, y = max(x - w // 2, 0), max(y - h // 2, 0)
|
|
|
|
+ return x, y, im[y:y+h, x:x+w]
|
|
|
|
+
|
|
|
|
+
|
|
def plot(self, im, ax, ratio, fill=False, linestyle="--", **kwargs):
|
|
def plot(self, im, ax, ratio, fill=False, linestyle="--", **kwargs):
|
|
if not self.is_visible: return
|
|
if not self.is_visible: return
|
|
x, y = self.xy
|
|
x, y = self.xy
|
|
@@ -123,7 +144,6 @@ class LocationPart(BasePart):
|
|
**kwargs
|
|
**kwargs
|
|
))
|
|
))
|
|
|
|
|
|
-
|
|
|
|
class BBoxPart(BasePart):
|
|
class BBoxPart(BasePart):
|
|
|
|
|
|
def read_annotation(self, annotation):
|
|
def read_annotation(self, annotation):
|
|
@@ -135,6 +155,13 @@ class BBoxPart(BasePart):
|
|
return utils.crop(image, self.xy, self.w, self.h,
|
|
return utils.crop(image, self.xy, self.w, self.h,
|
|
padding_mode, is_location=False)
|
|
padding_mode, is_location=False)
|
|
|
|
|
|
|
|
+ def reveal(self, im, ratio, *args, **kwargs):
|
|
|
|
+ _h, _w, c = utils.dimensions(im)
|
|
|
|
+ x,y = self.xy
|
|
|
|
+ return x, y, im[y:y+self.h, x:x+self.w]
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
def plot(self, im, ax, ratio, fill=False, linestyle="--", **kwargs):
|
|
def plot(self, im, ax, ratio, fill=False, linestyle="--", **kwargs):
|
|
ax.add_patch(Rectangle(
|
|
ax.add_patch(Rectangle(
|
|
(self.x, self.y), self.w, self.h,
|
|
(self.x, self.y), self.w, self.h,
|