예제 #1
0
def deblur(weight_path, input_dir, output_dir):
    g = generator_model()
    g.load_weights(weight_path)
    for image_name in os.listdir(input_dir):
        image = np.array([preprocess_image(load_image(os.path.join(input_dir, image_name)))])
        x_test = image
        generated_images = g.predict(x=x_test)
        generated = np.array([deprocess_image(img) for img in generated_images])
        x_test = deprocess_image(x_test)
        for i in range(generated_images.shape[0]):
            x = x_test[i, :, :, :]
            img = generated[i, :, :, :]
            output = np.concatenate((x, img), axis=1)
            im = Image.fromarray(output.astype(np.uint8))
            im.save(os.path.join(output_dir, image_name))
예제 #2
0
def deblur(image_path):
    data = {
        'A_paths': [image_path],
        'A': np.array([preprocess_image(load_image(image_path))])
    }
    x_test = data['A']
    g = generator_model()
    g.load_weights('generator.h5')
    generated_images = g.predict(x=x_test)
    generated = np.array([deprocess_image(img) for img in generated_images])
    x_test = deprocess_image(x_test)

    for i in range(generated_images.shape[0]):
        x = x_test[i, :, :, :]
        img = generated[i, :, :, :]
        output = np.concatenate((x, img), axis=1)
        im = Image.fromarray(output.astype(np.uint8))
        im.save('deblur'+image_path)
예제 #3
0
 def deblurOne(self, imageByte: bytes):
     image = np.array([preprocess_image(Image.open(io.BytesIO(imageByte)))])
     try:
         image = np.delete(image, 3, 3)
     except:
         pass
     x_test = image
     with self.graph.as_default():
         generated_images = self.g.predict(x=x_test)
     generated = np.array([deprocess_image(img) for img in generated_images])
     x_test = deprocess_image(x_test)
     for i in range(generated_images.shape[0]):
         img = generated[i, :, :, :]
         im = Image.fromarray(img.astype(np.uint8))
         output = io.BytesIO()
         im.save(output, format="JPEG")
         output.seek(0)
         return output
def DeBlur_GAN_Decomposition():
    st.subheader("GAN based Blur removal")
    g = generator_model()
    g.load_weights(dblur_weight_path)
    img_file_buffer = st.file_uploader("Upload an image",
                                       type=["jpg"])  #"png", "jpg", "jpeg",
    if img_file_buffer is not None:
        sample_image = Image.open(img_file_buffer)
        image_resize = sample_image.resize((256, 256))
        #st.write(type(image_resize), image_resize.size)
        image_in = np.array([preprocess_image(image_resize)])
        #st.write(image_in.shape)
        x_test = image_in
        generated_images = g.predict(x=x_test)
        generated = np.array(
            [deprocess_image(img) for img in generated_images])
        x_test = deprocess_image(x_test)
        #st.write("generated images size:", generated_images.shape)
        for i in range(generated_images.shape[0]):
            x = x_test[i, :, :, :]
            img = generated[i, :, :, :]
            #output = np.concatenate((x, img), axis=1)
            im = Image.fromarray(img.astype(np.uint8))

        with st.spinner('Enhancing Image...'):
            # Display
            plt.figure(figsize=(25, 20))
            plt.subplot(121)
            plt.title('Original Image')
            plt.axis('off')
            plt.imshow(image_resize)

            plt.subplot(122)
            plt.title('Final Image')
            plt.axis('off')
            plt.imshow(im)
            st.pyplot()
            time.sleep(10)