Lab1: Histogram Equalization
1. 实验环境(C++)
- 操作系统版本 MacOS Catalina 10.15
- OpenCV4.0 (imgcodecs | core | highgui | imgproc)
- Cmake-3.14
- Clang-1100.0.33.8
2. 实验步骤
-
Calculate the histogram H for src
-
Normalize the histogram.
std::array<double, 256> calNormalizedHist(cv::Mat& source) { std::array<double, 256> acc{0}; // Calculate the histogram H for src for(int i = 0; i < source.rows; i++) for (int j = 0; j < source.cols; j++) acc[ source.ptr<uchar>(i)[j]] ++; // Normalize the histogram. for(int i = 0; i < acc.size(); i++) acc[i] /= source.rows * source.cols; return acc; } -
Compute the integral of the histogram: H\'
-
Transform the image using H′ as a look-up table: $$