-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathblur_image.py
45 lines (33 loc) · 1.23 KB
/
blur_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
37
38
39
40
41
42
43
44
45
# vim: sta:et:sw=2:ts=2:sts=2
# Written by Antonio Loquercio
import numpy as np
import tensorflow as tf
from PIL import Image
from smoother import Smoother
# Basic model parameters.
tf.app.flags.DEFINE_string('image_path', './Colosseum_in_Rome,_Italy_-_April_2007.jpg',
"""Path to the image to blur.""")
FLAGS = tf.app.flags.FLAGS
# Basic Constants
SIGMA = 2.0
FILTER_SIZE = 13
def smooth():
Image_Placeholder = tf.placeholder( tf.float32, shape = [1, None, None, 3])
smoother = Smoother({'data':Image_Placeholder}, FILTER_SIZE, SIGMA)
smoothed_image = smoother.get_output()
init = tf.initialize_all_variables()
with tf.Session() as sess:
sess.run(init)
image = Image.open(FLAGS.image_path)
image = np.array(image, dtype = np.float32)
image = image.reshape((1, image.shape[0], image.shape[1], 3))
smoothed = sess.run(smoothed_image,
feed_dict = {Image_Placeholder: image})
smoothed = smoothed / np.max(smoothed)
out_image = np.squeeze(smoothed)
out_image = Image.fromarray(np.squeeze(np.uint8(out_image * 255)))
out_image.show()
def main(argv=None):
smooth()
if __name__ == '__main__':
tf.app.run()