From 06fce6b640aefffccd06551380520dac9a01660f Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 10 Sep 2014 10:12:45 -0700 Subject: [PATCH] vp8: Update to the adaptive denoising mode. Allow for option to apply spatial blur for temporal denoising, under the aggressive denoising mode. Change-Id: I41c5fdc0b6cf32d8f8d1d4236b25fa5aa406e89e --- vp8/common/postproc.c | 26 ++++++++++++++------------ vp8/common/postproc.h | 3 ++- vp8/encoder/denoising.c | 2 ++ vp8/encoder/denoising.h | 2 ++ vp8/encoder/onyx_if.c | 15 +++++++++++++-- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/vp8/common/postproc.c b/vp8/common/postproc.c index 769c2de6b..277f37194 100644 --- a/vp8/common/postproc.c +++ b/vp8/common/postproc.c @@ -385,13 +385,13 @@ void vp8_deblock(VP8_COMMON *cm, } #endif -#if !(CONFIG_TEMPORAL_DENOISING) void vp8_de_noise(VP8_COMMON *cm, YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *post, int q, int low_var_thresh, - int flag) + int flag, + int uvfilter) { int mbr; double level = 6.0e-05 * q * q * q - .0067 * q * q + .306 * q + .0065; @@ -412,18 +412,20 @@ void vp8_de_noise(VP8_COMMON *cm, source->y_buffer + 16 * mbr * source->y_stride, source->y_buffer + 16 * mbr * source->y_stride, source->y_stride, source->y_stride, source->y_width, limits, 16); - - vp8_post_proc_down_and_across_mb_row( - source->u_buffer + 8 * mbr * source->uv_stride, - source->u_buffer + 8 * mbr * source->uv_stride, - source->uv_stride, source->uv_stride, source->uv_width, limits, 8); - vp8_post_proc_down_and_across_mb_row( - source->v_buffer + 8 * mbr * source->uv_stride, - source->v_buffer + 8 * mbr * source->uv_stride, - source->uv_stride, source->uv_stride, source->uv_width, limits, 8); + if (uvfilter == 1) { + vp8_post_proc_down_and_across_mb_row( + source->u_buffer + 8 * mbr * source->uv_stride, + source->u_buffer + 8 * mbr * source->uv_stride, + source->uv_stride, source->uv_stride, source->uv_width, limits, + 8); + vp8_post_proc_down_and_across_mb_row( + source->v_buffer + 8 * mbr * source->uv_stride, + source->v_buffer + 8 * mbr * source->uv_stride, + source->uv_stride, source->uv_stride, source->uv_width, limits, + 8); + } } } -#endif double vp8_gaussian(double sigma, double mu, double x) { diff --git a/vp8/common/postproc.h b/vp8/common/postproc.h index 33d0a7f02..0fa12a7c6 100644 --- a/vp8/common/postproc.h +++ b/vp8/common/postproc.h @@ -39,7 +39,8 @@ void vp8_de_noise(struct VP8Common *oci, YV12_BUFFER_CONFIG *post, int q, int low_var_thresh, - int flag); + int flag, + int uvfilter); void vp8_deblock(struct VP8Common *oci, YV12_BUFFER_CONFIG *source, diff --git a/vp8/encoder/denoising.c b/vp8/encoder/denoising.c index 2f33d4ace..12f9734a1 100644 --- a/vp8/encoder/denoising.c +++ b/vp8/encoder/denoising.c @@ -384,6 +384,7 @@ void vp8_denoiser_set_parameters(VP8_DENOISER *denoiser, int mode) { denoiser->denoise_pars.pickmode_mv_bias = 100; denoiser->denoise_pars.qp_thresh = 0; denoiser->denoise_pars.consec_zerolast = UINT_MAX; + denoiser->denoise_pars.spatial_blur = 0; } else { denoiser->denoise_pars.scale_sse_thresh = 2; denoiser->denoise_pars.scale_motion_thresh = 16; @@ -392,6 +393,7 @@ void vp8_denoiser_set_parameters(VP8_DENOISER *denoiser, int mode) { denoiser->denoise_pars.pickmode_mv_bias = 60; denoiser->denoise_pars.qp_thresh = 100; denoiser->denoise_pars.consec_zerolast = 10; + denoiser->denoise_pars.spatial_blur = 20; } } diff --git a/vp8/encoder/denoising.h b/vp8/encoder/denoising.h index bb0c2ce8d..fb7930b6b 100644 --- a/vp8/encoder/denoising.h +++ b/vp8/encoder/denoising.h @@ -67,6 +67,8 @@ typedef struct { unsigned int qp_thresh; // Threshold for number of consecutive frames for blocks coded as ZEROMV-LAST. unsigned int consec_zerolast; + // Threshold for amount of spatial blur on Y channel. 0 means no spatial blur. + unsigned int spatial_blur; } denoise_params; typedef struct vp8_denoiser diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c index 791a4858d..d8eff669e 100644 --- a/vp8/encoder/onyx_if.c +++ b/vp8/encoder/onyx_if.c @@ -4023,6 +4023,17 @@ static void encode_frame_to_data_rate scale_and_extend_source(cpi->un_scaled_source, cpi); +#if CONFIG_TEMPORAL_DENOISING && CONFIG_POSTPROC + // Option to apply spatial blur under the aggressive or adaptive + // (temporal denoising) mode. + if (cpi->oxcf.noise_sensitivity >= 3) { + if (cpi->denoiser.denoise_pars.spatial_blur != 0) { + vp8_de_noise(cm, cpi->Source, cpi->Source, + cpi->denoiser.denoise_pars.spatial_blur, 1, 0, 0); + } + } +#endif + #if !(CONFIG_REALTIME_ONLY) && CONFIG_POSTPROC && !(CONFIG_TEMPORAL_DENOISING) if (cpi->oxcf.noise_sensitivity > 0) @@ -4055,11 +4066,11 @@ static void encode_frame_to_data_rate if (cm->frame_type == KEY_FRAME) { - vp8_de_noise(cm, cpi->Source, cpi->Source, l , 1, 0); + vp8_de_noise(cm, cpi->Source, cpi->Source, l , 1, 0, 1); } else { - vp8_de_noise(cm, cpi->Source, cpi->Source, l , 1, 0); + vp8_de_noise(cm, cpi->Source, cpi->Source, l , 1, 0, 1); src = cpi->Source->y_buffer;