blob: 4c5f10f1d83d4e864700833c1aa321e23cefddda [file] [log] [blame]
jackychenfa0befe2016-04-01 07:46:58 -07001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_VIDEO_PROCESSING_UTIL_NOISE_ESTIMATION_H_
12#define MODULES_VIDEO_PROCESSING_UTIL_NOISE_ESTIMATION_H_
jackychenfa0befe2016-04-01 07:46:58 -070013
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <cstdint>
kwiberg84be5112016-04-27 01:19:58 -070015#include <memory>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/video_processing/util/denoiser_filter.h"
jackychenfa0befe2016-04-01 07:46:58 -070018
19namespace webrtc {
20
jackychen8556c482016-04-20 16:04:31 -070021#define DISPLAY 0 // Rectangle diagnostics
22#define DISPLAYNEON 0 // Rectangle diagnostics on NEON
jackychenfa0befe2016-04-01 07:46:58 -070023
jackychen9bfa1062016-05-03 11:21:26 -070024const int kNoiseThreshold = 150;
jackychenfa0befe2016-04-01 07:46:58 -070025const int kNoiseThresholdNeon = 70;
26const int kConsecLowVarFrame = 6;
27const int kAverageLumaMin = 20;
28const int kAverageLumaMax = 220;
29const int kBlockSelectionVarMax = kNoiseThreshold << 1;
30
jackychenafaae0d2016-04-12 23:02:55 -070031// TODO(jackychen): To test different sampling strategy.
32// Collect noise data every NOISE_SUBSAMPLE_INTERVAL blocks.
33#define NOISE_SUBSAMPLE_INTERVAL 41
34
jackychenfa0befe2016-04-01 07:46:58 -070035class NoiseEstimation {
36 public:
37 void Init(int width, int height, CpuType cpu_type);
jackychenafaae0d2016-04-12 23:02:55 -070038 // Collect noise data from one qualified block.
jackychenfa0befe2016-04-01 07:46:58 -070039 void GetNoise(int mb_index, uint32_t var, uint32_t luma);
jackychenafaae0d2016-04-12 23:02:55 -070040 // Reset the counter for consecutive low-var blocks.
jackychenfa0befe2016-04-01 07:46:58 -070041 void ResetConsecLowVar(int mb_index);
jackychenafaae0d2016-04-12 23:02:55 -070042 // Update noise level for current frame.
jackychenfa0befe2016-04-01 07:46:58 -070043 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_;
jackychenafaae0d2016-04-12 23:02:55 -070052 int num_noisy_block_;
53 int num_static_block_;
jackychenfa0befe2016-04-01 07:46:58 -070054 CpuType cpu_type_;
55 uint32_t noise_var_;
56 double noise_var_accum_;
jackychenfa0befe2016-04-01 07:46:58 -070057 double percent_static_block_;
jackychenafaae0d2016-04-12 23:02:55 -070058 std::unique_ptr<uint32_t[]> consec_low_var_;
jackychenfa0befe2016-04-01 07:46:58 -070059};
60
61} // namespace webrtc
62
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020063#endif // MODULES_VIDEO_PROCESSING_UTIL_NOISE_ESTIMATION_H_