shithub: libvpx

Download patch

ref: 6db96a7f9ca9e569b87720af1c97a231049b2d11
parent: ff36b9c78b8a069978c7ba57c31a8b63fbf8b599
author: Jingning Han <jingning@google.com>
date: Tue Mar 5 07:14:40 EST 2019

Add normalization over frame level Wiener variance

Normalize the block level Wiener variance based decision according
to the frame level Wiener variance.

Change-Id: Ic2bdf1b322a65661775541dd6c174ba71579461a

--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -4732,7 +4732,7 @@
   DECLARE_ALIGNED(16, int16_t, src_diff[32 * 32]);
   DECLARE_ALIGNED(16, tran_low_t, coeff[32 * 32]);
 
-  int mb_row, mb_col;
+  int mb_row, mb_col, count = 0;
   // Hard coded operating block size
   const int block_size = 16;
   const int coeff_count = block_size * block_size;
@@ -4749,6 +4749,8 @@
 
   memset(zero_pred, 0, sizeof(*zero_pred) * coeff_count);
 
+  cpi->norm_wiener_variance = 0;
+
   for (mb_row = 0; mb_row < cm->mb_rows; ++mb_row) {
     for (mb_col = 0; mb_col < cm->mb_cols; ++mb_col) {
       int idx, hist_count = 0;
@@ -4789,18 +4791,21 @@
 
       // Wiener filter
       for (idx = 1; idx < coeff_count; ++idx) {
-        int sign = coeff[idx] < 0;
         int64_t sqr_coeff = (int64_t)coeff[idx] * coeff[idx];
         coeff[idx] = (int16_t)((sqr_coeff * coeff[idx]) /
                                (sqr_coeff + (int64_t)median_val * median_val));
-        if (sign) coeff[idx] = -coeff[idx];
-
         wiener_variance += (int64_t)coeff[idx] * coeff[idx];
       }
       cpi->mb_wiener_variance[mb_row * cm->mb_cols + mb_col] =
           wiener_variance / coeff_count;
+      cpi->norm_wiener_variance +=
+          cpi->mb_wiener_variance[mb_row * cm->mb_cols + mb_col];
+      ++count;
     }
   }
+
+  if (count) cpi->norm_wiener_variance /= count;
+  cpi->norm_wiener_variance = VPXMAX(1, cpi->norm_wiener_variance);
 }
 
 static void encode_frame_to_data_rate(VP9_COMP *cpi, size_t *size,
--- a/vp9/encoder/vp9_encoder.h
+++ b/vp9/encoder/vp9_encoder.h
@@ -628,6 +628,7 @@
   int ext_refresh_frame_context_pending;
   int ext_refresh_frame_context;
 
+  int64_t norm_wiener_variance;
   int64_t *mb_wiener_variance;
   int *stack_rank_buffer;