Advertisement
tankian202

Untitled

Oct 16th, 2023
653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.83 KB | None | 0 0
  1. void lab03() {
  2.     float numbers[9] = { 0, 0,0,1,0,0,0,0,0 };
  3.     Mat mask = Mat(3, 3, CV_32FC1, numbers);
  4.     Mat im = imread("eper.jpg");
  5.     Mat result = im.clone();
  6.     int key = 0;
  7.     for (int i = 0; (i < im.cols) && key != 27; i++)
  8.     {
  9.         filter2D(result, result, -1, mask);
  10.         imshow("Result", result);
  11.         key = waitKey();
  12.     }
  13.  
  14.     float numbers2[9] = {0.1, 0.1, 0.1, 0.1, 0.2, 0.1, 0.1, 0.1, 0.1};
  15.     Mat mask2 = Mat(3, 3, CV_32FC1, numbers2);
  16.     result = im.clone();
  17.     key = 0;
  18.     for (int i = 0; (i < im.cols) && key != 27; i++)
  19.     {
  20.         filter2D(result, result, -1, mask2);
  21.         imshow("Result", result);
  22.         key = waitKey();
  23.     }
  24.     im = imread("faliszonyeg.jpg");
  25.     float k = 0;
  26.     key = 0;
  27.     result = im.clone();
  28.     for (int i = 0; (i < im.cols) && key != 27; i++)
  29.     {
  30.         float numbers[9] = { 0, k / 4, 0, -k / 4, 1 + k, -k / 4, 0, -k / 4, 0 };
  31.         Mat mask = Mat(3, 3, CV_32FC1, numbers);
  32.         filter2D(result, result, -1, mask );
  33.         imshow("Result", result);
  34.         key = waitKey();
  35.         k++;
  36.     }
  37.     key = 0;
  38.     im = imread("eper.jpg");
  39.     destroyWindow("Result");
  40.     for (int k = 3; (k < 100) && key != 27;k += 2)
  41.     {
  42.         Mat resultGauss, resultBlur;
  43.         blur(im, resultBlur,Size(k,k));
  44.         GaussianBlur(im, resultGauss, Size(k, k), 1);
  45.         imshow("Gauss", resultGauss);
  46.         key = waitKey();
  47.         imshow("Blur", resultBlur);
  48.     key = waitKey();
  49.     }
  50.  
  51.     Mat imBe = imread("repulo.jpg");
  52.     Mat imKi = imBe.clone();
  53.     key = 0;
  54.     for (int db = 0; db < 20 ; ++db) {
  55.         line(imBe, Point(rand() % imBe.cols, rand() % imBe.rows),
  56.             Point(rand() % imBe.cols, rand() % imBe.rows),
  57.             Scalar(0, 0, 0, 0), 1 + db % 2);
  58.         Mat imKi = imBe.clone();
  59.     }
  60.     destroyAllWindows();
  61.     for (int i = 1; i < 10 && key != 27; i+=2)
  62.     {
  63.         medianBlur(imBe, imKi, i);
  64.         imshow("Result", imKi);
  65.         key = waitKey(0);
  66.     }
  67.     destroyAllWindows();
  68.     imBe = imread("amoba.png");
  69.  
  70.     key = 0;
  71.     for (int i = 0;i < 600 && key!=27;i++)
  72.     {
  73.         medianBlur(imBe, imBe, 21);
  74.         if(i%3==0){
  75.             imshow("result", imBe);
  76.             key = waitKey(0);
  77.         }
  78.  
  79.     }
  80. }
  81. void lab02() {
  82.     // Beolvassuk a színes képet
  83.     Mat im = imread("eper.jpg");
  84.     Mat z(im.rows, im.cols, CV_8UC1, Scalar(0));
  85.     Mat imBig = Mat(im.rows * 3, im.cols * 6, im.type());
  86.     imBig.setTo(Scalar(128, 128, 255, 0));
  87.     int index = 0;
  88.     Mat result = im.clone();
  89.    
  90.     Mat bgr[3], & b = bgr[0], & g = bgr[1], & r = bgr[2];
  91.     split(im, bgr);
  92.     showMyImage(imBig, result, index);
  93.     //1
  94.     merge(vector<Mat>{z, g, r}, result);
  95.     showMyImage(imBig, result, index);
  96.     merge(vector<Mat>{b, z, r}, result);
  97.     showMyImage(imBig, result, index);
  98.     merge(vector<Mat>{b, g, z}, result);
  99.     showMyImage(imBig, result, index);
  100.     //2
  101.     merge(vector<Mat>{b, z, z}, result);
  102.     showMyImage(imBig, result, index);
  103.     merge(vector<Mat>{z, g, z}, result);
  104.     showMyImage(imBig, result, index);
  105.     merge(vector<Mat>{z, z, r}, result);
  106.     showMyImage(imBig, result, index);
  107.     //3.
  108.     result = im.clone();
  109.     merge(vector<Mat>{b, g, r}, result);
  110.     showMyImage(imBig, result, index);
  111.     merge(vector<Mat>{b, r, g}, result);
  112.     showMyImage(imBig, result, index);
  113.     merge(vector<Mat>{g, b, r}, result);
  114.     showMyImage(imBig, result, index);
  115.     merge(vector<Mat>{g, r, b}, result);
  116.     showMyImage(imBig, result, index);
  117.     merge(vector<Mat>{r, b, g}, result);
  118.     showMyImage(imBig, result, index);
  119.     merge(vector<Mat>{r, g, b}, result);
  120.     showMyImage(imBig, result, index);
  121.     //4
  122.     merge(vector<Mat>{~b,g,r}, result);
  123.     showMyImage(imBig, result, index);
  124.     merge(vector<Mat>{b, ~g, r}, result);
  125.     showMyImage(imBig, result, index);
  126.     merge(vector<Mat>{b, g, ~r}, result);
  127.     showMyImage(imBig, result, index);
  128.     //5
  129.     cvtColor(im, result, COLOR_BGR2YCrCb);
  130.     Mat yCrCb[3], &y = yCrCb[0], &Cr = yCrCb[1], &Cb = yCrCb[2];
  131.     split(result,yCrCb);
  132.     merge(vector<Mat>{~y, Cr, Cb}, result);
  133.     cvtColor(result, result, COLOR_YCrCb2BGR);
  134.     showMyImage(imBig, result, index);
  135.     //6
  136.     merge(vector<Mat>{~b, ~g, ~r}, result);
  137.     showMyImage(imBig, result, index);
  138.  
  139.     waitKey(0);
  140.  
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement