2017-01-19 4 views
2

모든 입력 이미지에 입력 이미지와 동일한 크기의 마스크를 곱하고 싶습니다. 어떻게하면 텐톨 플로우에서 그렇게 할 수 있을까요?tensorflow에서 입력 이미지에 마스크를 곱하는 방법은 무엇입니까?

내 이미지 읽기 기능은 지금까지 다음과 같습니다

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) 

가 가능합니까? img가 이미 텐서 오브젝트인지 확실하지 않아이 함수를 사용할 수 있습니다. 나는 tensorflow에 익숙하지 않다 ...

+1

당신은 단순히 '마스크 = tf.constant (1.0, DTYPE = tf.float32, 모양 = img.get_shape을 수행 할 수 있습니다())' 'img_masked = img * mask' – keveman

답변

0

다음은 나를 위해 잘 작동하는 코드이다. jupyter 노트북을 사용하여 코드를 실행합니다.

또한
%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() 

는 여기 TF와 좋은 유튜브 튜토리얼 커버 이미지 조작이다 : https://www.youtube.com/watch?v=bvHgESVuS6Q&t=447s

관련 문제