def __call__(self, img, gt): img, gt = random_mirror(img, gt) if self.config.train_scale_array is not None: img, gt, scale = random_scale(img, gt, self.config.train_scale_array) crop_size = (self.config.image_height, self.config.image_width) crop_pos = generate_random_crop_pos(img.shape[:2], crop_size) if self.augment: p_img, _ = random_crop_pad_to_shape( normalize(img, self.img_mean, self.img_std), crop_pos, crop_size, 0) p_img_k, _ = random_crop_pad_to_shape( normalize(np.array(self.data_transforms(Image.fromarray(img))), self.img_mean, self.img_std), crop_pos, crop_size, 0) p_img = p_img.transpose(2, 0, 1) p_img_k = p_img_k.transpose(2, 0, 1) extra_dict = {'img_k': p_img_k} else: p_img, _ = random_crop_pad_to_shape( normalize(img, self.img_mean, self.img_std), crop_pos, crop_size, 0) p_img = p_img.transpose(2, 0, 1) extra_dict = None p_gt, _ = random_crop_pad_to_shape(gt, crop_pos, crop_size, 255) p_gt = cv2.resize( p_gt, (self.config.image_width // self.config.gt_down_sampling, self.config.image_height // self.config.gt_down_sampling), interpolation=cv2.INTER_NEAREST) return p_img, p_gt, extra_dict
def process_image(self, img, resize=None, crop_size=None): p_img = img if img.shape[2] < 3: im_b = p_img im_g = p_img im_r = p_img p_img = np.concatenate((im_b, im_g, im_r), axis=2) if resize is not None: if isinstance(resize, float): _size = p_img.shape[:2] # p_img = np.array(Image.fromarray(p_img).resize((int(_size[0]*resize), int(_size[1]*resize)), Image.BILINEAR)) p_img = np.array(Image.fromarray(p_img).resize((int(_size[1]*resize), int(_size[0]*resize)), Image.BILINEAR)) elif isinstance(resize, tuple) or isinstance(resize, list): assert len(resize) == 2 p_img = np.array(Image.fromarray(p_img).resize((int(resize[0]), int(resize[1])), Image.BILINEAR)) p_img = normalize(p_img, self.image_mean, self.image_std) if crop_size is not None: p_img, margin = pad_image_to_shape(p_img, crop_size, cv2.BORDER_CONSTANT, value=0) p_img = p_img.transpose(2, 0, 1) return p_img, margin p_img = p_img.transpose(2, 0, 1) return p_img
def process_image(self, img, crop_size=None): p_img = img if img.shape[2] < 3: im_b = p_img im_g = p_img im_r = p_img p_img = np.concatenate((im_b, im_g, im_r), axis=2) p_img = normalize(p_img, self.image_mean, self.image_std) if crop_size is not None: p_img, margin = pad_image_to_shape(p_img, crop_size, cv2.BORDER_CONSTANT, value=0) p_img = p_img.transpose(2, 0, 1) return p_img, margin p_img = p_img.transpose(2, 0, 1) return p_img
def __call__(self, img, gt): img, gt = random_mirror(img, gt) if self.config.train_scale_array is not None: img, gt, scale = random_scale(img, gt, self.config.train_scale_array) img = normalize(img, self.img_mean, self.img_std) crop_size = (self.config.image_height, self.config.image_width) crop_pos = generate_random_crop_pos(img.shape[:2], crop_size) p_img, _ = random_crop_pad_to_shape(img, crop_pos, crop_size, 0) p_gt, _ = random_crop_pad_to_shape(gt, crop_pos, crop_size, 255) p_gt = cv2.resize( p_gt, (self.config.image_width // self.config.gt_down_sampling, self.config.image_height // self.config.gt_down_sampling), interpolation=cv2.INTER_NEAREST) p_img = p_img.transpose(2, 0, 1) extra_dict = None return p_img, p_gt, extra_dict