[OpenCV] RGB Histogram Equalization
RGB Histogram Equalization
Reference: StackOverflow
Grayscale method: Official DOC
Reference: StackOverflow
Grayscale method: Official DOC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <iostream> | |
#include <opencv2/opencv.hpp> | |
#include <opencv2/highgui/highgui.hpp> | |
using namespace cv; | |
using namespace std; | |
/** @function main */ | |
Mat equalizeIntensity(const Mat& inputImage) | |
{ | |
if (inputImage.channels() >= 3) | |
{ | |
Mat ycrcb; | |
cvtColor(inputImage, ycrcb, CV_BGR2YCrCb); | |
vector<Mat> channels; | |
split(ycrcb, channels); | |
equalizeHist(channels[0], channels[0]); | |
Mat result; | |
merge(channels, ycrcb); | |
cvtColor(ycrcb, result, CV_YCrCb2BGR); | |
return result; | |
} | |
return Mat(); | |
} | |
int main(int argc, char** argv) | |
{ | |
Mat src, dst; | |
/// Load image | |
src = imread("C:/img/Fig0635(bottom_left_stream).tif"); | |
Mat src2 = src.clone(); | |
if (!src.data) | |
{ | |
cout << "Usage: ./Histogram_Demo <path_to_image>" << endl; | |
return -1; | |
} | |
src = equalizeIntensity(src); | |
imshow("before", src2); | |
imshow("after", src); | |
/// Wait until user exits the program | |
waitKey(0); | |
return 0; | |
} |
留言
張貼留言