def _resize_img(self, results): if self.keep_ratio: img1, scale_factor1 = commons.imrescale(results['img1'], results['scale'], return_scale=True) img2, scale_factor2 = commons.imrescale(results['img2'], results['scale'], return_scale=True) else: img1, w_scale, h_scale = commons.imresize(results['img1'], results['scale'], return_scale=True) scale_factor1 = np.array([w_scale, h_scale, w_scale, h_scale], dtype=np.float32) img2, w_scale, h_scale = commons.imresize(results['img2'], results['scale'], return_scale=True) scale_factor2 = np.array([w_scale, h_scale, w_scale, h_scale], dtype=np.float32) results['img1'] = img1 results['img2'] = img2 results['img1_shape'] = img1.shape results['img2_shape'] = img2.shape results['pad1_shape'] = img1.shape # in case that there is no padding results['pad2_shape'] = img2.shape # in case that there is no padding results['scale_factor1'] = scale_factor1 results['scale_factor2'] = scale_factor2 results['keep_ratio'] = self.keep_ratio
def _resize_img(self, results): results["img2"] = results['img'].copy() flag = random.random() donw_up_stage = random.randint(0, self.max_stage) if flag < 0.5: for i in range(donw_up_stage): results["img2"] = cv2.pyrDown(results["img2"]) for i in range(donw_up_stage): results["img2"] = cv2.pyrUp(results["img2"]) results['img2'] = cv2.resize( results['img2'], (results['img'].shape[1], results['img'].shape[0])) else: for i in range(donw_up_stage): results["img"] = cv2.pyrDown(results["img"]) for i in range(donw_up_stage): results["img"] = cv2.pyrUp(results["img"]) results['img'] = cv2.resize( results['img'], (results['img2'].shape[1], results['img2'].shape[0])) assert results['img2'].shape[0] == results['img'].shape[0] and \ results['img2'].shape[1] == results['img'].shape[1] if self.keep_ratio: img1, scale_factor1 = commons.imrescale(results['img'], results['scale'], return_scale=True) img2, scale_factor2 = commons.imrescale(results['img2'], results['scale'], return_scale=True) else: img1, w_scale, h_scale = commons.imresize(results['img'], results['scale'], return_scale=True) scale_factor1 = np.array([w_scale, h_scale, w_scale, h_scale], dtype=np.float32) img2, w_scale, h_scale = commons.imresize(results['img2'], results['scale'], return_scale=True) scale_factor2 = np.array([w_scale, h_scale, w_scale, h_scale], dtype=np.float32) results['img1'] = img1 results['img2'] = img2 results['img1_shape'] = img1.shape results['img2_shape'] = img2.shape results['pad1_shape'] = img1.shape # in case that there is no padding results['pad2_shape'] = img2.shape # in case that there is no padding results['scale_factor1'] = scale_factor1 results['scale_factor2'] = scale_factor2 results['keep_ratio'] = self.keep_ratio
def _resize_img(self, results): if self.keep_ratio: img, scale_factor = commons.imrescale(results['img'], results['scale'], return_scale=True) else: img, w_scale, h_scale = commons.imresize(results['img'], results['scale'], return_scale=True) scale_factor = np.array([w_scale, h_scale, w_scale, h_scale], dtype=np.float32) results['img'] = img results['img_shape'] = img.shape results['pad_shape'] = img.shape # in case that there is no padding results['scale_factor'] = scale_factor results['keep_ratio'] = self.keep_ratio
def __call__(self, results): if results['keep_ratio']: gt_seg = commons.imrescale(results['gt_semantic_seg'], results['scale'], interpolation='nearest') else: gt_seg = commons.imresize(results['gt_semantic_seg'], results['scale'], interpolation='nearest') if results['flip']: gt_seg = commons.imflip(gt_seg) if gt_seg.shape != results['pad_shape']: gt_seg = commons.impad(gt_seg, results['pad_shape'][:2]) if self.scale_factor != 1: gt_seg = commons.imrescale(gt_seg, self.scale_factor, interpolation='nearest') results['gt_semantic_seg'] = gt_seg return results