jackychen | fa0befe | 2016-04-01 07:46:58 -0700 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_VIDEO_PROCESSING_UTIL_NOISE_ESTIMATION_H_ |
| 12 | #define MODULES_VIDEO_PROCESSING_UTIL_NOISE_ESTIMATION_H_ |
jackychen | fa0befe | 2016-04-01 07:46:58 -0700 | [diff] [blame] | 13 | |
kwiberg | 84be511 | 2016-04-27 01:19:58 -0700 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "modules/include/module_common_types.h" |
| 17 | #include "modules/video_processing/util/denoiser_filter.h" |
jackychen | fa0befe | 2016-04-01 07:46:58 -0700 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | |
jackychen | 8556c48 | 2016-04-20 16:04:31 -0700 | [diff] [blame] | 21 | #define DISPLAY 0 // Rectangle diagnostics |
| 22 | #define DISPLAYNEON 0 // Rectangle diagnostics on NEON |
jackychen | fa0befe | 2016-04-01 07:46:58 -0700 | [diff] [blame] | 23 | |
jackychen | 9bfa106 | 2016-05-03 11:21:26 -0700 | [diff] [blame] | 24 | const int kNoiseThreshold = 150; |
jackychen | fa0befe | 2016-04-01 07:46:58 -0700 | [diff] [blame] | 25 | const int kNoiseThresholdNeon = 70; |
| 26 | const int kConsecLowVarFrame = 6; |
| 27 | const int kAverageLumaMin = 20; |
| 28 | const int kAverageLumaMax = 220; |
| 29 | const int kBlockSelectionVarMax = kNoiseThreshold << 1; |
| 30 | |
jackychen | afaae0d | 2016-04-12 23:02:55 -0700 | [diff] [blame] | 31 | // TODO(jackychen): To test different sampling strategy. |
| 32 | // Collect noise data every NOISE_SUBSAMPLE_INTERVAL blocks. |
| 33 | #define NOISE_SUBSAMPLE_INTERVAL 41 |
| 34 | |
jackychen | fa0befe | 2016-04-01 07:46:58 -0700 | [diff] [blame] | 35 | class NoiseEstimation { |
| 36 | public: |
| 37 | void Init(int width, int height, CpuType cpu_type); |
jackychen | afaae0d | 2016-04-12 23:02:55 -0700 | [diff] [blame] | 38 | // Collect noise data from one qualified block. |
jackychen | fa0befe | 2016-04-01 07:46:58 -0700 | [diff] [blame] | 39 | void GetNoise(int mb_index, uint32_t var, uint32_t luma); |
jackychen | afaae0d | 2016-04-12 23:02:55 -0700 | [diff] [blame] | 40 | // Reset the counter for consecutive low-var blocks. |
jackychen | fa0befe | 2016-04-01 07:46:58 -0700 | [diff] [blame] | 41 | void ResetConsecLowVar(int mb_index); |
jackychen | afaae0d | 2016-04-12 23:02:55 -0700 | [diff] [blame] | 42 | // Update noise level for current frame. |
jackychen | fa0befe | 2016-04-01 07:46:58 -0700 | [diff] [blame] | 43 | void UpdateNoiseLevel(); |
| 44 | // 0: low noise, 1: high noise |
| 45 | uint8_t GetNoiseLevel(); |
| 46 | |
| 47 | private: |
| 48 | int width_; |
| 49 | int height_; |
| 50 | int mb_rows_; |
| 51 | int mb_cols_; |
jackychen | afaae0d | 2016-04-12 23:02:55 -0700 | [diff] [blame] | 52 | int num_noisy_block_; |
| 53 | int num_static_block_; |
jackychen | fa0befe | 2016-04-01 07:46:58 -0700 | [diff] [blame] | 54 | CpuType cpu_type_; |
| 55 | uint32_t noise_var_; |
| 56 | double noise_var_accum_; |
jackychen | fa0befe | 2016-04-01 07:46:58 -0700 | [diff] [blame] | 57 | double percent_static_block_; |
jackychen | afaae0d | 2016-04-12 23:02:55 -0700 | [diff] [blame] | 58 | std::unique_ptr<uint32_t[]> consec_low_var_; |
jackychen | fa0befe | 2016-04-01 07:46:58 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | } // namespace webrtc |
| 62 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 63 | #endif // MODULES_VIDEO_PROCESSING_UTIL_NOISE_ESTIMATION_H_ |