Tensorflow 2d Convolution On Rgb Channels Separately?
I want to apply a Gaussian blur to an RGB image. I want it to be operated on each channel independently. The code below outputs a blurred image with 3 channels but all with the sam
Solution 1:
You can use tf.nn.separable_conv2d
to do that:
import tensorflow as tf
# ...
gauss_kernel_2d = gaussian_kernel(2, 0.0, 1.0) # outputs a 5*5 tensor
gauss_kernel = tf.tile(gauss_kernel_2d[:, :, tf.newaxis, tf.newaxis], [1, 1, 3, 1]) # 5*5*3*1
# Pointwise filter that does nothing
pointwise_filter = tf.eye(3, batch_shape=[1, 1])
image = tf.nn.separable_conv2d(tf.expand_dims(image, 0), gauss_kernel, pointwise_filter,
strides=[1, 1, 1, 1], padding='SAME')
image = tf.squeeze(image) # 600*800*3
Post a Comment for "Tensorflow 2d Convolution On Rgb Channels Separately?"