OLD | NEW |
---|---|
(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 cpu_type_ = cpu_type; | |
22 } | |
23 | |
24 void NoiseEstimation::GetNoise(int mb_index, uint32_t var, uint32_t luma) { | |
marpan
2016/03/30 18:27:20
Comments: This computes block noise and accumulate
jackychen_
2016/03/30 22:36:37
It normalizes var and accumulates. var is computed
| |
25 consec_low_var_[mb_index]++; | |
26 num_stationary_block_++; | |
27 if (consec_low_var_[mb_index] >= kConsecLowVarFrame && | |
28 (luma >> 8) < kAverageLumaMax && (luma >> 8) > kAverageLumaMin) { | |
29 int nor_var = var / (luma >> 12); | |
30 noise_var_ += | |
31 nor_var > kBlockSelectionVarMax ? kBlockSelectionVarMax : nor_var; | |
32 num_noisy_block_++; | |
33 } | |
34 } | |
35 | |
36 void NoiseEstimation::ResetConsecLowVar(int mb_index) { | |
37 consec_low_var_[mb_index] = 0; | |
38 } | |
39 | |
40 uint8_t NoiseEstimation::GetNoiseLevel() { | |
marpan
2016/03/30 18:27:20
You're still doing 3 things in this function:
1. n
jackychen_
2016/03/30 22:36:37
Split to 2 functions and add some comments.
| |
41 int mb_cols = width_ >> 4; | |
42 int mb_rows = height_ >> 4; | |
marpan
2016/03/30 18:27:20
is it worth defining mb_cols/rows_ in this class,
jackychen_
2016/03/30 22:36:37
Done.
| |
43 // No enough samples implies the motion of the camera or too many moving | |
marpan
2016/03/30 18:27:20
Should condition of "Not enough samples" be num_no
jackychen_
2016/03/30 22:36:37
Correct. I just use thresh = 0, so I code as !num_
| |
44 // objects in the frame. | |
45 if (num_stationary_block_ < 0.65 * mb_cols * mb_rows || !num_noisy_block_) { | |
marpan
2016/03/30 18:27:20
prefer (0.65 * mb_cols * mb_rows)
jackychen_
2016/03/30 22:36:37
Done.
| |
46 noise_var_ = 0; | |
47 noise_var_accum_ = 0; | |
marpan
2016/03/30 18:27:20
is this intentional to set (the running average) n
jackychen_
2016/03/30 22:36:37
Yes. When it happens, I think we should start over
| |
48 num_stationary_block_ = 0; | |
49 num_noisy_block_ = 0; | |
marpan
2016/03/30 18:27:20
the 3 quantities (noise_var, num_stationary_block_
jackychen_
2016/03/30 22:36:37
There is a "return" in the last line of if branch,
| |
50 #if DISPLAY | |
51 printf("Not enough samples.\n"); | |
52 #endif | |
53 return 0; | |
54 } else { | |
55 noise_var_ /= num_noisy_block_; | |
56 percent_non_montion_block_ = | |
marpan
2016/03/30 18:27:20
non_motion
jackychen_
2016/03/30 22:36:37
Maybe it's better to use "static" to make it conci
| |
57 static_cast<double>(num_stationary_block_) / (mb_cols * mb_rows); | |
58 #if DISPLAY | |
59 printf("%d %d fraction = %.3f\n", num_stationary_block_, mb_cols * mb_rows, | |
60 percent_non_montion_block_); | |
61 #endif | |
62 num_noisy_block_ = 0; | |
63 num_stationary_block_ = 0; | |
64 } | |
65 // For the first frame get the noise value, just use the value as accumulated | |
66 // one, otherwise, use the averaging window. | |
67 if (noise_var_accum_ == 0) { | |
68 noise_var_accum_ = noise_var_; | |
69 } else { | |
70 noise_var_accum_ = (noise_var_accum_ * 15 + noise_var_) / 16; | |
71 } | |
72 #if DISPLAY | |
73 printf("noise_var_accum_ = %.1f, noise_var_ = %d.\n", noise_var_accum_, | |
74 noise_var_); | |
75 #endif | |
76 // Reset noise_var_ for the next frame. | |
77 noise_var_ = 0; | |
78 int noise_thr = cpu_type_ ? kNoiseThreshold : kNoiseThresholdNeon; | |
79 if (noise_var_accum_ > noise_thr) { | |
80 return 1; | |
81 } | |
82 return 0; | |
83 } | |
84 | |
85 } // namespace webrtc | |
OLD | NEW |