VP9 denoising enabled by noise_sensitivity param
As in VP8. Currently, this parameter is set with the VP8E_SET_NOISE_SENSITIVITY flag. The flag was not renamed so that we don't break the interface for webrtc. This should probably be changed at some point in the future. Change-Id: Ic73fcb0dde9d1d019e9d042050b617333ac65472
This commit is contained in:
@@ -15,6 +15,17 @@
|
|||||||
#include "vp9/common/vp9_reconinter.h"
|
#include "vp9/common/vp9_reconinter.h"
|
||||||
#include "vp9/encoder/vp9_denoiser.h"
|
#include "vp9/encoder/vp9_denoiser.h"
|
||||||
|
|
||||||
|
/* The VP9 denoiser is a work-in-progress. It currently is only designed to work
|
||||||
|
* with speed 6, though it (inexplicably) seems to also work with speed 5 (one
|
||||||
|
* would need to modify the source code in vp9_pickmode.c and vp9_encoder.c to
|
||||||
|
* make the calls to the vp9_denoiser_* functions when in speed 5).
|
||||||
|
*
|
||||||
|
* The implementation is very similar to that of the VP8 denoiser. While
|
||||||
|
* choosing the motion vectors / reference frames, the denoiser is run, and if
|
||||||
|
* it did not modify the signal to much, the denoised block is copied to the
|
||||||
|
* signal.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef OUTPUT_YUV_DENOISED
|
#ifdef OUTPUT_YUV_DENOISED
|
||||||
static void make_grayscale(YV12_BUFFER_CONFIG *yuv);
|
static void make_grayscale(YV12_BUFFER_CONFIG *yuv);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ void vp9_coef_tree_initialize();
|
|||||||
// #define OUTPUT_YUV_REC
|
// #define OUTPUT_YUV_REC
|
||||||
|
|
||||||
#ifdef OUTPUT_YUV_DENOISED
|
#ifdef OUTPUT_YUV_DENOISED
|
||||||
FILE *yuv_denoised_file;
|
FILE *yuv_denoised_file = NULL;
|
||||||
#endif
|
#endif
|
||||||
#ifdef OUTPUT_YUV_SRC
|
#ifdef OUTPUT_YUV_SRC
|
||||||
FILE *yuv_file;
|
FILE *yuv_file;
|
||||||
@@ -657,9 +657,11 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) {
|
|||||||
cpi->ext_refresh_frame_context_pending = 0;
|
cpi->ext_refresh_frame_context_pending = 0;
|
||||||
|
|
||||||
#if CONFIG_DENOISING
|
#if CONFIG_DENOISING
|
||||||
vp9_denoiser_alloc(&(cpi->denoiser), cm->width, cm->height,
|
if (cpi->oxcf.noise_sensitivity > 0) {
|
||||||
cm->subsampling_x, cm->subsampling_y,
|
vp9_denoiser_alloc(&(cpi->denoiser), cm->width, cm->height,
|
||||||
VP9_ENC_BORDER_IN_PIXELS);
|
cm->subsampling_x, cm->subsampling_y,
|
||||||
|
VP9_ENC_BORDER_IN_PIXELS);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -839,8 +841,12 @@ VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf) {
|
|||||||
cpi->mb.nmvsadcost_hp[1] = &cpi->mb.nmvsadcosts_hp[1][MV_MAX];
|
cpi->mb.nmvsadcost_hp[1] = &cpi->mb.nmvsadcosts_hp[1][MV_MAX];
|
||||||
cal_nmvsadcosts_hp(cpi->mb.nmvsadcost_hp);
|
cal_nmvsadcosts_hp(cpi->mb.nmvsadcost_hp);
|
||||||
|
|
||||||
|
#if CONFIG_DENOISING
|
||||||
#ifdef OUTPUT_YUV_DENOISED
|
#ifdef OUTPUT_YUV_DENOISED
|
||||||
yuv_denoised_file = fopen("denoised.yuv", "ab");
|
if (cpi->oxcf.noise_sensitivity > 0) {
|
||||||
|
yuv_denoised_file = fopen("denoised.yuv", "ab");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#ifdef OUTPUT_YUV_SRC
|
#ifdef OUTPUT_YUV_SRC
|
||||||
yuv_file = fopen("bd.yuv", "ab");
|
yuv_file = fopen("bd.yuv", "ab");
|
||||||
@@ -1079,7 +1085,9 @@ void vp9_remove_compressor(VP9_COMP *cpi) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if CONFIG_DENOISING
|
#if CONFIG_DENOISING
|
||||||
vp9_denoiser_free(&(cpi->denoiser));
|
if (cpi->oxcf.noise_sensitivity > 0) {
|
||||||
|
vp9_denoiser_free(&(cpi->denoiser));
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dealloc_compressor_data(cpi);
|
dealloc_compressor_data(cpi);
|
||||||
@@ -1093,8 +1101,12 @@ void vp9_remove_compressor(VP9_COMP *cpi) {
|
|||||||
vp9_remove_common(&cpi->common);
|
vp9_remove_common(&cpi->common);
|
||||||
vpx_free(cpi);
|
vpx_free(cpi);
|
||||||
|
|
||||||
|
#if CONFIG_DENOISING
|
||||||
#ifdef OUTPUT_YUV_DENOISED
|
#ifdef OUTPUT_YUV_DENOISED
|
||||||
fclose(yuv_denoised_file);
|
if (cpi->oxcf.noise_sensitivity > 0) {
|
||||||
|
fclose(yuv_denoised_file);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#ifdef OUTPUT_YUV_SRC
|
#ifdef OUTPUT_YUV_SRC
|
||||||
fclose(yuv_file);
|
fclose(yuv_file);
|
||||||
@@ -1305,6 +1317,7 @@ void vp9_write_yuv_frame(YV12_BUFFER_CONFIG *s, FILE *f) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if CONFIG_DENOISING
|
||||||
#if defined(OUTPUT_YUV_DENOISED)
|
#if defined(OUTPUT_YUV_DENOISED)
|
||||||
// The denoiser buffer is allocated as a YUV 440 buffer. This function writes it
|
// The denoiser buffer is allocated as a YUV 440 buffer. This function writes it
|
||||||
// as YUV 420. We simply use the top-left pixels of the UV buffers, since we do
|
// as YUV 420. We simply use the top-left pixels of the UV buffers, since we do
|
||||||
@@ -1336,6 +1349,7 @@ void vp9_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) {
|
|||||||
} while (--h);
|
} while (--h);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef OUTPUT_YUV_REC
|
#ifdef OUTPUT_YUV_REC
|
||||||
void vp9_write_yuv_rec_frame(VP9_COMMON *cm) {
|
void vp9_write_yuv_rec_frame(VP9_COMMON *cm) {
|
||||||
@@ -1574,12 +1588,14 @@ void vp9_update_reference_frames(VP9_COMP *cpi) {
|
|||||||
&cm->ref_frame_map[cpi->lst_fb_idx], cm->new_fb_idx);
|
&cm->ref_frame_map[cpi->lst_fb_idx], cm->new_fb_idx);
|
||||||
}
|
}
|
||||||
#if CONFIG_DENOISING
|
#if CONFIG_DENOISING
|
||||||
vp9_denoiser_update_frame_info(&cpi->denoiser,
|
if (cpi->oxcf.noise_sensitivity > 0) {
|
||||||
*cpi->Source,
|
vp9_denoiser_update_frame_info(&cpi->denoiser,
|
||||||
cpi->common.frame_type,
|
*cpi->Source,
|
||||||
cpi->refresh_alt_ref_frame,
|
cpi->common.frame_type,
|
||||||
cpi->refresh_golden_frame,
|
cpi->refresh_alt_ref_frame,
|
||||||
cpi->refresh_last_frame);
|
cpi->refresh_golden_frame,
|
||||||
|
cpi->refresh_last_frame);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2171,16 +2187,21 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef OUTPUT_YUV_DENOISED
|
|
||||||
vp9_write_yuv_frame_420(&cpi->denoiser.running_avg_y[INTRA_FRAME],
|
|
||||||
yuv_denoised_file);
|
|
||||||
#endif
|
|
||||||
#ifdef OUTPUT_YUV_SRC
|
#ifdef OUTPUT_YUV_SRC
|
||||||
vp9_write_yuv_frame(cpi->Source, yuv_file);
|
vp9_write_yuv_frame(cpi->Source, yuv_file);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
set_speed_features(cpi);
|
set_speed_features(cpi);
|
||||||
|
|
||||||
|
#if CONFIG_DENOISING
|
||||||
|
#ifdef OUTPUT_YUV_DENOISED
|
||||||
|
if (cpi->oxcf.noise_sensitivity > 0) {
|
||||||
|
vp9_write_yuv_frame_420(&cpi->denoiser.running_avg_y[INTRA_FRAME],
|
||||||
|
yuv_denoised_file);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
// Decide q and q bounds.
|
// Decide q and q bounds.
|
||||||
q = vp9_rc_pick_q_and_bounds(cpi, &bottom_index, &top_index);
|
q = vp9_rc_pick_q_and_bounds(cpi, &bottom_index, &top_index);
|
||||||
|
|
||||||
|
|||||||
@@ -440,7 +440,9 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
#if CONFIG_DENOISING
|
#if CONFIG_DENOISING
|
||||||
vp9_denoiser_reset_frame_stats(&cpi->denoiser);
|
if (cpi->oxcf.noise_sensitivity > 0) {
|
||||||
|
vp9_denoiser_reset_frame_stats(&cpi->denoiser);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (cpi->sf.reuse_inter_pred_sby) {
|
if (cpi->sf.reuse_inter_pred_sby) {
|
||||||
@@ -658,7 +660,9 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if CONFIG_DENOISING
|
#if CONFIG_DENOISING
|
||||||
vp9_denoiser_update_frame_stats(&cpi->denoiser, mbmi, sse_y, this_mode);
|
if (cpi->oxcf.noise_sensitivity > 0) {
|
||||||
|
vp9_denoiser_update_frame_stats(&cpi->denoiser, mbmi, sse_y, this_mode);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (this_rd < best_rd || x->skip) {
|
if (this_rd < best_rd || x->skip) {
|
||||||
@@ -774,7 +778,9 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if CONFIG_DENOISING
|
#if CONFIG_DENOISING
|
||||||
vp9_denoiser_denoise(&cpi->denoiser, x, mi_row, mi_col, bsize);
|
if (cpi->oxcf.noise_sensitivity > 0) {
|
||||||
|
vp9_denoiser_denoise(&cpi->denoiser, x, mi_row, mi_col, bsize);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return INT64_MAX;
|
return INT64_MAX;
|
||||||
|
|||||||
Reference in New Issue
Block a user