Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: webrtc/modules/video_processing/util/noise_estimation.cc

Issue 1822333003: External denoiser based on noise estimation and moving object detection. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix some style issues. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/video_processing/util/noise_estimation.h"
12
13 namespace webrtc {
14
15 void NoiseEstimation::Init(int width, int height, CpuType cpu_type) {
16 int mb_cols = width >> 4;
17 int mb_rows = height >> 4;
18 consec_low_var_.reset(new uint32_t[mb_cols * mb_rows]());
19 width_ = width;
20 height_ = height;
21 mb_cols_ = width_ >> 4;
22 mb_rows_ = height_ >> 4;
23 cpu_type_ = cpu_type;
24 }
25
26 void NoiseEstimation::GetNoise(int mb_index, uint32_t var, uint32_t luma) {
27 consec_low_var_[mb_index]++;
28 num_static_block_++;
29 if (consec_low_var_[mb_index] >= kConsecLowVarFrame &&
30 (luma >> 8) < kAverageLumaMax && (luma >> 8) > kAverageLumaMin) {
31 // Normalized var by the average luma value, this gives more credit to
marpan 2016/03/31 18:36:47 weight?
jackychen_ 2016/04/01 00:05:06 Done.
32 // darker blocks.
33 int nor_var = var / (luma >> 12);
34 noise_var_ +=
35 nor_var > kBlockSelectionVarMax ? kBlockSelectionVarMax : nor_var;
36 num_noisy_block_++;
37 }
38 }
39
40 void NoiseEstimation::ResetConsecLowVar(int mb_index) {
41 consec_low_var_[mb_index] = 0;
42 }
43
44 void NoiseEstimation::UpdateNoiseLevel() {
45 // No enough samples implies the motion of the camera or too many moving
46 // objects in the frame.
47 if (num_static_block_ < (0.65 * mb_cols_ * mb_rows_) || !num_noisy_block_) {
marpan 2016/03/31 18:36:47 look into why not "num_noisy_block_ < T"
jackychen_ 2016/04/01 00:05:06 Done.
48 noise_var_ = 0;
49 noise_var_accum_ = 0;
50 num_static_block_ = 0;
51 num_noisy_block_ = 0;
52 #if DISPLAY
53 printf("Not enough samples.\n");
54 #endif
55 return;
56 } else {
57 // Normalized by the number of noisy blocks.
58 noise_var_ /= num_noisy_block_;
59 // Get the percentage of static blocks.
60 percent_static_block_ =
61 static_cast<double>(num_static_block_) / (mb_cols_ * mb_rows_);
62 #if DISPLAY
63 printf("%d %d fraction = %.3f\n", num_static_block_, mb_cols_ * mb_rows_,
64 percent_static_block_);
65 #endif
66 num_noisy_block_ = 0;
67 num_static_block_ = 0;
68 }
69 // For the first frame just update the value with current noise_var_,
70 // otherwise, use the averaging window.
71 if (noise_var_accum_ == 0) {
72 noise_var_accum_ = noise_var_;
73 } else {
74 noise_var_accum_ = (noise_var_accum_ * 15 + noise_var_) / 16;
75 }
76 // Reset noise_var_ for the next frame.
77 noise_var_ = 0;
78 #if DISPLAY
79 printf("noise_var_accum_ = %.1f, noise_var_ = %d.\n", noise_var_accum_,
80 noise_var_);
81 #endif
82 }
83
84 uint8_t NoiseEstimation::GetNoiseLevel() {
85 int noise_thr = cpu_type_ ? kNoiseThreshold : kNoiseThresholdNeon;
86 UpdateNoiseLevel();
87 if (noise_var_accum_ > noise_thr) {
88 return 1;
89 }
90 return 0;
91 }
92
93 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_processing/util/noise_estimation.h ('k') | webrtc/modules/video_processing/video_denoiser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698