def resize(self, in_size, out_size): ''' The function resize calculates new parameters of point after resizing image :param in_size: input image size :param out_size: output image size :return: PointLocation class object ''' new_size = sly_image.restore_proportional_size(in_size=in_size, out_size=out_size) frow = new_size[0] / in_size[0] fcol = new_size[1] / in_size[1] return self.scale_frow_fcol(frow=frow, fcol=fcol)
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 scale(img: np.ndarray, ann: Annotation, frow: float = None, fcol: float = None, f: float = None) \ -> (np.ndarray, Annotation): """ Resize the input image array and annotation to the given size. Args: img: Input image array. ann: Input annotation. frow: Desired height scale height value frow: Desired width scale width value f: Desired height and width scale values in one Returns: A tuple containing resized image array and annotation. """ _validate_image_annotation_shape(img, ann) new_size = sly_image.restore_proportional_size(in_size=ann.img_size, frow=frow, fcol=fcol, f=f) res_img = sly_image.resize(img, new_size) res_ann = ann.resize(new_size) return res_img, res_ann
def resize(img: np.ndarray, ann: Annotation, size: tuple) -> (np.ndarray, Annotation): """ Resize the input image array and annotation to the given size. Args: img: Input image array. ann: Input annotation. size: Desired size (height, width) in pixels or -1. If one of values is -1 and "keep": true then for specific width height will be automatically computed to keep aspect ratio. Returns: A tuple containing resized image array and annotation. """ _validate_image_annotation_shape(img, ann) height = take_with_default(size[0], -1) # For backward capability width = take_with_default(size[1], -1) size = (height, width) new_size = sly_image.restore_proportional_size(in_size=ann.img_size, out_size=size) res_img = sly_image.resize(img, new_size) res_ann = ann.resize(new_size) return res_img, res_ann
def resize(self, in_size, out_size): new_size = sly_image.restore_proportional_size(in_size=in_size, out_size=out_size) frow = new_size[0] / in_size[0] fcol = new_size[1] / in_size[1] return self.scale_frow_fcol(frow=frow, fcol=fcol)