Exemple #1
0
 def __init__(self,
              canvas=None,
              trajectory=None,
              fraction=None,
              path_to_save=None,
              max_len=60):
     if canvas is None:
         self.canvas = (canvas, canvas)
     else:
         self.canvas = (canvas, canvas)
     if trajectory is None:
         self.trajectory = Trajectory(canvas=canvas,
                                      expl=0.005,
                                      max_len=max_len).fit(show=False,
                                                           save=False)
     else:
         self.trajectory = trajectory.x
     if fraction is None:
         self.fraction = [1 / 2, 1]
     else:
         self.fraction = fraction
     self.path_to_save = path_to_save
     self.PSFnumber = len(self.fraction)
     self.iters = len(self.trajectory)
     self.PSFs = []
def blur(args):

    # Unpack args
    img_path, folder_in, folder_out, canvas_size = args  #Crank the canvas_size value for more blur!!!
    print(img_path)

    # Blur images
    params = [0.01, 0.009, 0.008, 0.007, 0.005, 0.003]
    trajectory = Trajectory(
        canvas=canvas_size, expl=np.random.choice(params)
    ).fit(
        show=True
    )  #UPDATED: I removed the max_len parameter.  It is now a function of canvas size. I wanted it to scale without having people think about it. -David 2

    psf = PSF(canvas=canvas_size, trajectory=trajectory).fit()

    BlurImage(
        os.path.join(folder_in, img_path),
        PSFs=psf,
        path__to_save=folder_out,
        part=np.random.choice([1, 2, 3])).\
            blur_image(save=True)
Exemple #3
0
 def __init__(self,
              canvas=None,
              trajectory=None,
              fraction=None,
              path_to_save=None):
     if canvas is None:
         self.canvas = (canvas, canvas)
     else:
         self.canvas = (canvas, canvas)
     if trajectory is None:
         self.trajectory = Trajectory(canvas=canvas,
                                      expl=0.005).fit(show=False,
                                                      save=False)
     else:
         self.trajectory = trajectory.x
     if fraction is None:
         self.fraction = [1]  #[1/100, 1/20, 1/10, 1/5, 1/2, 1/1.5, 1]
     else:
         self.fraction = fraction
     self.path_to_save = path_to_save
     self.PSFnumber = len(self.fraction)  #the original code
     #print(self.PSFnumber)
     self.iters = len(self.trajectory)
     self.PSFs = []
Exemple #4
0
                for i in range(len(self.result)):
                        axes[i].imshow(self.result[i])
            else:
                plt.axis('off')

                plt.imshow(self.result[0])
            if show and 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)
                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 = '/home/ubuntu/Downloads/DeblurGAN/datasets/trainB'
    folder_to_save = '/home/ubuntu/Downloads/DeblurGAN/datasets/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)
Exemple #5
0
 for i in range(record_num):
     tfrecord_name = path_to_save + "N%05d.tfrecord" % (i + 1 +
                                                        record_start_cnt)
     writer = tf.python_io.TFRecordWriter(tfrecord_name)
     for j in range(min(number - example_num * i, example_num)):
         params = [0.03, 0.009, 0.008, 0.007, 0.005, 0.004]
         max_len = np.random.choice(np.arange(1, 31),
                                    p=[
                                        0.02, 0.02, 0.02, 0.02, 0.02, 0.02,
                                        0.02, 0.02, 0.02, 0.02, 0.02, 0.02,
                                        0.02, 0.02, 0.02, 0.02, 0.02, 0.02,
                                        0.02, 0.02, 0.06, 0.06, 0.06, 0.06,
                                        0.06, 0.06, 0.06, 0.06, 0.06, 0.06
                                    ])
         trajectory = Trajectory(
             canvas=32, max_len=max_len, expl=np.random.choice(
                 params)).fit()  #60#np.random.randint(3,15)
         psf = PSF(canvas=32,
                   trajectory=trajectory,
                   path_to_save=path_to_save).fit(show=False, save=False)
         #print(np.sum(psf[0]))
         psfchoice = 0  #np.random.choice(np.arange(7))
         cv2.normalize(
             psf[psfchoice], psf[psfchoice], 1.0, 0.0, cv2.NORM_L1
         )  #, alpha=0, beta=1, norm_type=cv2.NORM_MINMAX)#NORM_MINMAX
         #print(psf[2].shape)
         #print(psf[0])
         #print(np.sum(psf[psfchoice]))
         print("process %d in %d" % (example_num * i + j, number))
         psf_bytes = (psf[psfchoice]).tobytes()
         example = gen_example_v0([psf_bytes], shape=(32, 32), psf_num=1)