示例#1
0
    def get_patch(self, lr, hr):
        scale = self.scale[self.idx_scale]
        # print("scale:",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)
        elif not self.benchmark:
            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)
        else:
            try:
                ih, iw = lr.shape[:2]
            except:
                ih, iw = lr[0]['image'].shape[:2]
            try:
                hr = hr[0:ih * scale, 0:iw * scale]
            except:
                hr = hr[0]['image'][0:ih * scale, 0:iw * scale]

        return lr, hr
示例#2
0
    def _get_patch_bk(self, lr, hr):
        LR_size = self.opt['LR_size']
        
        lr, hr = common.get_patch(lr, hr, LR_size, self.scale)
        lr, hr = common.augment([lr, hr])

        return lr, hr
示例#3
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)
            #print(lr.shape)
            if not self.args.no_augment: lr, hr = common.augment(lr, hr)

        # print(lr.shape)
        else:
            # 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)
            ih, iw = lr.shape[:2]
            hr = hr[0:ih * scale, 0:iw * scale]

        return lr, hr
示例#4
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
示例#5
0
    def _get_patch(self, ):  # lr, hr):
        patch_size = self.args.patch_size
        scale = self.scale[0]
        multi_scale = len(self.scale) > 1

        batch_size = 1  #min(self.args.batch_size, len(self.remain_idx))
        # scale = self.scale[self.idx_scale]
        # multi_scale = len(self.scale) > 1
        idx = self.remain_idx[:batch_size]

        self.remain_idx = self.remain_idx[batch_size:]
        lr, hr = self.raw_lr[idx], self.raw_hr[idx]

        lr = lr.astype(np.float32)[0]
        hr = hr.astype(np.float32)[0]

        lr = lr[:, :, ::-1]
        hr = hr[:, :, ::-1]

        # lr = lr.transpose(2,0,1)
        # hr = hr.transpose(2,0,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
示例#6
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
示例#7
0
    def _get_patch(self, hr, filename):
        patch_size = self.args.patch_size

        if self.train:
            scale = self.scale[0]
            if self.args.task_type == 'denoising':
                lr, hr = common.get_patch_noise(
                    hr, patch_size, scale
                )
            if self.args.task_type == 'SISR':
                lr, hr = common.get_patch_bic(
                    hr, patch_size, scale
                )
            if self.args.task_type == 'JIAR':
                lr, hr = common.get_patch_compress(
                    hr, patch_size, scale
                )

            lr, hr = common.augment([lr, hr])
            return lr, hr, scale
        else:
            scale = self.scale[0]
            if self.args.task_type == 'denoising':
                lr, hr = common.add_img_noise(
                    hr, scale
                )
            if self.args.task_type == 'SISR':
                lr, hr = self._get_patch_test(
                    hr, patch_size, scale
                )
            if self.args.task_type == 'JIAR':
                lr, hr = common.get_img_compress(
                    hr, patch_size, scale
                )
            return lr, hr, scale
示例#8
0
    def get_patch(self, lr, hr, lrr, hq):
        scale = self.scale[self.idx_scale]
        multi_scale = len(self.scale) > 1
        if self.train:
            lr, hr = common.get_patch(lr,
                                      hr,
                                      patch_size=self.args.patch_size,
                                      scale=scale,
                                      multi_scale=multi_scale)

            lrr, _ = common.get_patch(lrr,
                                      lrr,
                                      patch_size=self.args.patch_size,
                                      scale=scale,
                                      multi_scale=multi_scale)

            hq, _ = common.get_patch(hq,
                                     hq,
                                     patch_size=self.args.patch_size,
                                     scale=scale,
                                     multi_scale=multi_scale)

            if not self.args.no_augment:
                lr, hr, lrr, hq = common.augment(lr, hr, lrr, hq)
        else:
            ih, iw = lr.shape[:2]
            hr = hr[0:ih, 0:iw]
            lrr = lrr[0:ih, 0:iw]
            hq = hq[0:ih, 0:iw]

        return lr, hr, lrr, hq
示例#9
0
    def get_patch(self, lr, labels):

        data = []
        data.append(lr)
        for label in labels:
            data.append(label)
        # LR, HR, labels

        scale = self.scale[self.idx_scale]
        if self.n_colors == 4:
            scale = scale * 2

        #print(scale)
        #print(self.args.test_patch_size)
        if self.train:
            data = common.get_patch(*data,
                                    patch_size=self.args.patch_size,
                                    scale=scale,
                                    multi=(len(self.scale) > 1),
                                    input_large=self.input_large)
        else:
            data = common.get_center_patch(
                *data,
                patch_size=self.args.test_patch_size,
                scale=scale,
                multi=(len(self.scale) > 1),
                input_large=self.input_large)

        if self.train and not self.args.no_augment:
            data = common.augment(*data)
        #print(data[0].shape)
        #print(data[1].shape)
        return data
示例#10
0
文件: vsrdata.py 项目: royson/VDAN
    def get_patch(self, lr, hr, ix, iy):
        """
        Returns patches for multiple scales
        """
        scale = self.scale
        if self.train:
            patch_size = self.args.patch_size - (self.args.patch_size % 4)
            lr, hr = common.get_patch(
                lr,
                hr,
                patch_size=patch_size,
                scale=scale,
                ix=ix,
                iy=iy
            )
            if not self.args.no_augment:
                lr, hr = common.augment(lr, hr)
        else:
            ih, iw = lr.shape[:2]
            ih -= ih % 4
            iw -= iw % 4
            lr = lr[:ih, :iw]
            hr = hr[:ih * scale, :iw * scale]

        return lr, hr
示例#11
0
    def get_patch(self, lhr, ix, iy, hflip, vflip, rot90, scale):
        """
        Returns patches for multiple scales
        """
        '''if self.train:
            ih, iw = lr.shape[:2]
            ih -= ih % 4
            iw -= iw % 4
            lr = lr[:ih, :iw]
            hr = hr[:ih * scale, :iw * scale]'''
        if self.train:
            #patch_size = self.args.patch_size - (self.args.patch_size % 4)
            lhr = common.get_patch_onlyLR(
                    lhr,
                    patch_size_w=self.args.patch_size_w,
                    patch_size_h=self.args.patch_size_h,
                    ix=ix,
                    iy=iy,
                    scale=scale
                )
            if not self.args.no_augment:
                #lhr = img_as_ubyte(transform.rotate(lhr, jiao))
                lhr = common.augment(lhr, hflip, vflip, rot90)

        '''else:
            ih, iw, _ = lhr.shape
            ih = int(ih/scale)
            iw = int(iw/scale)
            ih -= ih % 4
            iw += iw % 4
            lhr = lhr[:ih*scale, :iw*scale]'''

        return lhr
示例#12
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
示例#13
0
    def __getitem__(self, idx):
        scale = self.scale[self.scaleIdx]
        if self.train:
            idx = (idx % self.args.nTrain) + 1
        else:
            idx = (idx + self.args.valOffset) + 1

        quality = random.randrange(len(
            self.args.quality)) if self.train else -1
        if self.args.ext == 'png':
            nameIn, nameTar = self.getFileName(idx, quality)
            imgIn = sio.imread(nameIn)
            imgTar = sio.imread(nameTar)
        elif self.args.ext == 'pt':
            nameIn, nameTar = self.getFileName(idx, quality)
            imgIn = torch.load(nameIn).numpy()
            imgTar = torch.load(nameTar).numpy()
        elif self.args.ext == 'ptpack':
            imgIn = self.packIn[self.scaleIdx][quality][idx].numpy()
            imgTar = self.packTar[idx].numpy()

        if self.train:
            imgIn, imgTar, pi = common.getPatch(imgIn, imgTar, self.args,
                                                scale)
            imgIn, imgTar, ai = common.augment(imgIn, imgTar)
        else:
            (ih, iw, c) = imgIn.shape
            imgTar = imgTar[0:ih * scale, 0:iw * scale, :]

        imgIn, imgTar = common.setChannel(imgIn, imgTar, self.args.nChannel)

        return common.np2Tensor(imgIn, imgTar, self.args.rgbRange,
                                self.args.precision)
示例#14
0
    def _get_patch(self, lr1, lr2, lr3, hr):

        LR_size = self.opt['LR_size']
        # random crop and augment
        lr1, lr2, lr3, hr = common.get_patch(lr1, lr2, lr3, hr, LR_size, self.scale)
        lr1, lr2, lr3, hr = common.augment([lr1, lr2, lr3, hr])

        return lr1, lr2, lr3, hr
示例#15
0
    def get_patch_no(self, lr, hr, pts):
        scale = self.scale[self.idx_scale]

        if self.train:
            if not self.args.no_augment:
                lr, hr, pts = common.augment(lr, hr, pts)

        return lr, hr, pts
 def get_patch(self, lr, hr, nr):
     lr, hr, nr = common.get_patch(lr,
                                   hr,
                                   nr,
                                   patch_size=self.opt.patch_size,
                                   n_channels=1)
     lr, hr, nr = common.augment(lr, hr, nr)
     return lr, hr, nr
示例#17
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
示例#18
0
    def generate_lr_hr(self, hr, idx):
        if self.train:
            # pick a blur kernel randomly
            k_idx = random.randrange(0,self.n_filters)
            kernel = self.filter_bank[k_idx]
            if len(kernel.shape) > 2:
                assert(False, "cannot handle 3d kernels")
            [k_h, k_w] = kernel.shape[:2]
            [h, w, c] = hr.shape[:3]
            
            # After convolution with the  blur kernel the patch size should be equal to self.hr_size
            # The valid sizez before convolution are given below
            patch_h = self.hr_size + k_h - 1
            patch_w = self.hr_size + k_w - 1

            # randomly extract a patch of this size from the hr image.
            hr_patch = self.extract_hrpatch(hr, patch_h, patch_w)

            blurred_stack = []
            # blur the patch using the kernel
            for ch in range(c):
                blurred_stack.append(convolve2d(hr_patch[:,:,ch], kernel, mode='valid'))
            blurred = np.stack(blurred_stack, axis=2)
            assert(blurred.shape[0]==self.hr_size, "Blurred shape = {}, valid hr shape = {}".format(blurred.shape, self.hr_size))
            lr = blurred[::self.scale, ::self.scale, :]
            assert(lr.shape[0]==self.lr_size, "lr shape = {}, valid shape = {}".format(lr.shape, self.lr_size))
            valid_hr_patch = hr_patch[int(k_h/2):-int(k_h/2), int(k_w/2):-int(k_w/2), :]
            
            noise_patch = self.get_noise_patch(lr.shape)
            noise_scaling = np.random.random()*3 + 1
            lr += noise_scaling*noise_patch
            lr = np.clip(lr, 0, 255)
            lr, valid_hr_patch = common.augment([lr, valid_hr_patch])
            # lr = misc.imresize(hr, 1/self.scale, interp='bicubic')
            # Add noise.
            # noise_level = random.random()*3
            # noise_patch = np.random.normal(0, noise_level, (self.lr_size, self.lr_size))
            # lr = lr + noise_patch[:,:,None]
            # lr = np.clip(lr, 0, 255)
            return valid_hr_patch, lr
        else:
            k_idx = idx % self.n_filters
            kernel = self.filter_bank[k_idx]
            [k_h, k_w] = kernel.shape[:2]
            [h, w, c] = hr.shape[:3]
            blurred_stack = []
            # blur the patch using the kernel
            for ch in range(c):
                blurred_stack.append(convolve2d(hr[:,:,ch], kernel, mode='valid'))
            blurred = np.stack(blurred_stack, axis=2)
            lr = blurred[::self.scale, ::self.scale, :]
            valid_hr = hr[int(k_h/2):-int(k_h/2), int(k_w/2):-int(k_w/2), :]
            noise_level = random.random()*12
            noise_patch = np.random.normal(0, noise_level, (lr.shape[0], lr.shape[1]))
            lr = lr + noise_patch[:,:,None]
            lr = np.clip(lr, 0, 255)
            return valid_hr, lr
示例#19
0
    def get_patch(self, lr, hr):
        scale = self.scale[self.idx_scale]
        lr, hr = common.get_mspatch(lr,
                                    hr,
                                    patch_size=self.args.patch_size,
                                    scale=scale)
        if not self.args.no_augment: lr, hr = common.augment(lr, hr)

        return lr, hr
示例#20
0
    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
示例#21
0
    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
示例#22
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)
        # print('shapes again here', lr.shape, hr.shape)
        lr, hr = common.augment([lr, hr])
        # lr = common.add_noise(lr, self.opt['noise'])
        # print('shapes again', lr.shape, hr.shape)
        return lr, hr
示例#23
0
 def _get_patch(self, img_in, img_tar):
     patch_size = self.opt.patch_size
     scale = self.scale
     if self.train:
         img_in, img_tar = common.get_patch(
             img_in, img_tar, patch_size=patch_size, scale=scale)
         img_in, img_tar = common.augment(img_in, img_tar)
     else:
         ih, iw = img_in.shape[:2]
         img_tar = img_tar[0:ih * scale, 0:iw * scale, :]
     return img_in, img_tar
示例#24
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
示例#25
0
    def get_patch(self, lr, hr):
        scale = self.scale[self.idx_scale]
        if self.train:
            hr, lr = common.get_patch(hr,
                                      lr,
                                      patch_size=self.args.patch_size,
                                      scale=scale,
                                      multi=(len(self.scale) > 1),
                                      input_large=True)
            if self.args.no_augment: lr, hr = common.augment(lr, hr)

        return lr, hr
示例#26
0
 def get_patch(self, lr, hr):
     scale = self.scale[0]
     if self.train:
         lr, hr = common.get_patch(
             lr, hr,
             patch_size=self.args.patch_size,
             scale=scale,
             multi=(len(self.scale) > 1),
         )
         if not self.args.no_augment:
             lr, hr = common.augment(lr, hr)
     return lr, hr
示例#27
0
    def _get_patch(self, hr, filename):
        patch_size = self.args.patch_size

        if self.train:
            scale = self.scale[0]
            lr, hr = common.get_patch_noise(hr, patch_size, scale)
            lr, hr = common.augment([lr, hr])
            return lr, hr, scale
        else:
            scale = self.scale[0]
            lr, hr = common.add_img_noise(hr, scale)
            return lr, hr, scale
示例#28
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
示例#29
0
文件: DIV2K.py 项目: laomao0/AIM_DAIN
    def _get_patch(self, img_in, img_tar):
        scale = self.scale[self.idx_scale]
        if self.train:
            img_in, img_tar, pi = common.get_patch(
                img_in, img_tar, self.args, scale)
            img_in, img_tar, ai = common.augment(img_in, img_tar)

            return img_in, img_tar, pi, ai
        else:
            ih, iw, c = img_in.shape
            img_tar = img_tar[0:ih * scale, 0:iw * scale, :]

            return img_in, img_tar, None, None
示例#30
0
    def get_patch(self, lr, hr):
        scale = 1
        if self.mode == 'train':
            lr, hr = common.get_patch(lr,
                                      hr,
                                      patch_size=self.args.patch_size,
                                      n_channels=self.n_channels)
            if self.args.augment: lr, hr = common.augment(lr, hr)
        else:
            ih, iw = lr.shape[:2]
            hr = hr[0:ih * scale, 0:iw * scale]

        return lr, hr