MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ssim

Function ssim

tensorflow/python/ops/image_ops_impl.py:3307–3378  ·  view source on GitHub ↗

Computes SSIM index between img1 and img2. This function is based on the standard SSIM implementation from: Wang, Z., Bovik, A. C., Sheikh, H. R., & Simoncelli, E. P. (2004). Image quality assessment: from error visibility to structural similarity. IEEE transactions on image processing.

(img1,
         img2,
         max_val,
         filter_size=11,
         filter_sigma=1.5,
         k1=0.01,
         k2=0.03)

Source from the content-addressed store, hash-verified

3305
3306@tf_export('image.ssim')
3307def ssim(img1,
3308 img2,
3309 max_val,
3310 filter_size=11,
3311 filter_sigma=1.5,
3312 k1=0.01,
3313 k2=0.03):
3314 """Computes SSIM index between img1 and img2.
3315
3316 This function is based on the standard SSIM implementation from:
3317 Wang, Z., Bovik, A. C., Sheikh, H. R., & Simoncelli, E. P. (2004). Image
3318 quality assessment: from error visibility to structural similarity. IEEE
3319 transactions on image processing.
3320
3321 Note: The true SSIM is only defined on grayscale. This function does not
3322 perform any colorspace transform. (If input is already YUV, then it will
3323 compute YUV SSIM average.)
3324
3325 Details:
3326 - 11x11 Gaussian filter of width 1.5 is used.
3327 - k1 = 0.01, k2 = 0.03 as in the original paper.
3328
3329 The image sizes must be at least 11x11 because of the filter size.
3330
3331 Example:
3332
3333 ```python
3334 # Read images from file.
3335 im1 = tf.decode_png('path/to/im1.png')
3336 im2 = tf.decode_png('path/to/im2.png')
3337 # Compute SSIM over tf.uint8 Tensors.
3338 ssim1 = tf.image.ssim(im1, im2, max_val=255, filter_size=11,
3339 filter_sigma=1.5, k1=0.01, k2=0.03)
3340
3341 # Compute SSIM over tf.float32 Tensors.
3342 im1 = tf.image.convert_image_dtype(im1, tf.float32)
3343 im2 = tf.image.convert_image_dtype(im2, tf.float32)
3344 ssim2 = tf.image.ssim(im1, im2, max_val=1.0, filter_size=11,
3345 filter_sigma=1.5, k1=0.01, k2=0.03)
3346 # ssim1 and ssim2 both have type tf.float32 and are almost equal.
3347 ```
3348
3349 Args:
3350 img1: First image batch.
3351 img2: Second image batch.
3352 max_val: The dynamic range of the images (i.e., the difference between the
3353 maximum the and minimum allowed values).
3354 filter_size: Default value 11 (size of gaussian filter).
3355 filter_sigma: Default value 1.5 (width of gaussian filter).
3356 k1: Default value 0.01
3357 k2: Default value 0.03 (SSIM is less sensitivity to K2 for lower values, so
3358 it would be better if we taken the values in range of 0< K2 <0.4).
3359
3360 Returns:
3361 A tensor containing an SSIM value for each image in batch. Returned SSIM
3362 values are in range (-1, 1], when pixel values are non-negative. Returns
3363 a tensor with shape: broadcast(img1.shape[:-3], img2.shape[:-3]).
3364 """

Callers

nothing calls this directly

Calls 7

convert_image_dtypeFunction · 0.85
_ssim_per_channelFunction · 0.85
reduce_meanMethod · 0.80
control_dependenciesMethod · 0.45
identityMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected