Reputation: 411
I am using Keras with Tensorflow backend and want to evaluate the PSNR between two images. I am able to evaluate on all three RGB channels, like this:
def psnr(hr, sr):
return tf.image.psnr(hr, sr, max_val=255)
with the psnr function from tensorflow (tf.image.psnr
But what would I do to only evaluate on the first channel? I assume I need to extract those values from the tensor some how. In python it is usually possible to do something like hr[:, 0, 0], but this obviously does not work here.
Upvotes: 0
Views: 1657
Reputation: 16906
im1 = tf.image.convert_image_dtype(np.random.randn(64,64,3), tf.float32)
im2 = tf.image.convert_image_dtype(np.random.randn(64,64,3), tf.float32)
psnr = tf.image.psnr(tf.expand_dims(im1[:,:,0], 2),
tf.expand_dims(im2[:,:,0], 2), max_val=255)
with tf.Session() as sess:
print (sess.run(psnr))
Get the first channel using im1[:,:,0]
and reshape it to h x w x 1
by adding the one channel using expand_dims
Upvotes: 1