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

Side by Side Diff: webrtc/modules/video_processing/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: Created 4 years, 9 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/noise_estimation.h"
12
13 namespace webrtc {
14
15 void NoiseEstimation::SetResolution(int width, int height) {
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 }
22
23 void NoiseEstimation::GetNoise(int mb_index, uint32_t var, uint32_t luma) {
24 consec_low_var_[mb_index]++;
25 num_stationary_block_++;
26 if (consec_low_var_[mb_index] >= 6 && (luma >> 8) < 220 && (luma >> 8) > 20) {
marpan 2016/03/24 20:56:16 i would prefer to expose these thresholds (6, 229,
jackychen_ 2016/03/25 18:45:44 Done.
27 noise_var_ += ((var / (luma >> 12)) > 384) ? 384 : (var / (luma >> 12));
28 num_noisy_block_++;
29 }
30 }
31
32 void NoiseEstimation::ResetConsecLowVar(int mb_index) {
33 consec_low_var_[mb_index] = 0;
34 }
35
36 uint8_t NoiseEstimation::GetNoiseLevel() {
37 int mb_cols = width_ >> 4;
38 int mb_rows = height_ >> 4;
39 // No enough samples implies the motion of the camera.
marpan 2016/03/24 20:56:16 ...or too much of object in frame
jackychen_ 2016/03/25 18:45:44 Done.
40 if (num_stationary_block_ < 0.75 * mb_cols * mb_rows || !num_noisy_block_) {
41 noise_var_ = 0;
42 noise_var_accum_ = 0;
43 num_stationary_block_ = 0;
44 num_noisy_block_ = 0;
45 #if DISPLAY
46 printf("Not enough samples.\n");
47 #endif
48 return 0;
49 } else {
50 noise_var_ /= num_noisy_block_;
51 percent_non_montion_block_ =
52 static_cast<double>(num_stationary_block_) / (mb_cols * mb_rows);
53 #if DISPLAY
54 printf("%d %d fraction = %.3f\n", num_stationary_block_, mb_cols * mb_rows,
55 percent_non_montion_block_);
56 #endif
57 num_noisy_block_ = 0;
58 num_stationary_block_ = 0;
59 }
60 // For the first frame get the noise value, just use the value as accumulated
61 // one, otherwise, use the averaging window.
62 if (noise_var_accum_ == 0) {
63 noise_var_accum_ = noise_var_;
64 } else {
65 noise_var_accum_ = (noise_var_accum_ * 15 + noise_var_) / 16;
marpan 2016/03/24 20:56:16 better to expose this (15) as parameter too?
jackychen_ 2016/03/25 18:45:44 Acknowledged.
66 }
67 #if DISPLAY
68 printf("noise_var_accum_ = %.1f, noise_var_ = %d.\n", noise_var_accum_,
69 noise_var_);
70 #endif
71 // Reset noise_var_ for the next frame.
72 noise_var_ = 0;
73 if (noise_var_accum_ > kNoiseThresholdHigh) {
74 return 2;
75 } else if (noise_var_accum_ > kNoiseThreshold) {
76 return 1;
77 }
78 return 0;
79 }
80
81 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698