|
@@ -7,7 +7,7 @@ class Parts(object):
|
|
|
super(Parts, self).__init__()
|
|
|
annots = utils.rescale_parts(image, part_annotations, rescale_size)
|
|
|
|
|
|
- self._parts = [ImagePart(image, a) for a in annots]
|
|
|
+ self._parts = [ImagePart(a) for a in annots]
|
|
|
self.rescale_size = rescale_size
|
|
|
|
|
|
def __getitem__(self, i):
|
|
@@ -29,12 +29,14 @@ class Parts(object):
|
|
|
for p in self._parts:
|
|
|
p.is_visible = p._id in idxs
|
|
|
|
|
|
+
|
|
|
def invert_selection(self):
|
|
|
self.select(np.logical_not(self.selected))
|
|
|
|
|
|
- def set_visibility(self, idxs, value):
|
|
|
- for p in self._parts[idxs]:
|
|
|
- p.is_visible = value
|
|
|
+ def offset(self, dx, dy):
|
|
|
+ for p in self._parts:
|
|
|
+ p.x += dx
|
|
|
+ p.y += dy
|
|
|
|
|
|
def visible_locs(self):
|
|
|
vis = [(p._id, p.xy) for p in self._parts if p.is_visible]
|
|
@@ -45,9 +47,8 @@ class Parts(object):
|
|
|
return np.array([p.crop(*args, **kwargs) for p in self._parts])
|
|
|
|
|
|
class ImagePart(object):
|
|
|
- def __init__(self, image, annotation):
|
|
|
+ def __init__(self, annotation):
|
|
|
super(ImagePart, self).__init__()
|
|
|
- self.image = image
|
|
|
|
|
|
if len(annotation) == 4:
|
|
|
# here x,y are the center of the part
|
|
@@ -62,13 +63,13 @@ class ImagePart(object):
|
|
|
else:
|
|
|
raise ValueError("Unknown annotation format: {}".format(annotation))
|
|
|
|
|
|
- def crop(self, ratio=None, padding_mode="edge"):
|
|
|
+ def crop(self, image, ratio=None, padding_mode="edge"):
|
|
|
if not self.is_visible:
|
|
|
- h, w, c = utils.dimensions(self.image)
|
|
|
+ h, w, c = utils.dimensions(image)
|
|
|
crop_h, crop_w = int(h * ratio), int(w * ratio)
|
|
|
return np.zeros((crop_h, crop_w, c), dtype=np.uint8)
|
|
|
else:
|
|
|
- return utils.crop(self.image, self.xy, ratio, padding_mode)
|
|
|
+ return utils.crop(image, self.xy, ratio, padding_mode)
|
|
|
|
|
|
@property
|
|
|
def is_visible(self):
|