Exemple #1
0
    def _get_patch(self, lr, hr,lr2=None,hr2=None):
        patch_size = self.args.patch_size
        scale = self.scale[self.idx_scale]
        multi_scale = len(self.scale) > 1

        if self.train:
            if (self.args.nmodels == 1):
                lr, hr = common.get_patch(
                    lr, hr, patch_size, scale, multi_scale=multi_scale
                )
                lr, hr = common.augment([lr, hr])
                lr = common.add_noise(lr, self.args.noise)
            else:
                lr, hr, lr2, hr2 = common.get_patch_2model(
                    lr, hr, lr2, hr2, patch_size, scale, multi_scale=multi_scale
                )               
        else:
            if (self.args.nmodels == 1):
                ih, iw = lr.shape[0:2]
                hr = hr[0:ih * scale, 0:iw * scale]
            else:
                ih, iw = lr.shape[0:2]
                hr = hr[0:ih * scale, 0:iw * scale]            
                hr2 = hr2[0:ih * scale, 0:iw * scale]   

        return lr, hr, lr2, hr2
Exemple #2
0
 def _get_patch(self, lr, hr):
     LR_size = self.opt['LR_size']
     # random crop and augment
     lr, hr = common.get_patch(lr, hr, LR_size, self.scale)
     lr, hr = common.augment([lr, hr])
     lr = common.add_noise(lr, self.opt['noise'])
     return lr, hr
Exemple #3
0
    def __getitem__(self, idx):

        blur = imageio.imread(self.blur_list[idx], pilmode='RGB')
        if len(self.sharp_list) > 0:
            sharp = imageio.imread(self.sharp_list[idx], pilmode='RGB')
            imgs = [blur, sharp]
        else:
            imgs = [blur]

        if self.mode == 'train':
            imgs = common.crop(*imgs, ps=self.args.patch_size)
            if self.args.augment:
                imgs = common.augment(*imgs, hflip=True, rot=True, shuffle=True, change_saturation=True, rgb_range=self.args.rgb_range)
                imgs[0] = common.add_noise(imgs[0], sigma_sigma=2, rgb_range=self.args.rgb_range)
        else:
            pass    # deliver test image as is.

        if self.args.gaussain_pyramid:
            imgs = common.generate_pyramid(*imgs, n_scales=self.args.n_scales)

        imgs = common.np2tensor(*imgs)
        relpath = os.path.relpath(self.blur_list[idx], self.subset_root)

        blur = imgs[0]
        sharp = imgs[1] if len(imgs) > 1 else False

        return blur, sharp, idx, relpath
Exemple #4
0
    def _get_patch(self, ir, vis):
        Label_Size = self.opt['Label_Size']
        if self.train:
            ir, vis = common.get_patch(ir, vis, Label_Size, self.scale)
            ir, vis = common.augment([ir, vis])
            ir = common.add_noise(ir, self.opt['noise'])

        return ir, vis
Exemple #5
0
    def __getitem__(self, idx):
        lr, hr, filename = self._load_file(idx)
        pair = self.get_patch(lr, hr)
        pair = common.set_channel(*pair, n_channels=self.args.n_colors)
        pair = common.add_noise(*pair,
                                noise_type=self.args.noise_type,
                                noise_param=self.args.noise_param)
        pair_t = common.np2Tensor(*pair, rgb_range=self.args.rgb_range)

        return pair_t[0], pair_t[1], filename
    def _get_patch(self, lr, hr, scale, patch_size, phase_str):
        if phase_str == 'train':
            lr, hr = common.get_patch(
                lr, hr, patch_size, scale)
            lr, hr = common.augment([lr, hr], self.opt['use_flip'], self.opt['use_rot'])
            lr = common.add_noise(lr, self.opt['noise'])
        else:
            hr = common.modcrop(hr, scale)

        return lr, hr
    def _get_patch(self, lr, hr, lrpan, pan, msx2=False):

        LR_size = self.opt['LR_size']
        # random crop and augment
        lr, hr, lrpan, pan = common.get_patch(lr, hr, pan,
                 LR_size, self.scale, lrpan=lrpan, msx2=msx2)
        lr, hr, lrpan, pan = common.augment([lr, hr, lrpan, pan])
        lr = common.add_noise(lr, self.opt['noise'])

        return lr, hr, lrpan, pan
Exemple #8
0
    def _get_patch(self, lr, hr):
        LR_size = self.opt['LR_size']
        if self.train:
            lr, hr = common.get_patch(
                lr, hr, LR_size, self.scale)
            lr, hr = common.augment([lr, hr])
            lr = common.add_noise(lr, self.opt['noise'])
        else:
            hr = common.modcrop(hr, self.scale)

        return lr, hr
Exemple #9
0
    def _get_patch(self, img_input, img_tar):
        patch_size = self.args.patch_size
        scale = self.scale
        if self.train:
            img_input, img_tar = common.get_patch(img_input, img_tar, patch_size, scale)
            img_input, img_tar = common.augment([img_input, img_tar])
            img_input = common.add_noise(img_input, self.sigma)
        else:
            ih, iw = img_input.shape[0:2]
            img_tar = img_tar[0:ih * scale, 0:iw * scale]

        return img_input, img_tar
Exemple #10
0
    def _get_patch(self, lr, hr):
        patch_size = self.args.patch_size
        scale = self.noise_g[self.idx_scale]
        multi_scale = len(self.noise_g) > 1
        if self.train:
            lr, hr = common.get_patch(
                lr, hr, patch_size, scale, multi_scale=multi_scale
            )
            lr, hr = common.augment([lr, hr])
            lr = common.add_noise(lr, self.args.noise)
        else:
            ih, iw = lr.shape[0:2]
            hr = hr[0:ih * scale, 0:iw * scale]

        return lr, hr
Exemple #11
0
    def _get_patch(self, lr, hr):
        patch_size = self.args.patch_size
        scale = self.scale[self.idx_scale]
        multi_scale = len(self.scale) > 1
        if self.train:
            #from IPython import embed; embed(); exit()
            lr, hr = common.get_patch(lr,
                                      hr,
                                      patch_size,
                                      scale,
                                      multi_scale=multi_scale)
            lr, hr = common.augment([lr, hr])
            lr = common.add_noise(lr, self.args.noise)
        else:
            ih, iw = lr.shape[0:2]
            hr = hr[0:ih * scale, 0:iw * scale]

        return lr, hr
Exemple #12
0
    def get_patch(self, lr, hr):
        scale = self.scale[self.idx_scale]
        if self.train:
            lr, hr = common.get_patch(lr,
                                      hr,
                                      patch_size=self.args.patch_size,
                                      scale=scale,
                                      multi=(len(self.scale) > 1),
                                      input_large=self.input_large)
            if not self.args.no_augment: lr, hr = common.augment(lr, hr)
            # HaiMai: Add Noise to Signal
            lr = common.add_noise(lr, self.args.noise)
            lr = common.gamma_correction(lr, 3)
        else:
            ih, iw = lr.shape[:2]
            hr = hr[0:ih * scale, 0:iw * scale]

        return lr, hr
Exemple #13
0
def prepare_data(args):
    print("Preparing DIV2K dataset ...")
    h5file_path = "{}/DIV2K_np_test_{}.h5".format(args.h5file_dir, args.test_sigma)
    h5 = h5py.File(h5file_path, 'w')
    h_group = h5.create_group('h')
    l_group = h5.create_group('l')

    h_list = sorted(glob.glob(args.test_h + "*.png"))

    with tqdm(total=len(h_list)) as t:
        t.set_description("H & L")
        for i, path in enumerate(h_list):
            img = img2np(load_img(path))
            h_group.create_dataset(str(i), data=img)
            l_group.create_dataset(str(i), data=add_noise(img, float(args.test_sigma), train=False))
            t.update()

    h5.close()
    print("Prepare successfully")
Exemple #14
0
    def _get_patch(self, lr, hr):
        patch_size = self.args.patch_size  # 192
        scale = self.scale[self.idx_scale]  # 4
        multi_scale = len(self.scale) > 1
        # lr: (48,48,3)
        # hr: (192,192,3)
        if self.train:
            lr, hr = common.get_patch(lr,
                                      hr,
                                      patch_size,
                                      scale,
                                      multi_scale=multi_scale)
            lr, hr = common.augment([lr, hr])
            # 为低分辨率图片加特征
            lr = common.add_noise(lr, self.args.noise)
        else:
            ih, iw = lr.shape[0:2]
            hr = hr[0:ih * scale, 0:iw * scale]

        return lr, hr
Exemple #15
0
    def get_patch(self, lr, hr):
        #patch_size = self.args.patch_size
        scale = self.scale[self.idx_scale]
        if self.train:
            lr, hr = common.get_patch(
                lr, hr,
                patch_size=self.args.patch_size,
                scale=scale,
                multi=(len(self.scale) > 1),
                input_large=self.input_large
            )
           # if not self.args.no_augment: lr, hr = common.augment(lr, hr)
            ###############################
            lr, hr = common.augment(lr, hr)
            lr = common.add_noise(lr, self.args.noise)
            ###############################
        else:
            ih, iw = lr.shape[:2]
            hr = hr[0:ih * scale, 0:iw * scale]

        return lr, hr