(x, y, reducer, max_val, compensation=1.0)
return luminance, cs
r"""Helper function to SSIM.

  SSIM estimates covariances with weighted sums, e.g., normalized Gaussian blur.
  Like the unbiased covariance estimator has normalization factor of n-1 instead
  of n, naive covariance estimations with weighted sums are biased estimators.
  Suppose `reducer` is a weighted sum, then the mean estimators are
    mu_x = \sum_i w_i x_i,
    mu_y = \sum_i w_i y_i,
  where w_i's are the weighted-sum weights, and covariance estimator is
    cov_xy = \sum_i w_i (x_i - mu_x) (y_i - mu_y)
  with assumption \sum_i w_i = 1. This covariance estimator is biased, since
    E cov_xy = (1 - \sum_i w_i ** 2) Cov(X, Y).
  For SSIM measure with unbiased covariance estimators, pass as `compensation`
  argument (1 - \sum_i w_i ** 2).

  Arguments:
    x: first set of images.
    y: first set of images.
    reducer: Function that computes 'local' averages from set of images.
      For non-covolutional version, this is usually tf.reduce_mean(x, [1, 2]),
      and for convolutional version, this is usually tf.nn.avg_pool or
      tf.nn.conv2d with weighted-sum kernel.
    max_val: The dynamic range (i.e., the difference between the maximum
      possible allowed value and the minimum allowed value).
    compensation: Compensation factor. See above.

  Returns:
    A pair containing the luminance measure and the contrast-structure measure.
r"""Helper function to SSIM.
r Helper function to SSIM .
def _ssim_helper(x, y, reducer, max_val, compensation=1.0):
  r"""Helper function to SSIM.

  SSIM estimates covariances with weighted sums, e.g., normalized Gaussian blur.
  Like the unbiased covariance estimator has normalization factor of n-1 instead
  of n, naive covariance estimations with weighted sums are biased estimators.
  Suppose `reducer` is a weighted sum, then the mean estimators are
    mu_x = \sum_i w_i x_i,
    mu_y = \sum_i w_i y_i,
  where w_i's are the weighted-sum weights, and covariance estimator is
    cov_xy = \sum_i w_i (x_i - mu_x) (y_i - mu_y)
  with assumption \sum_i w_i = 1. This covariance estimator is biased, since
    E cov_xy = (1 - \sum_i w_i ** 2) Cov(X, Y).
  For SSIM measure with unbiased covariance estimators, pass as `compensation`
  argument (1 - \sum_i w_i ** 2).

  Arguments:
    x: first set of images.
    y: first set of images.
    reducer: Function that computes 'local' averages from set of images.
      For non-covolutional version, this is usually tf.reduce_mean(x, [1, 2]),
      and for convolutional version, this is usually tf.nn.avg_pool or
      tf.nn.conv2d with weighted-sum kernel.
    max_val: The dynamic range (i.e., the difference between the maximum
      possible allowed value and the minimum allowed value).
    compensation: Compensation factor. See above.

  Returns:
    A pair containing the luminance measure and the contrast-structure measure.
  """
  c1 = (_SSIM_K1 * max_val) ** 2
  c2 = (_SSIM_K2 * max_val) ** 2

  # SSIM luminance measure is
  # (2 * mu_x * mu_y + c1) / (mu_x ** 2 + mu_y ** 2 + c1).
  mean0 = reducer(x)
  mean1 = reducer(y)
  num0 = mean0 * mean1 * 2.0
  den0 = tf.square(mean0) + tf.square(mean1)
  luminance = (num0 + c1) / (den0 + c1)

  # SSIM contrast-structure measure is
  #   (2 * cov_xy + c2) / (cov_xx + cov_yy + c2).
  # Note that `reducer` is a weighted sum with weight w_k, \sum_i w_i = 1, then
  #   cov_xy = \sum_i w_i (x_i - mu_x) (y_i - mu_y)
  #          = \sum_i w_i x_i y_i - (\sum_i w_i x_i) (\sum_j w_j y_j).
  num1 = reducer(x * y) * 2.0
  den1 = reducer(tf.square(x) + tf.square(y))
  c2 *= compensation
  cs = (num1 - num0 + c2) / (den1 - den0 + c2)

  # SSIM score is the product of the luminance and contrast-structure measures.
  return luminance, cs
def _ssim_helper ( x , y , reducer , max_val , compensation = 1.0 ) : c1 = ( _SSIM_K1 * max_val ) ** 2 c2 = ( _SSIM_K2 * max_val ) ** 2 # SSIM luminance measure is # (2 * mu_x * mu_y + c1) / (mu_x ** 2 + mu_y ** 2 + c1). mean0 = reducer ( x ) mean1 = reducer ( y ) num0 = mean0 * mean1 * 2.0 den0 = tf . square ( mean0 ) + tf . square ( mean1 ) luminance = ( num0 + c1 ) / ( den0 + c1 ) # SSIM contrast-structure measure is #   (2 * cov_xy + c2) / (cov_xx + cov_yy + c2). # Note that `reducer` is a weighted sum with weight w_k, \sum_i w_i = 1, then #   cov_xy = \sum_i w_i (x_i - mu_x) (y_i - mu_y) #          = \sum_i w_i x_i y_i - (\sum_i w_i x_i) (\sum_j w_j y_j). num1 = reducer ( x * y ) * 2.0 den1 = reducer ( tf . square ( x ) + tf . square ( y ) ) c2 *= compensation cs = ( num1 - num0 + c2 ) / ( den1 - den0 + c2 ) # SSIM score is the product of the luminance and contrast-structure measures. return luminance , cs