Exemplo n.º 1
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,max_len=canvas*0.8, expl=0.003).fit(show=False, save=False).x
     else:
         self.trajectory = trajectory.x
     if fraction is None:
         self.fraction = [1/100, 1/10, 1/2, 1]
         #self.fraction = [1 , 1 , 1 , 1]
     else:
         self.fraction = fraction
     self.path_to_save = path_to_save
     self.PSFnumber = len(self.fraction)
     self.iters = len(self.trajectory)
     self.PSFs = []
Exemplo n.º 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)
Exemplo n.º 3
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 = './sharp'
    folder_to_save = './blured'
    #    params = [0.5, 0.9, 0.8, 0.7, 0.5, 3]
    params = 3
    for path in os.listdir(folder):
        print(path)
        #        trajectory = Trajectory(canvas=64, max_len=200, expl=np.random.choice(params)).fit()
        trajectory = Trajectory(canvas=32, max_len=200, expl=3).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)
Exemplo n.º 4
0
    ax = fig.gca(projection='3d')
    # ax.plot_wireframe(X,Y,kernel,color='c')
    # plt.show()
    # 曲面,x,y,z坐标,横向步长,纵向步长,颜色,线宽,是否渐变
    # cm.coolwarm
    surf = ax.plot_surface(X, Y, kernel, rstride=1, cstride=1, cmap='plasma', edgecolor='none')
    plt.show()


if __name__ == '__main__':
    can = 15
    motion_blur_list = []
    params = [0.01, 0.009, 0.008, 0.007,0.006, 0.005,0.004, 0.003,0.002]
    for p in params:
        for i in range(10):
            trajectory = Trajectory(canvas=can, max_len=can*0.8, expl=p).fit()
            psf = PSF(canvas=can, trajectory=trajectory).fit()
            motion_blur_list.append(np.reshape(psf[3],(1,can,can)))
        print("w")

    motion_blur_list = np.concatenate(motion_blur_list,axis=0)
    print(motion_blur_list.shape)
    save_path = "motion_blur_kernel.npy"
    np.save(save_path,motion_blur_list)


'''
    img  = Image.open('0001.png')
    #img.show()
    img = Image.fromarray(convolve(img, np.reshape(psf.PSFs[3],(can,can,1)), mode='nearest'))
    img.show()
Exemplo n.º 5
0
                    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'
    folder = '/Users/apple/Desktop/research_summer/MSKCC_deblur/image/sharp'
    folder_to_save = '/Users/apple/Desktop/research_summer/MSKCC_deblur/image/blur'
    if not os.path.exists(folder_to_save):
        os.makedirs(folder_to_save)
    #params = [0.01, 0.009, 0.008, 0.007, 0.005, 0.003]
    #params=[0.2,0.15,0.1,0.07,0.05,0.03,0.01,0.007,0.005]
    params = [0.2, 0.17, 0.15, 0.13, 0.1, 0.07, 0.05, 0.03, 0.01,
              0.007]  #Usual tasks (first 8437 pairs)
    #params=[0.3,0.25,0.2,0.17,0.15,0.13,0.1,0.07,0.05,0.01] #for the brain images, easier.
    #for path in os.listdir(folder):
    for path in os.listdir(folder)[:]:
        print(path)
        expl = np.random.choice(params)
        trajectory = Trajectory(canvas=64, max_len=60, expl=expl).fit()
        print(expl)
        psf = PSF(canvas=64, trajectory=trajectory).fit()
        #part=np.random.choice([1,2,3])
        part = 3
        print(part)
        BlurImage(os.path.join(folder, path), PSFs=psf,
                  path__to_save=folder_to_save, part=part).\
            blur_image(save=True)