daily pastebin goal
38%
SHARE
TWEET

Untitled

a guest Mar 22nd, 2018 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <opencv2/opencv.hpp>
  2. #include <iostream>
  3.  
  4. using namespace cv;
  5. using namespace std;
  6.  
  7. Mat eqHistBgr(const Mat& inputImage)
  8. {
  9.     vector<Mat> channels;
  10.     split(inputImage, channels);
  11.  
  12.     for (int i = 0;i < 3;i++) {
  13.         equalizeHist(channels[i], channels[i]);
  14.     }
  15.     Mat result;
  16.     merge(channels, result);
  17.     return result;
  18.  
  19.     return Mat();
  20. }
  21.  
  22. Mat smoothingBgr(const Mat& inputImage, int kernelSize)
  23. {
  24.     vector<Mat> channels;
  25.     split(inputImage, channels);
  26.  
  27.     for (int i = 0;i < 3;i++) {
  28.         blur(channels[i], channels[i], Size(kernelSize, kernelSize), Point(-1,-1));
  29.     }
  30.     Mat result;
  31.     merge(channels, result);
  32.     return result;
  33.  
  34.     return Mat();
  35. }
  36.  
  37. Mat smoothingHsv(const Mat& inputImage, int kernelSize)
  38. {
  39.     Mat hsv;
  40.     cvtColor(inputImage, hsv, COLOR_BGR2HSV);
  41.     blur(hsv, hsv, Size(kernelSize, kernelSize), Point(-1, -1));
  42.     cvtColor(hsv, hsv, COLOR_HSV2BGR);
  43.  
  44.     return hsv;
  45.     return Mat();
  46. }
  47.  
  48.  
  49.  
  50. Mat eqHistHsv(const Mat& inputImage)
  51. {
  52.     Mat hsv;
  53.     cvtColor(inputImage, hsv, COLOR_BGR2HSV);
  54.  
  55.     vector<Mat> channels;
  56.     split(inputImage, channels);
  57.  
  58.     equalizeHist(channels[2], channels[2]);
  59.    
  60.     Mat result;
  61.     merge(channels, result);
  62.  
  63.     cvtColor(result, result, COLOR_HSV2BGR);
  64.     return result;
  65.     return Mat();
  66. }
  67.  
  68. int main(int argc, char** argv)
  69. {
  70.     // Read the image file
  71.     Mat image = imread("C:/Users/lab/Desktop/images/images/Fig4.jpg");
  72.     //Mat result = eqHistBgr(image);
  73.     //Mat result = eqHistHsv(image);
  74.     //Mat result = smoothingBgr(image, 5);
  75.     Mat result = smoothingHsv(image, 5);
  76.  
  77.  
  78.     //Define the names of windows
  79.     String windowNameOfOriginalImage = "Original Image";
  80.     String windowNameOfHistogramEqualized = "Histogram Equalized Color Image";
  81.  
  82.     // Create windows with the above names
  83.     namedWindow(windowNameOfOriginalImage, WINDOW_NORMAL);
  84.     namedWindow(windowNameOfHistogramEqualized, WINDOW_NORMAL);
  85.  
  86.     // Show images inside the created windows.
  87.     imshow(windowNameOfOriginalImage, image);
  88.     imshow(windowNameOfHistogramEqualized, result);
  89.  
  90.     waitKey(0); // Wait for any keystroke in any one of the windows
  91.  
  92.     destroyAllWindows(); //Destroy all opened windows
  93.  
  94.     return 0;
  95. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top