Skip to content

Commit 0b97008

Browse files
author
Karthikeyan Vasuki Balasubramaniam
committed
Adding PNG Extraction
1 parent 18e35ac commit 0b97008

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/label_png_image.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This script works only for PNG Files
2+
# If you need JPG/JPEG images, the decode
3+
# function has to be changed
4+
#
5+
6+
import tensorflow as tf
7+
import sys
8+
import PIL
9+
from PIL import Image
10+
import numpy as np
11+
12+
image_path = sys.argv[1]
13+
filename_queue = tf.train.string_input_producer([image_path])
14+
reader = tf.WholeFileReader()
15+
key, value = reader.read(filename_queue)
16+
my_img = tf.image.decode_png(value)
17+
init_op = tf.initialize_all_variables()
18+
19+
with tf.Session() as sess:
20+
sess.run(init_op)
21+
coord = tf.train.Coordinator()
22+
threads = tf.train.start_queue_runners(coord=coord)
23+
24+
for i in range(1):
25+
image = my_img.eval()
26+
27+
print(image.shape)
28+
print (PIL.Image.fromarray(np.asarray(image)))
29+
30+
coord.request_stop()
31+
coord.join(threads)
32+

0 commit comments

Comments
 (0)