NoobsDeSroobs

Mixing vertical and horizontal sobel filtering.

Feb 23rd, 2015
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include <opencv2/core/core.hpp>
  2. #include <opencv2/highgui/highgui.hpp>
  3. #include <opencv2/imgproc/imgproc.hpp>
  4. #include <iostream>
  5.  
  6. int main()
  7. {
  8.     cv::Mat img = cv::imread("E:/Dropbox/IMERSO/stainless-cube01_1024x1024.jpg");
  9.     cv::namedWindow("FunnyEffectsLol9ga!!!111", cv::WINDOW_AUTOSIZE);
  10.     cv::Mat grey;
  11.     cv::cvtColor(img, grey, cv::COLOR_BGR2GRAY);
  12.  
  13.     cv::Mat sobel1;
  14.     cv::Sobel(grey, sobel1, CV_32F, 0, 1);
  15.  
  16.     double minVal, maxVal;
  17.     minMaxLoc(sobel1, &minVal, &maxVal); //find minimum and maximum intensities
  18.  
  19.     cv::Mat draw1;
  20.     sobel1.convertTo(draw1, CV_8U, 255.0 / (maxVal - minVal), -minVal * 255.0 / (maxVal - minVal));
  21.  
  22.     cv::Mat sobel2;
  23.     cv::Sobel(grey, sobel2, CV_32F, 1, 0);
  24.  
  25.     minMaxLoc(sobel2, &minVal, &maxVal); //find minimum and maximum intensities
  26.  
  27.     cv::Mat draw2;
  28.     sobel2.convertTo(draw2, CV_8U, 255.0 / (maxVal - minVal), -minVal * 255.0 / (maxVal - minVal));
  29.  
  30.     cv::Mat height(draw2);
  31.     //cv::min(draw1, draw2, height);
  32.  
  33.     for (size_t y = 1; y < height.rows-1; y++) {
  34.         for (size_t x = 1; x < height.cols-1; x++) {
  35.             height.at<uchar>(y, x) = (draw1.at<uchar>(y, x) + draw2.at<uchar>(y, x)) / 2;
  36.         }
  37.     }
  38.  
  39.     cv::GaussianBlur(height, height, cv::Size(3, 3), 1, 1);
  40.     imshow("FunnyEffectsLol9ga!!!111", height);
  41.  
  42.     cv::waitKey(0);
  43.     cv::destroyWindow("FunnyEffectsLol9ga!!!111");
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment