예제 #1
0
    def __init__(self, image_path, PSFs=None, part=None, path__to_save=None):
        """

        :param image_path: path to square, RGB image.
        :param PSFs: array of Kernels.
        :param part: int number of kernel to use.
        :param path__to_save: folder to save results.
        """
        if os.path.isfile(image_path):
            self.image_path = image_path
            self.original = misc.imread(self.image_path)
            self.shape = self.original.shape
            if len(self.shape) < 3:
                raise Exception('We support only RGB images yet.')
            elif self.shape[0] != self.shape[1]:
                raise Exception('We support only square images yet.')
        else:
            raise Exception('Not correct path to image.')
        self.path_to_save = path__to_save
        if PSFs is None:
            if self.path_to_save is None:
                self.PSFs = PSF(canvas=self.shape[0]).fit()
            else:
                self.PSFs = PSF(canvas=self.shape[0],
                                path_to_save=os.path.join(
                                    self.path_to_save,
                                    'PSFs.png')).fit(save=True)
        else:
            self.PSFs = PSFs

        self.part = part
        self.result = []
예제 #2
0
                cv2.imwrite(
                    os.path.join(self.path_to_save,
                                 self.image_path.split('/')[-1]),
                    self.result[0] * 255)
                plt.show()
            elif save:
                if self.path_to_save is None:
                    raise Exception(
                        'Please create Trajectory instance with path_to_save')
                cv2.imwrite(
                    os.path.join(self.path_to_save,
                                 self.image_path.split('/')[-1]),
                    self.result[0] * 255)
            elif show:
                plt.show()


if __name__ == '__main__':
    folder = '/Users/mykolam/PycharmProjects/University/DeblurGAN2/results_sharp'
    folder_to_save = '/Users/mykolam/PycharmProjects/University/DeblurGAN2/blured'
    params = [0.01, 0.009, 0.008, 0.007, 0.005, 0.003]
    for path in os.listdir(folder):
        print(path)
        trajectory = Trajectory(canvas=64,
                                max_len=60,
                                expl=np.random.choice(params)).fit()
        psf = PSF(canvas=64, trajectory=trajectory).fit()
        BlurImage(os.path.join(folder, path), PSFs=psf,
                  path__to_save=folder_to_save, part=np.random.choice([1, 2, 3])). \
            blur_image(save=True)