def transform(self, image): """ Transform the image. Args: image(numpy.ndarray): Original image to be transformed. Returns: numpy.ndarray, transformed image. """ image = check_numpy_param('image', image) ori_dtype = image.dtype rgb, chw, normalized, gray3dim, image = self._check(image) if rgb: h, w, _ = np.shape(image) else: h, w = np.shape(image) move_x_centor = w / 2*(1 - self.factor_x) move_y_centor = h / 2*(1 - self.factor_y) img = to_pil(image) trans_image = img.transform(img.size, Image.AFFINE, (self.factor_x, 0, move_x_centor, 0, self.factor_y, move_y_centor)) trans_image = self._original_format(trans_image, chw, normalized, gray3dim) return trans_image.astype(ori_dtype)
def transform(self, image): """ Transform the image. Args: image(numpy.ndarray): Original image to be transformed. Returns: numpy.ndarray, transformed image. """ _, chw, normalized, gray3dim, image = self._check(image) img = to_pil(image) trans_image = img.rotate(self.angle, expand=False) trans_image = self._original_format(trans_image, chw, normalized, gray3dim) return trans_image
def transform(self, image): """ Transform the image. Args: image (numpy.ndarray): Original image to be transformed. Returns: numpy.ndarray, transformed image. """ _, chw, normalized, gray3dim, image = self._check(image) image = to_pil(image) trans_image = image.filter( ImageFilter.GaussianBlur(radius=self.radius)) trans_image = self._original_format(trans_image, chw, normalized, gray3dim) return trans_image
def transform(self, image): """ Transform the image. Args: image (numpy.ndarray): Original image to be transformed. Returns: numpy.ndarray, transformed image. """ _, chw, normalized, gray3dim, image = self._check(image) image = to_pil(image) img_contrast = ImageEnhance.Brightness(image) trans_image = img_contrast.enhance(self.factor) trans_image = self._original_format(trans_image, chw, normalized, gray3dim) return trans_image
def transform(self, image): """ Transform the image. Args: image (numpy.ndarray): Original image to be transformed. Returns: numpy.ndarray, transformed image. """ image = check_numpy_param('image', image) ori_dtype = image.dtype _, chw, normalized, gray3dim, image = self._check(image) image = to_pil(image) img_contrast = ImageEnhance.Contrast(image) trans_image = img_contrast.enhance(self.factor) trans_image = self._original_format(trans_image, chw, normalized, gray3dim) return trans_image.astype(ori_dtype)
def transform(self, image): """ Transform the image. Args: image(numpy.ndarray): Original image to be transformed. Returns: numpy.ndarray, transformed image. """ _, chw, normalized, gray3dim, image = self._check(image) img = to_pil(image) if self.auto_param: image_shape = np.shape(image) self.x_bias = image_shape[0] * self.x_bias self.y_bias = image_shape[1] * self.y_bias trans_image = img.transform(img.size, Image.AFFINE, (1, 0, self.x_bias, 0, 1, self.y_bias)) trans_image = self._original_format(trans_image, chw, normalized, gray3dim) return trans_image
def transform(self, image): """ Transform the image. Args: image(numpy.ndarray): Original image to be transformed. Returns: numpy.ndarray, transformed image. """ image = check_numpy_param('image', image) ori_dtype = image.dtype rgb, chw, normalized, gray3dim, image = self._check(image) img = to_pil(image) if rgb: h, w, _ = np.shape(image) else: h, w = np.shape(image) if self.factor_x != 0: boarder_x = [0, -w, -self.factor_x*h, -w - self.factor_x*h] min_x = min(boarder_x) max_x = max(boarder_x) scale = (max_x - min_x) / w move_x_cen = (w - scale*w - scale*h*self.factor_x) / 2 move_y_cen = h*(1 - scale) / 2 else: boarder_y = [0, -h, -self.factor_y*w, -h - self.factor_y*w] min_y = min(boarder_y) max_y = max(boarder_y) scale = (max_y - min_y) / h move_y_cen = (h - scale*h - scale*w*self.factor_y) / 2 move_x_cen = w*(1 - scale) / 2 trans_image = img.transform(img.size, Image.AFFINE, (scale, scale*self.factor_x, move_x_cen, scale*self.factor_y, scale, move_y_cen)) trans_image = self._original_format(trans_image, chw, normalized, gray3dim) return trans_image.astype(ori_dtype)