def resize_origin_and_bitmap(origin: PointLocation, bitmap: np.ndarray, in_size, out_size): new_size = restore_proportional_size(in_size=in_size, out_size=out_size) row_scale = new_size[0] / in_size[0] col_scale = new_size[1] / in_size[1] # TODO: Double check (+restore_proportional_size) or not? bitmap.shape and in_size are equal? # Make sure the resulting size has at least one pixel in every direction (i.e. limit the shrinkage to avoid having # empty bitmaps as a result). scaled_rows = max(round(bitmap.shape[0] * row_scale), 1) scaled_cols = max(round(bitmap.shape[1] * col_scale), 1) scaled_origin = PointLocation(row=round(origin.row * row_scale), col=round(origin.col * col_scale)) scaled_bitmap = resize_inter_nearest(bitmap, (scaled_rows, scaled_cols)) return scaled_origin, scaled_bitmap
def make_gt(self, image_shape, ann, ignore_not_mapped_classes=False): # int32 instead of int64 because opencv cannot draw on int64 bitmaps. gt = np.ones(image_shape[:2], dtype=np.int32) * self._bkg_color # default bkg for label in ann.labels: gt_color = self._class_mapping.get(label.obj_class.name, None) if gt_color is None: # TODO: Factor out this check to lib if not ignore_not_mapped_classes: raise RuntimeError( 'Missing class mapping (title to index). Class {}.'. format(label.obj_class.name)) else: label.geometry.draw(gt, gt_color) gt = sly_image.resize_inter_nearest(gt, self._out_size).astype(np.int64) return gt
def _resize_mask(mask, out_rows, out_cols): return resize_inter_nearest(mask.astype(np.uint8), (out_rows, out_cols)).astype(np.bool)