forked from RaphaelMeudec/deblur-gan
-
Notifications
You must be signed in to change notification settings - Fork 1
/
deblur_image.py
36 lines (28 loc) · 979 Bytes
/
deblur_image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import numpy as np
from PIL import Image
import click
from model import generator_model
from utils import load_image, deprocess_image, preprocess_image
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)
@click.command()
@click.option('--image_path', help='Image to deblur')
def deblur_command(image_path):
return deblur(image_path)
if __name__ == "__main__":
deblur_command()