tfmri.image.ssim

ssim(img1, img2, max_val=None, filter_size=11, filter_sigma=1.5, k1=0.01, k2=0.03, batch_dims=None, image_dims=None, rank=None, name='ssim')

Computes the structural similarity index (SSIM) between two N-D images. (deprecated arguments)

Deprecated: SOME ARGUMENTS ARE DEPRECATED: (rank). They will be removed after 2022-09-01. Instructions for updating: Use argument image_dims instead.

This function operates on batches of multi-channel inputs and returns an SSIM value for each image in the batch.

Parameters
  • img1 – A Tensor. First batch of images. For 2D images, must have rank >= 3 with shape batch_shape + [height, width, channels]. For 3D images, must have rank >= 4 with shape batch_shape + [depth, height, width, channels]. height, width and depth must be greater than or equal to filter_size. Can have integer or floating point type, with values in the range [0, max_val].

  • img2 – A Tensor. Second batch of images. For 2D images, must have rank >= 3 with shape batch_shape + [height, width, channels]. For 3D images, must have rank >= 4 with shape batch_shape + [depth, height, width, channels]. height, width and depth must be greater than or equal to filter_size. Can have integer or floating point type, with values in the range [0, max_val].

  • max_val – The dynamic range of the images (i.e., the difference between the maximum and the minimum allowed values). Defaults to 1 for floating point input images and MAX for integer input images, where MAX is the largest positive representable number for the data type.

  • filter_size – The size of the Gaussian filter. Defaults to 11.

  • filter_sigma – The standard deviation of the Gaussian filter. Defaults to 1.5.

  • k1 – Factor used to calculate the regularization constant for the luminance term, as C1 = (k1 * max_val) ** 2. Defaults to 0.01.

  • k2 – Factor used to calculate the regularization constant for the contrast term, as C2 = (k2 * max_val) ** 2. Defaults to 0.03.

  • batch_dims

    An int. The number of batch dimensions in input images. If None, it is inferred from inputs and image_dims as (rank of inputs) - image_dims - 1. If image_dims is also None, then batch_dims defaults to 1. batch_dims can always be inferred if image_dims was specified, so you only need to provide one of the two.

  • image_dims

    An int. The number of spatial dimensions in input images. If None, it is inferred from inputs and batch_dims as (rank of inputs) - batch_dims - 1. Defaults to None. image_dims can always be inferred if batch_dims was specified, so you only need to provide one of the two.

  • rank

    An int. The number of spatial dimensions. Must be 2 or 3. Defaults to tf.rank(img1) - 2. In other words, if rank is not explicitly set, img1 and img2 should have shape [batch, height, width, channels] if processing 2D images or [batch, depth, height, width, channels] if processing 3D images.

  • name – Namespace to embed the computation in.

Returns

A Tensor of type float32 and shape batch_shape containing an SSIM value for each image in the batch.

References

1

Zhou Wang, A. C. Bovik, H. R. Sheikh and E. P. Simoncelli, “Image quality assessment: from error visibility to structural similarity,” in IEEE Transactions on Image Processing, vol. 13, no. 4, pp. 600-612, April 2004, doi: 10.1109/TIP.2003.819861.