noise_estimation.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #ifndef MODULES_VIDEO_PROCESSING_UTIL_NOISE_ESTIMATION_H_
  11. #define MODULES_VIDEO_PROCESSING_UTIL_NOISE_ESTIMATION_H_
  12. #include <cstdint>
  13. #include <memory>
  14. #include "modules/video_processing/util/denoiser_filter.h"
  15. namespace webrtc {
  16. #define DISPLAY 0 // Rectangle diagnostics
  17. #define DISPLAYNEON 0 // Rectangle diagnostics on NEON
  18. const int kNoiseThreshold = 150;
  19. const int kNoiseThresholdNeon = 70;
  20. const int kConsecLowVarFrame = 6;
  21. const int kAverageLumaMin = 20;
  22. const int kAverageLumaMax = 220;
  23. const int kBlockSelectionVarMax = kNoiseThreshold << 1;
  24. // TODO(jackychen): To test different sampling strategy.
  25. // Collect noise data every NOISE_SUBSAMPLE_INTERVAL blocks.
  26. #define NOISE_SUBSAMPLE_INTERVAL 41
  27. class NoiseEstimation {
  28. public:
  29. void Init(int width, int height, CpuType cpu_type);
  30. // Collect noise data from one qualified block.
  31. void GetNoise(int mb_index, uint32_t var, uint32_t luma);
  32. // Reset the counter for consecutive low-var blocks.
  33. void ResetConsecLowVar(int mb_index);
  34. // Update noise level for current frame.
  35. void UpdateNoiseLevel();
  36. // 0: low noise, 1: high noise
  37. uint8_t GetNoiseLevel();
  38. private:
  39. int width_;
  40. int height_;
  41. int mb_rows_;
  42. int mb_cols_;
  43. int num_noisy_block_;
  44. int num_static_block_;
  45. CpuType cpu_type_;
  46. uint32_t noise_var_;
  47. double noise_var_accum_;
  48. double percent_static_block_;
  49. std::unique_ptr<uint32_t[]> consec_low_var_;
  50. };
  51. } // namespace webrtc
  52. #endif // MODULES_VIDEO_PROCESSING_UTIL_NOISE_ESTIMATION_H_