Convert RGBA-image to black and white image in Tensorflow -


tf.image.decode_png() can output grayscale, rgb , rgba image.

but i'd convert rgba pure black , white in tensorflow (without using pillow).

please give me advice.

use tf.select thresholding

pil_image = pilimage.open('/temp/panda.png') show_pil_image(pil_image) 

enter image description here

pil_buf = open('/temp/panda.png').read() contents = tf.placeholder(dtype=tf.string) decode_op = tf.image.decode_png(contents, channels=1) gray_image = tf.squeeze(decode_op) # shape (127,127,1) -> shape (127,127) sess = create_session() [decoded] = sess.run([gray_image], feed_dict={contents: pil_buf}) show_pil_image(pilimage.fromarray(decoded)) 

enter image description here

contents = tf.placeholder(dtype=tf.string) decode_op = tf.image.decode_png(contents, channels=1) gray_image = tf.squeeze(decode_op) # shape (127,127,1) -> shape (127,127) select_op = tf.select(gray_image>127, 255*tf.ones_like(gray_image), tf.zeros_like(gray_image)) sess = create_session() [decoded] = sess.run([select_op], feed_dict={contents: pil_buf}) show_pil_image(pilimage.fromarray(decoded)) 

enter image description here


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -