How to use the tf.image.SSIM function

Hello, can anyone please help me understand how to use this SSIM function (tf.image.ssim  |  TensorFlow v2.16.1)? The filter_size parameter has a default value of 11, according to the documentation information, “the image sizes must be at least 11x11 because of the filter size.” If I then use an image of size 8x11, how should I adjust this, and if applicable, other function parameters? Thanks.

Hi @marcocintra ,

The filter_size parameter is responsible for defining the size of the Gaussian filter used in the SSIM computation. If your image size is 8x11, you need to set filter_size to a value smaller than or equal to the smallest dimension of your image, which in this case is 8.
Here’s the complete code

import tensorflow as tf

# Generate two random images of size 8x11
img1 = tf.random.uniform(shape=(8, 11, 3), minval=0, maxval=1)
img2 = tf.random.uniform(shape=(8, 11, 3), minval=0, maxval=1)

# Compute SSIM with adjusted filter_size
ssim_value = tf.image.ssim(img1, img2, max_val=1.0, filter_size=8)
print("SSIM:", ssim_value.numpy())

Thank you !