示例#1
0
    def __init__(self,
                 image_dirs,
                 is_gray=False,
                 crop_size=64,
                 random_scale=True,
                 rotate=True,
                 fliplr=True,
                 fliptb=True,
                 preload=True):
        super(SingleImageLoader, self).__init__()

        self.image_filenames = []
        self.preload = preload

        all_files = os.walk(image_dirs)
        for path, dir_list, file_list in all_files:
            self.image_filenames.extend(
                join(path, x) for x in file_list if is_image_file(x))
        if self.preload:
            self.image_list = []
            for file in self.image_filenames:
                img = Image.open(file).convert('RGB')
                self.image_list.append(img)

        self.is_gray = is_gray
        self.crop_size = crop_size
        self.rotate = rotate
        self.fliplr = fliplr
        self.fliptb = fliptb
        self.random_scale = random_scale
示例#2
0
文件: solver.py 项目: liyucs/RAGNet
    def prepare_data(self, train_path, is_ref_syn):
        blended = []
        transmission = []
        reflection = []
        if is_ref_syn:
            print('loading synthetic data...')
        else:
            print('loading real data...')

        for dirname in train_path:
            train_t_gt = dirname + "/transmission_layer/"
            train_r_gt = dirname + "/reflection_layer/"
            train_b = dirname + "/blended/"
            if is_ref_syn:
                r_list = os.listdir(train_r_gt)
            for _, _, fnames in sorted(os.walk(train_t_gt)):
                for fname in fnames:
                    if is_ref_syn:
                        if not fname in r_list:
                            continue
                    if is_image_file(fname):
                        path_transmission = os.path.join(train_t_gt, fname)
                        transmission_img = cv2.imread(path_transmission)
                        path_blended = os.path.join(train_b, fname)
                        blended_img = cv2.imread(path_blended)
                        path_reflection = os.path.join(train_r_gt, fname)
                        reflection_img = cv2.imread(path_reflection)

                        blended.append(blended_img)
                        transmission.append(transmission_img)
                        reflection.append(reflection_img)

        return blended, transmission, reflection
示例#3
0
 def __init__(self, dataPath='', loadSize=72, fineSize=64, flip=1):
     super(DATASET, self).__init__()
     # list all images into a list
     self.list = [x for x in listdir(dataPath) if is_image_file(x)]
     self.dataPath = dataPath
     self.loadSize = loadSize
     self.fineSize = fineSize
     self.flip = flip
示例#4
0
    def __init__(self, image_dir, is_gray=False, scale_factor=[2, 3, 4]):
        super(BenchmarkLoader, self).__init__()

        self.image_filenames = []
        all_files = os.walk(image_dir)
        for path, dir_list, file_list in all_files:
            self.image_filenames.extend(
                join(path, x) for x in file_list if is_image_file(x))
        # self.image_filenames = [join(image_dir, x) for x in sorted(listdir(image_dir)) if is_image_file(x)]
        self.is_gray = is_gray
        self.scale_factor = scale_factor
 def __init__(self,
              dataPath='facades/train',
              loadSize=286,
              fineSize=256,
              flip=1):
     super(Facades, self).__init__()
     # list all images into a list
     self.image_list = [x for x in listdir(dataPath) if is_image_file(x)]
     self.dataPath = dataPath
     self.loadSize = loadSize
     self.fineSize = fineSize
     self.flip = flip
示例#6
0
    def get_test_data(self):
        data_path = self.config['data_path'] + self.config['test_path']
        files_list = [
            join(data_path, x) for x in sorted(listdir(data_path))
            if is_image_file(x)
        ]
        img_list = []
        # TODO: use scipy.misc when tuning, finally use imresize for matlab-like bicubic performance
        for file in files_list:
            img = io.imread(file)
            if img.shape[2] == 4:
                img = color.rgba2rgb(img)
            img_ycbcr = color.rgb2ycbcr(img) / 255
            img_ycbcr = img_ycbcr.astype('float32')
            (rows, cols, channel) = img_ycbcr.shape
            img_y, img_cb, img_cr = np.split(img_ycbcr,
                                             indices_or_sections=channel,
                                             axis=2)
            size_lr = (int(rows // self.config['upscale']),
                       int(cols // self.config['upscale']))

            # img_y_lr = cv2.resize(img_y.squeeze(), dsize=(int(cols // self.config['upscale']), int(rows // self.config['upscale'])),
            #                      interpolation=cv2.INTER_CUBIC)
            # img_y_lr = misc.imresize(img_y.squeeze(), size=size_lr, interp='bicubic', mode='F')
            img_y_lr = imresize(img_y.squeeze(), output_shape=size_lr)
            img_cb = imresize(img_cb.squeeze(), output_shape=size_lr)
            img_cr = imresize(img_cr.squeeze(), output_shape=size_lr)
            img = imresize(img, output_shape=size_lr)

            # import matplotlib.pyplot as plt
            # plt.imshow(img_y_lr, cmap ='gray')
            # plt.show()

            img_bundle = {
                'name': os.path.basename(file),
                'origin': img,
                'x': img_y_lr,
                'y': img_ycbcr,
                'cb': img_cb.squeeze(),
                'cr': img_cr.squeeze(),
                'size': img_ycbcr.shape[0:-1]
            }
            # img_bundle = {'name': os.path.basename(file), 'x': img_y_lr, 'y': img_y, 'cb': img_cb.squeeze(),
            #               'cr': img_cr.squeeze(),
            #               'size': size_lr}
            img_list.append(img_bundle)

        return img_list
示例#7
0
    def __init__(self, image_dir, is_gray=False, preload=False):
        super(SampleLoader, self).__init__()

        self.image_filenames = []
        self.preload = preload

        all_files = os.walk(image_dir)
        for path, dir_list, file_list in all_files:
            self.image_filenames.extend(
                join(path, x) for x in file_list if is_image_file(x))
        if self.preload:
            self.image_list = []
            for file in self.image_filenames:
                img = Image.open(file).convert('RGB')
                self.image_list.append(img)

        self.is_gray = is_gray