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

Function ssim_multiscale

tensorflow/python/ops/image_ops_impl.py:3386–3509  ·  view source on GitHub ↗

Computes the MS-SSIM between img1 and img2. This function assumes that `img1` and `img2` are image batches, i.e. the last three dimensions are [height, width, channels]. Note: The true SSIM is only defined on grayscale. This function does not perform any colorspace transform. (If input i

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

Source from the content-addressed store, hash-verified

3384
3385@tf_export('image.ssim_multiscale')
3386def ssim_multiscale(img1,
3387 img2,
3388 max_val,
3389 power_factors=_MSSSIM_WEIGHTS,
3390 filter_size=11,
3391 filter_sigma=1.5,
3392 k1=0.01,
3393 k2=0.03):
3394 """Computes the MS-SSIM between img1 and img2.
3395
3396 This function assumes that `img1` and `img2` are image batches, i.e. the last
3397 three dimensions are [height, width, channels].
3398
3399 Note: The true SSIM is only defined on grayscale. This function does not
3400 perform any colorspace transform. (If input is already YUV, then it will
3401 compute YUV SSIM average.)
3402
3403 Original paper: Wang, Zhou, Eero P. Simoncelli, and Alan C. Bovik. "Multiscale
3404 structural similarity for image quality assessment." Signals, Systems and
3405 Computers, 2004.
3406
3407 Arguments:
3408 img1: First image batch.
3409 img2: Second image batch. Must have the same rank as img1.
3410 max_val: The dynamic range of the images (i.e., the difference between the
3411 maximum the and minimum allowed values).
3412 power_factors: Iterable of weights for each of the scales. The number of
3413 scales used is the length of the list. Index 0 is the unscaled
3414 resolution's weight and each increasing scale corresponds to the image
3415 being downsampled by 2. Defaults to (0.0448, 0.2856, 0.3001, 0.2363,
3416 0.1333), which are the values obtained in the original paper.
3417 filter_size: Default value 11 (size of gaussian filter).
3418 filter_sigma: Default value 1.5 (width of gaussian filter).
3419 k1: Default value 0.01
3420 k2: Default value 0.03 (SSIM is less sensitivity to K2 for lower values, so
3421 it would be better if we taken the values in range of 0< K2 <0.4).
3422
3423 Returns:
3424 A tensor containing an MS-SSIM value for each image in batch. The values
3425 are in range [0, 1]. Returns a tensor with shape:
3426 broadcast(img1.shape[:-3], img2.shape[:-3]).
3427 """
3428 with ops.name_scope(None, 'MS-SSIM', [img1, img2]):
3429 # Convert to tensor if needed.
3430 img1 = ops.convert_to_tensor(img1, name='img1')
3431 img2 = ops.convert_to_tensor(img2, name='img2')
3432 # Shape checking.
3433 shape1, shape2, checks = _verify_compatible_image_shapes(img1, img2)
3434 with ops.control_dependencies(checks):
3435 img1 = array_ops.identity(img1)
3436
3437 # Need to convert the images to float32. Scale max_val accordingly so that
3438 # SSIM is computed correctly.
3439 max_val = math_ops.cast(max_val, img1.dtype)
3440 max_val = convert_image_dtype(max_val, dtypes.float32)
3441 img1 = convert_image_dtype(img1, dtypes.float32)
3442 img2 = convert_image_dtype(img2, dtypes.float32)
3443

Callers

nothing calls this directly

Calls 15

convert_image_dtypeFunction · 0.85
do_padFunction · 0.85
_ssim_per_channelFunction · 0.85
reshapeMethod · 0.80
not_equalMethod · 0.80
reduce_meanMethod · 0.80
rangeFunction · 0.70
name_scopeMethod · 0.45
control_dependenciesMethod · 0.45
identityMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected