2017-01-19 5 views
2

Ich möchte jedes Eingabebild mit einer Maske der gleichen Größe wie das Eingabebild multiplizieren. Wie würde ich das im Tensorflow machen?Wie multipliziert man Eingangsbilder mit Maske im Tensorflow?

sieht Meine Bildlesefunktion wie dies bisher:

img_contents = tf.read_file(input_queue[0]) 
label_contents = tf.read_file(input_queue[1]) 
img = tf.image.decode_png(img_contents, channels=3) 
label = tf.image.decode_png(label_contents, channels=1) 

# Now I want to do something like this? 
mask = tf.constant(1.0, dtype=tf.float32, shape=img.shape) 
img_masked = tf.multiply(img,mask) 

ist das möglich? Nicht sicher, ob img bereits ein Tensor-Objekt ist und ich diese Funktion hier verwenden kann. Ich bin neu in Tensorflow ...

+1

Sie einfach tun kann, 'mask = tf.constant (1,0, dtype = tf.float32, Form = img.get_shape()) ' ' img_masked = img * maske' – keveman

Antwort

0

Hier ist der Code, der gut für mich funktioniert. Ich verwende jupyter Notebook, um den Code auszuführen.

%matplotlib inline 
import tensorflow as tf 
from matplotlib.image import imread 
import matplotlib.pyplot as plt 

# Loading test image from the local filesystem 
x = tf.Variable(imread("test_img.jpg"),dtype='float32') 
x_mask = tf.Variable(imread("test_mask.jpg"),dtype='float32') 
img_mult = tf.multiply(x,x_mask) 

plt.imshow(imread("test_img.jpg")) 
plt.show() 
plt.imshow(imread("test_mask.jpg")) 
plt.show() 

sess = tf.Session() 
sess.run(tf.global_variables_initializer()) 
res = sess.run(img_mult) 

plt.imshow(res) 
plt.show() 

Auch ist hier eine gute Tutorial YouTube Abdeckung Bildbearbeitung mit TF: https://www.youtube.com/watch?v=bvHgESVuS6Q&t=447s

Verwandte Themen