Ejemplo n.º 1
0
    def __getitem__(self, index):
        HR_path, LR_path = None, None
        scale = self.opt['scale']
        HR_size = self.opt['HR_size']

        # get HR image
        HR_path = self.paths_HR[index]
        img_HR = common.read_img(self.HR_env, HR_path)

        # get LR image
        if self.paths_LR:
            LR_path = self.paths_LR[index]
            img_LR = common.read_img(self.LR_env, LR_path)
        else:
            raise NotImplementedError('Low resolution images do not exist')

        img_LR, img_HR = self._get_patch(img_LR, img_HR, scale, HR_size, self.opt['phase'])
        # channel conversion
        if self.opt['color']:
            img_LR, img_HR = common.channel_convert(img_HR.shape[2], [img_LR, img_HR], self.opt['color'])

        # HWC to CHW, BGR to RGB, numpy to tensor

        tensor_LR, tensor_HR = common.np2Tensor([img_LR, img_HR])

        if LR_path is None:
            LR_path = HR_path

        return {'LR': tensor_LR, 'HR': tensor_HR, 'LR_path': LR_path, 'HR_path': HR_path}
Ejemplo n.º 2
0
    def __getitem__(self, index):
        HR_path, LR_path = None, None
        scale = self.opt['scale']
        HR_size = self.opt['HR_size']

        # get HR image
        HR_path = self.paths_HR[index]
        img_HR = common.read_img(self.HR_env, HR_path)

        # get LR image
        if self.paths_LR:
            LR_path = self.paths_LR[index]
            img_LR = common.read_img(self.LR_env, LR_path)
        else:
            raise NotImplementedError('Low resolution images do not exist')

        # get coeff
        coeff_path = self.path_coeff[index]
        coeff = common.read_coeff(self.coeff_env, coeff_path)
        coeff = [coeff[0][i] for i in range(coeff.size)]

        # channel conversion
        if self.opt['color']:
            img_LR, img_HR = common.channel_convert(img_HR.shape[2], [img_LR, img_HR], self.opt['color'])

        # HWC to CHW, BGR to RGB, numpy to tensor
        tensor_LR = torch.from_numpy(np.ascontiguousarray(img_LR)).float()
        tensor_HR = torch.from_numpy(np.ascontiguousarray(img_HR)).float()

        if LR_path is None:
            LR_path = HR_path

        return {'LR': tensor_LR, 'HR': tensor_HR, 'LR_path': LR_path, 'HR_path': HR_path, 'coeff': coeff}
Ejemplo n.º 3
0
 def __getitem__(self, idx):
     lr, hr, lr_path, hr_path = self._load_file(idx)
     lr, hr = self._get_patch(lr, hr)
     # channel conversion
     if self.opt['color']:
         lr, hr = common.channel_convert(hr.shape[2], [lr, hr], self.opt['color'])
     lr_tensor, hr_tensor = common.np2Tensor([lr, hr], self.opt['rgb_range'])
     return {'LR': lr_tensor, 'HR': hr_tensor, 'LR_path': lr_path, 'HR_path': hr_path}
Ejemplo n.º 4
0
    def __getitem__(self, index):
        LR_path = None

        # get LR image
        LR_path = self.paths_LR[index]
        img_LR = util.read_img(self.LR_env, LR_path)
        H, W, C = img_LR.shape

        # channel conversion
        if self.opt['color']:
            img_LR = util.channel_convert(C, self.opt['color'], [img_LR])[0]

        # HWC to CHW, BGR to RGB, numpy to tensor
        if img_LR.shape[2] == 3:
            img_LR = img_LR[:, :, [2, 1, 0]]
        img_LR = torch.from_numpy(
            np.ascontiguousarray(np.transpose(img_LR, (2, 0, 1)))).float()

        return {'LR': img_LR, 'LR_path': LR_path}