|
@@ -10,6 +10,9 @@ class BasePartCollection(ABC):
|
|
def __getitem__(self, i):
|
|
def __getitem__(self, i):
|
|
return self._parts[i]
|
|
return self._parts[i]
|
|
|
|
|
|
|
|
+ def __len__(self, i):
|
|
|
|
+ return len(self._parts)
|
|
|
|
+
|
|
def __repr__(self):
|
|
def __repr__(self):
|
|
return repr(np.stack([p.as_annotation for p in self._parts]))
|
|
return repr(np.stack([p.as_annotation for p in self._parts]))
|
|
|
|
|
|
@@ -47,7 +50,9 @@ class BasePartCollection(ABC):
|
|
return np.array(idxs), np.array(xy).T
|
|
return np.array(idxs), np.array(xy).T
|
|
|
|
|
|
def visible_crops(self, *args, **kwargs):
|
|
def visible_crops(self, *args, **kwargs):
|
|
- return np.array([p.crop(*args, **kwargs) for p in self._parts])
|
|
|
|
|
|
+ crops = [p.crop(*args, **kwargs) for p in self._parts]
|
|
|
|
+ return crops
|
|
|
|
+ # return np.array(crops)
|
|
|
|
|
|
def plot(self, cmap=plt.cm.jet, **kwargs):
|
|
def plot(self, cmap=plt.cm.jet, **kwargs):
|
|
for i, p in enumerate(self._parts):
|
|
for i, p in enumerate(self._parts):
|
|
@@ -73,7 +78,7 @@ class BasePart(ABC):
|
|
return repr(self.as_annotation)
|
|
return repr(self.as_annotation)
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
- def new(image, annotation, rescale_size=-1):
|
|
|
|
|
|
+ def new(image, annotation, rescale_size=-1, center_cropped=True):
|
|
from .annotation import BBoxPart, LocationPart
|
|
from .annotation import BBoxPart, LocationPart
|
|
if len(annotation) == 4:
|
|
if len(annotation) == 4:
|
|
return LocationPart(image, annotation, rescale_size)
|
|
return LocationPart(image, annotation, rescale_size)
|
|
@@ -82,14 +87,11 @@ class BasePart(ABC):
|
|
else:
|
|
else:
|
|
raise ValueError("Unknown part annotation format: {}".format(annotation))
|
|
raise ValueError("Unknown part annotation format: {}".format(annotation))
|
|
|
|
|
|
- def rescale(self, image, annotation, rescale_size):
|
|
|
|
|
|
+ def rescale(self, image, annotation, rescale_size, center_cropped=True):
|
|
if rescale_size is not None and rescale_size > 0:
|
|
if rescale_size is not None and rescale_size > 0:
|
|
- h, w, c = utils.dimensions(image)
|
|
|
|
- scale = np.array([w, h]) / rescale_size
|
|
|
|
xy = annotation[1:3]
|
|
xy = annotation[1:3]
|
|
- xy = xy * scale
|
|
|
|
- annotation[1:3] = xy
|
|
|
|
-
|
|
|
|
|
|
+ new_xy = utils.rescale(image, xy, rescale_size, center_cropped)
|
|
|
|
+ annotation[1:3] = new_xy
|
|
return annotation
|
|
return annotation
|
|
|
|
|
|
@property
|
|
@property
|