I am trying to apply a mask (binary, only one channel) to an RGB image (3 channels normalized to [0, 1]). My current solution is that I split the RGB image into it, multiply it by the mask, and combine these channels again:
with tf.variable_scope('apply_mask') as scope:
zero_one_mask = (output_mask + 1) / 2
channels = tf.split(3, 3, output_img)
channels = [tf.mul(c, zero_one_mask) for c in channels]
output_img = tf.concat(3, channels)
However, this seems rather inefficient, especially since, in my opinion, none of these calculations are performed in place. Is there a more efficient way to do this?
source
share