Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <opencv2/opencv.hpp>
- #include <iostream>
- using namespace cv;
- using namespace std;
- Mat eqHistBgr(const Mat& inputImage)
- {
- vector<Mat> channels;
- split(inputImage, channels);
- for (int i = 0;i < 3;i++) {
- equalizeHist(channels[i], channels[i]);
- }
- Mat result;
- merge(channels, result);
- return result;
- return Mat();
- }
- Mat smoothingBgr(const Mat& inputImage, int kernelSize)
- {
- vector<Mat> channels;
- split(inputImage, channels);
- for (int i = 0;i < 3;i++) {
- blur(channels[i], channels[i], Size(kernelSize, kernelSize), Point(-1,-1));
- }
- Mat result;
- merge(channels, result);
- return result;
- return Mat();
- }
- Mat smoothingHsv(const Mat& inputImage, int kernelSize)
- {
- Mat hsv;
- cvtColor(inputImage, hsv, COLOR_BGR2HSV);
- blur(hsv, hsv, Size(kernelSize, kernelSize), Point(-1, -1));
- cvtColor(hsv, hsv, COLOR_HSV2BGR);
- return hsv;
- return Mat();
- }
- Mat eqHistHsv(const Mat& inputImage)
- {
- Mat hsv;
- cvtColor(inputImage, hsv, COLOR_BGR2HSV);
- vector<Mat> channels;
- split(inputImage, channels);
- equalizeHist(channels[2], channels[2]);
- Mat result;
- merge(channels, result);
- cvtColor(result, result, COLOR_HSV2BGR);
- return result;
- return Mat();
- }
- int main(int argc, char** argv)
- {
- // Read the image file
- Mat image = imread("C:/Users/lab/Desktop/images/images/Fig4.jpg");
- //Mat result = eqHistBgr(image);
- //Mat result = eqHistHsv(image);
- //Mat result = smoothingBgr(image, 5);
- Mat result = smoothingHsv(image, 5);
- //Define the names of windows
- String windowNameOfOriginalImage = "Original Image";
- String windowNameOfHistogramEqualized = "Histogram Equalized Color Image";
- // Create windows with the above names
- namedWindow(windowNameOfOriginalImage, WINDOW_NORMAL);
- namedWindow(windowNameOfHistogramEqualized, WINDOW_NORMAL);
- // Show images inside the created windows.
- imshow(windowNameOfOriginalImage, image);
- imshow(windowNameOfHistogramEqualized, result);
- waitKey(0); // Wait for any keystroke in any one of the windows
- destroyAllWindows(); //Destroy all opened windows
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement