def __getitem__(self, index):
        # ===== fetch data ===== #
        img_path = osp.join(self.data_file_dir, self.image_list[index])
        img, img_align, mid = self._fetch_data(img_path)

        # ===== data aug ===== #
        if self.transform.resize:
            img, _ = resize(img, mid, self.transform.resize)
            img_align, _ = resize(img_align, mid, self.transform.resize)
        if self.transform.rotate:
            img, _ = random_rotate(img, mid, self.transform.rotate)
        if self.transform.flip:
            img, _ = random_mirror(img, mid)
        if self.transform.gaussian_kernels:
            img = random_gaussian_blur(img, self.transform.gaussian_kernels)
        if self.transform.brightness:
            img = random_brightness(img, self.transform.brightness)

        img = normalize(img)
        img_align = normalize(img_align)

        # ===== torch data format ===== #
        img = torch.FloatTensor(img.transpose(2, 0, 1))
        img_align = torch.FloatTensor(img_align.transpose(2, 0, 1))

        if self.stage == 'test':
            return img, img_align, self.image_list[index]
        else:
            return img, img_align
Esempio n. 2
0
    def __call__(self, img, gt):
        img, gt = random_mirror(img, gt)
        if config.train_scale_array is not None:
			 img, gt, scale = random_scale(img, gt, config.train_scale_array)
        img = normalize(img, self.img_mean, self.img_std)
		# pytorch input need image value range from 0-1
        crop_size = (config.image_height, config.image_width)
        crop_pos = generate_random_crop_pos(img.shape[:2], crop_size)
		# get legal crop start position
        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)
		 #gt padding value is 225, image padding value is 0
        # add padding to those image with smaller shape
        return p_img, p_gt
Esempio n. 3
0
    def __call__ (self, img, gt):
        # can be not 320 when evaluate
        img = normalize(img, self.img_mean, self.img_std)
        
        im_original_shape = img.shape[:2]   # [500 375]
        print(im_original_shape)
        
        img = mic.imresize(img, self.target_size/ float(max(im_original_shape)))

        resized_shape = img.shape[:2]   # 320 240
        margin  = [(self.target_size - resized_shape[0])//2, (self.target_size - resized_shape[1])//2 ]   # 0, 40
        img = cv2.copyMakeBorder(img, margin[0], self.target_size - resized_shape[0] - margin[0], 
            margin[1], self.target_size - resized_shape[1] - margin[1], cv2.BORDER_REFLECT_101)
        
        assert (img.shape[0] == img.shape[1] == self.target_size)
        return img, gt, dict(margin = margin, resized_shape = resized_shape, im_original_shape = im_original_shape)
Esempio n. 4
0
 def __call__ (self, img, gt, sal):
     img_ = normalize(img, self.img_mean, self.img_std)
     return img_, gt, sal