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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/video_processing/noise_estimation.cc
diff --git a/webrtc/modules/video_processing/noise_estimation.cc b/webrtc/modules/video_processing/noise_estimation.cc
new file mode 100644
index 0000000000000000000000000000000000000000..99bc8ffdfd13084dd206d802c43dff7417f455c3
--- /dev/null
+++ b/webrtc/modules/video_processing/noise_estimation.cc
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/modules/video_processing/noise_estimation.h"
+
+namespace webrtc {
+
+void NoiseEstimation::SetResolution(int width, int height) {
+ int mb_cols = width >> 4;
+ int mb_rows = height >> 4;
+ consec_low_var_.reset(new uint32_t[mb_cols * mb_rows]());
+ width_ = width;
+ height_ = height;
+}
+
+void NoiseEstimation::GetNoise(int mb_index, uint32_t var, uint32_t luma) {
+ consec_low_var_[mb_index]++;
+ num_stationary_block_++;
+ 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.
+ noise_var_ += ((var / (luma >> 12)) > 384) ? 384 : (var / (luma >> 12));
+ num_noisy_block_++;
+ }
+}
+
+void NoiseEstimation::ResetConsecLowVar(int mb_index) {
+ consec_low_var_[mb_index] = 0;
+}
+
+uint8_t NoiseEstimation::GetNoiseLevel() {
+ int mb_cols = width_ >> 4;
+ int mb_rows = height_ >> 4;
+ // 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.
+ if (num_stationary_block_ < 0.75 * mb_cols * mb_rows || !num_noisy_block_) {
+ noise_var_ = 0;
+ noise_var_accum_ = 0;
+ num_stationary_block_ = 0;
+ num_noisy_block_ = 0;
+#if DISPLAY
+ printf("Not enough samples.\n");
+#endif
+ return 0;
+ } else {
+ noise_var_ /= num_noisy_block_;
+ percent_non_montion_block_ =
+ static_cast<double>(num_stationary_block_) / (mb_cols * mb_rows);
+#if DISPLAY
+ printf("%d %d fraction = %.3f\n", num_stationary_block_, mb_cols * mb_rows,
+ percent_non_montion_block_);
+#endif
+ num_noisy_block_ = 0;
+ num_stationary_block_ = 0;
+ }
+ // For the first frame get the noise value, just use the value as accumulated
+ // one, otherwise, use the averaging window.
+ if (noise_var_accum_ == 0) {
+ noise_var_accum_ = noise_var_;
+ } else {
+ 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.
+ }
+#if DISPLAY
+ printf("noise_var_accum_ = %.1f, noise_var_ = %d.\n", noise_var_accum_,
+ noise_var_);
+#endif
+ // Reset noise_var_ for the next frame.
+ noise_var_ = 0;
+ if (noise_var_accum_ > kNoiseThresholdHigh) {
+ return 2;
+ } else if (noise_var_accum_ > kNoiseThreshold) {
+ return 1;
+ }
+ return 0;
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698