Advertisement
Guest User

Untitled

a guest
May 20th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 58.23 KB | None | 0 0
  1. // OpenCVApplication.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "common.h"
  6. #include <queue>
  7. #include <stdio.h>
  8. #include <string>
  9.  
  10. #define WEAK 128
  11. #define STRONG 255
  12.  
  13.  
  14.  
  15. void testOpenImage()
  16. {
  17. char fname[MAX_PATH];
  18. while(openFileDlg(fname))
  19. {
  20. Mat src;
  21. src = imread(fname);
  22. imshow("image",src);
  23. waitKey();
  24. }
  25. }
  26.  
  27. void testOpenImagesFld()
  28. {
  29. char folderName[MAX_PATH];
  30. if (openFolderDlg(folderName)==0)
  31. return;
  32. char fname[MAX_PATH];
  33. FileGetter fg(folderName,"bmp");
  34. while(fg.getNextAbsFile(fname))
  35. {
  36. Mat src;
  37. src = imread(fname);
  38. imshow(fg.getFoundFileName(),src);
  39. if (waitKey()==27) //ESC pressed
  40. break;
  41. }
  42. }
  43.  
  44. void testImageOpenAndSave()
  45. {
  46. Mat src, dst;
  47.  
  48. src = imread("Images/Lena_24bits.bmp", CV_LOAD_IMAGE_COLOR); // Read the image
  49.  
  50. if (!src.data) // Check for invalid input
  51. {
  52. printf("Could not open or find the image\n");
  53. return;
  54. }
  55.  
  56. // Get the image resolution
  57. Size src_size = Size(src.cols, src.rows);
  58.  
  59. // Display window
  60. const char* WIN_SRC = "Src"; //window for the source image
  61. namedWindow(WIN_SRC, CV_WINDOW_AUTOSIZE);
  62. cvMoveWindow(WIN_SRC, 0, 0);
  63.  
  64. const char* WIN_DST = "Dst"; //window for the destination (processed) image
  65. namedWindow(WIN_DST, CV_WINDOW_AUTOSIZE);
  66. cvMoveWindow(WIN_DST, src_size.width + 10, 0);
  67.  
  68. cvtColor(src, dst, CV_BGR2GRAY); //converts the source image to a grayscale one
  69.  
  70. imwrite("Images/Lena_24bits_gray.bmp", dst); //writes the destination to file
  71.  
  72. imshow(WIN_SRC, src);
  73. imshow(WIN_DST, dst);
  74.  
  75. printf("Press any key to continue ...\n");
  76. waitKey(0);
  77. }
  78.  
  79. void testNegativeImage()
  80. {
  81. char fname[MAX_PATH];
  82. while(openFileDlg(fname))
  83. {
  84. double t = (double)getTickCount(); // Get the current time [s]
  85.  
  86. Mat src = imread(fname,CV_LOAD_IMAGE_GRAYSCALE);
  87. int height = src.rows;
  88. int width = src.cols;
  89. Mat dst = Mat(height,width,CV_8UC1);
  90. // Asa se acceseaaza pixelii individuali pt. o imagine cu 8 biti/pixel
  91. // Varianta ineficienta (lenta)
  92. for (int i=0; i<height; i++)
  93. {
  94. for (int j=0; j<width; j++)
  95. {
  96. uchar val = src.at<uchar>(i,j);
  97. uchar neg = MAX_PATH-val;
  98. dst.at<uchar>(i,j) = neg;
  99. }
  100. }
  101.  
  102. // Get the current time again and compute the time difference [s]
  103. t = ((double)getTickCount() - t) / getTickFrequency();
  104. // Print (in the console window) the processing time in [ms]
  105. printf("Time = %.3f [ms]\n", t * 1000);
  106.  
  107. imshow("input image",src);
  108. imshow("negative image",dst);
  109. waitKey();
  110. }
  111. }
  112.  
  113. void testParcurgereSimplaDiblookStyle()
  114. {
  115. char fname[MAX_PATH];
  116. while (openFileDlg(fname))
  117. {
  118. Mat src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
  119. int height = src.rows;
  120. int width = src.cols;
  121. Mat dst = src.clone();
  122.  
  123. double t = (double)getTickCount(); // Get the current time [s]
  124.  
  125. // the fastest approach using the “diblook style”
  126. uchar *lpSrc = src.data;
  127. uchar *lpDst = dst.data;
  128. int w = (int) src.step; // no dword alignment is done !!!
  129. for (int i = 0; i<height; i++)
  130. for (int j = 0; j < width; j++) {
  131. uchar val = lpSrc[i*w + j];
  132. lpDst[i*w + j] = 255 - val;
  133. }
  134.  
  135. // Get the current time again and compute the time difference [s]
  136. t = ((double)getTickCount() - t) / getTickFrequency();
  137. // Print (in the console window) the processing time in [ms]
  138. printf("Time = %.3f [ms]\n", t * 1000);
  139.  
  140. imshow("input image",src);
  141. imshow("negative image",dst);
  142. waitKey();
  143. }
  144. }
  145.  
  146. void testColor2Gray()
  147. {
  148. char fname[MAX_PATH];
  149. while(openFileDlg(fname))
  150. {
  151. Mat src = imread(fname);
  152.  
  153. int height = src.rows;
  154. int width = src.cols;
  155.  
  156. Mat dst = Mat(height,width,CV_8UC1);
  157.  
  158. // Asa se acceseaaza pixelii individuali pt. o imagine RGB 24 biti/pixel
  159. // Varianta ineficienta (lenta)
  160. for (int i=0; i<height; i++)
  161. {
  162. for (int j=0; j<width; j++)
  163. {
  164. Vec3b v3 = src.at<Vec3b>(i,j);
  165. uchar b = v3[0];
  166. uchar g = v3[1];
  167. uchar r = v3[2];
  168. dst.at<uchar>(i,j) = (r+g+b)/3;
  169. }
  170. }
  171.  
  172. imshow("input image",src);
  173. imshow("gray image",dst);
  174. waitKey();
  175. }
  176. }
  177.  
  178. void testBGR2HSV()
  179. {
  180. char fname[MAX_PATH];
  181. while (openFileDlg(fname))
  182. {
  183. Mat src = imread(fname);
  184. int height = src.rows;
  185. int width = src.cols;
  186.  
  187. // Componentele d eculoare ale modelului HSV
  188. Mat H = Mat(height, width, CV_8UC1);
  189. Mat S = Mat(height, width, CV_8UC1);
  190. Mat V = Mat(height, width, CV_8UC1);
  191.  
  192. // definire pointeri la matricele (8 biti/pixeli) folosite la afisarea componentelor individuale H,S,V
  193. uchar* lpH = H.data;
  194. uchar* lpS = S.data;
  195. uchar* lpV = V.data;
  196.  
  197. Mat hsvImg;
  198. cvtColor(src, hsvImg, CV_BGR2HSV);
  199.  
  200. // definire pointer la matricea (24 biti/pixeli) a imaginii HSV
  201. uchar* hsvDataPtr = hsvImg.data;
  202.  
  203. for (int i = 0; i<height; i++)
  204. {
  205. for (int j = 0; j<width; j++)
  206. {
  207. int hi = i*width * 3 + j * 3;
  208. int gi = i*width + j;
  209.  
  210. lpH[gi] = hsvDataPtr[hi] * 510 / 360; // lpH = 0 .. 255
  211. lpS[gi] = hsvDataPtr[hi + 1]; // lpS = 0 .. 255
  212. lpV[gi] = hsvDataPtr[hi + 2]; // lpV = 0 .. 255
  213. }
  214. }
  215.  
  216. imshow("input image", src);
  217. imshow("H", H);
  218. imshow("S", S);
  219. imshow("V", V);
  220.  
  221. waitKey();
  222. }
  223. }
  224.  
  225. void testResize()
  226. {
  227. char fname[MAX_PATH];
  228. while(openFileDlg(fname))
  229. {
  230. Mat src;
  231. src = imread(fname);
  232. Mat dst1,dst2;
  233. //without interpolation
  234. resizeImg(src,dst1,320,false);
  235. //with interpolation
  236. resizeImg(src,dst2,320,true);
  237. imshow("input image",src);
  238. imshow("resized image (without interpolation)",dst1);
  239. imshow("resized image (with interpolation)",dst2);
  240. waitKey();
  241. }
  242. }
  243.  
  244. void testCanny()
  245. {
  246. char fname[MAX_PATH];
  247. while(openFileDlg(fname))
  248. {
  249. Mat src,dst,gauss;
  250. src = imread(fname,CV_LOAD_IMAGE_GRAYSCALE);
  251. double k = 0.4;
  252. int pH = 50;
  253. int pL = (int) k*pH;
  254. GaussianBlur(src, gauss, Size(5, 5), 0.8, 0.8);
  255. Canny(gauss,dst,pL,pH,3);
  256. imshow("input image",src);
  257. imshow("canny",dst);
  258. waitKey();
  259. }
  260. }
  261.  
  262. void testVideoSequence()
  263. {
  264. VideoCapture cap("Videos/rubic.avi"); // off-line video from file
  265. //VideoCapture cap(0); // live video from web cam
  266. if (!cap.isOpened()) {
  267. printf("Cannot open video capture device.\n");
  268. waitKey(0);
  269. return;
  270. }
  271.  
  272. Mat edges;
  273. Mat frame;
  274. char c;
  275.  
  276. while (cap.read(frame))
  277. {
  278. Mat grayFrame;
  279. cvtColor(frame, grayFrame, CV_BGR2GRAY);
  280. Canny(grayFrame,edges,40,100,3);
  281. imshow("source", frame);
  282. imshow("gray", grayFrame);
  283. imshow("edges", edges);
  284. c = cvWaitKey(0); // waits a key press to advance to the next frame
  285. if (c == 27) {
  286. // press ESC to exit
  287. printf("ESC pressed - capture finished\n");
  288. break; //ESC pressed
  289. };
  290. }
  291. }
  292.  
  293.  
  294. void testSnap()
  295. {
  296. VideoCapture cap(0); // open the deafult camera (i.e. the built in web cam)
  297. if (!cap.isOpened()) // openenig the video device failed
  298. {
  299. printf("Cannot open video capture device.\n");
  300. return;
  301. }
  302.  
  303. Mat frame;
  304. char numberStr[256];
  305. char fileName[256];
  306.  
  307. // video resolution
  308. Size capS = Size((int)cap.get(CV_CAP_PROP_FRAME_WIDTH),
  309. (int)cap.get(CV_CAP_PROP_FRAME_HEIGHT));
  310.  
  311. // Display window
  312. const char* WIN_SRC = "Src"; //window for the source frame
  313. namedWindow(WIN_SRC, CV_WINDOW_AUTOSIZE);
  314. cvMoveWindow(WIN_SRC, 0, 0);
  315.  
  316. const char* WIN_DST = "Snapped"; //window for showing the snapped frame
  317. namedWindow(WIN_DST, CV_WINDOW_AUTOSIZE);
  318. cvMoveWindow(WIN_DST, capS.width + 10, 0);
  319.  
  320. char c;
  321. int frameNum = -1;
  322. int frameCount = 0;
  323.  
  324. for (;;)
  325. {
  326. cap >> frame; // get a new frame from camera
  327. if (frame.empty())
  328. {
  329. printf("End of the video file\n");
  330. break;
  331. }
  332.  
  333. ++frameNum;
  334.  
  335. imshow(WIN_SRC, frame);
  336.  
  337. c = cvWaitKey(10); // waits a key press to advance to the next frame
  338. if (c == 27) {
  339. // press ESC to exit
  340. printf("ESC pressed - capture finished");
  341. break; //ESC pressed
  342. }
  343. if (c == 115){ //'s' pressed - snapp the image to a file
  344. frameCount++;
  345. fileName[0] = NULL;
  346. sprintf(numberStr, "%d", frameCount);
  347. strcat(fileName, "Images/A");
  348. strcat(fileName, numberStr);
  349. strcat(fileName, ".bmp");
  350. bool bSuccess = imwrite(fileName, frame);
  351. if (!bSuccess)
  352. {
  353. printf("Error writing the snapped image\n");
  354. }
  355. else
  356. imshow(WIN_DST, frame);
  357. }
  358. }
  359.  
  360. }
  361.  
  362. void MyCallBackFunc(int event, int x, int y, int flags, void* param)
  363. {
  364. //More examples: http://opencvexamples.blogspot.com/2014/01/detect-mouse-clicks-and-moves-on-image.html
  365. Mat* src = (Mat*)param;
  366. if (event == CV_EVENT_LBUTTONDOWN)
  367. {
  368. /*printf("Pos(x,y): %d,%d Color(RGB): %d,%d,%d\n",
  369. x, y,
  370. (int)(*src).at<Vec3b>(y, x)[2],
  371. (int)(*src).at<Vec3b>(y, x)[1],
  372. (int)(*src).at<Vec3b>(y, x)[0]);*/
  373. }
  374. }
  375.  
  376. void testMouseClick()
  377. {
  378. Mat src;
  379. // Read image from file
  380. char fname[MAX_PATH];
  381. while (openFileDlg(fname))
  382. {
  383. src = imread(fname);
  384. //Create a window
  385. namedWindow("My Window", 1);
  386.  
  387. //set the callback function for any mouse event
  388. setMouseCallback("My Window", MyCallBackFunc, &src);
  389.  
  390. //show the image
  391. imshow("My Window", src);
  392.  
  393. // Wait until user press some key
  394. waitKey(0);
  395. }
  396. }
  397.  
  398. /* Histogram display function - display a histogram using bars (simlilar to L3 / PI)
  399. Input:
  400. name - destination (output) window name
  401. hist - pointer to the vector containing the histogram values
  402. hist_cols - no. of bins (elements) in the histogram = histogram image width
  403. hist_height - height of the histogram image
  404. Call example:
  405. showHistogram ("MyHist", hist_dir, 255, 200);
  406. */
  407. void showHistogram(const std::string& name, int* hist, const int hist_cols, const int hist_height)
  408. {
  409. Mat imgHist(hist_height, hist_cols, CV_8UC3, CV_RGB(255, 255, 255)); // constructs a white image
  410.  
  411. //computes histogram maximum
  412. int max_hist = 0;
  413. for (int i = 0; i<hist_cols; i++)
  414. if (hist[i] > max_hist)
  415. max_hist = hist[i];
  416. double scale = 1.0;
  417. scale = (double)hist_height / max_hist;
  418. int baseline = hist_height - 1;
  419.  
  420. for (int x = 0; x < hist_cols; x++) {
  421. Point p1 = Point(x, baseline);
  422. Point p2 = Point(x, baseline - cvRound(hist[x] * scale));
  423. line(imgHist, p1, p2, CV_RGB(255, 0, 255)); // histogram bins colored in magenta
  424. }
  425.  
  426. imshow(name, imgHist);
  427. }
  428.  
  429. //************* lab 1 **************
  430.  
  431. void negative_image()
  432. {
  433. Mat img = imread("Images/cameraman.bmp",CV_LOAD_IMAGE_GRAYSCALE);
  434.  
  435. for (int i = 0; i<img.rows; i++) {
  436.  
  437. for (int j = 0; j<img.cols; j++) {
  438.  
  439. img.at<uchar>(i, j) = 255 - img.at<uchar>(i, j);
  440. }
  441. }
  442.  
  443. imshow("negative image", img);
  444. waitKey(0);
  445.  
  446. }
  447.  
  448. //Implementaţi o funcţie care schimbă nivelele de gri cu un factor aditiv
  449. void changeGray(int factor)
  450. {
  451. char fname[MAX_PATH];
  452. while (openFileDlg(fname))
  453. {
  454. Mat src;
  455.  
  456. src = imread(fname,CV_LOAD_IMAGE_GRAYSCALE);
  457. Mat img(src.rows, src.cols, CV_8UC1);
  458.  
  459. for (int i = 0; i < src.rows; i++)
  460. {
  461. for (int j = 0; j < src.cols; j++)
  462. {
  463.  
  464. if (src.at<uchar>(i, j) + factor > 255)
  465. {
  466. img.at<uchar>(i, j) = 255;
  467. }
  468. else {
  469. img.at<uchar>(i, j) =src.at<uchar>(i,j)+ factor;
  470. }
  471. }
  472. }
  473. imshow("Imagine", src);
  474. imshow("Imagine schimbata", img);
  475. waitKey(0);
  476. }
  477. }
  478.  
  479. //Implementaţi o funcţie care schimbă nivelele de gri cu un factor multiplicativ. Salvaţi
  480. //imaginea rezultat.
  481.  
  482. void changeGrayMulti(int factor)
  483. {
  484. char fname[MAX_PATH];
  485. while (openFileDlg(fname))
  486. {
  487. Mat src;
  488. src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
  489.  
  490. Mat img(src.rows, src.cols, CV_8UC1);
  491.  
  492. for (int i = 0; i < src.rows; i++)
  493. {
  494. for (int j = 0; j < src.cols; j++)
  495. {
  496.  
  497. if (src.at<uchar>(i, j) * factor > 255)
  498. {
  499. img.at<uchar>(i, j) = 255;
  500. }
  501. else {
  502. img.at<uchar>(i,j)=src.at<uchar>(i, j) * factor;
  503. }
  504. }
  505. }
  506. imshow("Imagine", src);
  507. imshow("Imagine schimbata", img);
  508. waitKey(0);
  509. imwrite("Imagine.png", img);
  510. }
  511. }
  512.  
  513.  
  514.  
  515. /*Creaţi o imagine color de dimensiune 256 x 256. Împărţiţi imaginea în 4 sectoare pătrate,
  516. şi coloraţi aceste sectoare, din stânga-sus până în dreapta-jos, astfel: alb, roşu, verde,
  517. galben.*/
  518.  
  519. void patruSectoare()
  520. {
  521. Mat img(256, 256, CV_8UC3);
  522.  
  523. for (int i = 0; i < img.rows; i++)
  524. {
  525. for (int j = 0; j < img.cols; j++)
  526. {
  527.  
  528. if (i < img.rows/2 && j < img.cols/2)
  529. {
  530. img.at<Vec3b>(i, j) = Vec3b(255, 255, 255);
  531. }
  532.  
  533. if (i<img.rows/2 && j>img.cols/2)
  534. {
  535. img.at<Vec3b>(i, j) = Vec3b(0, 0, 255);
  536. }
  537.  
  538. if (i>img.rows/2 && j<img.cols/2)
  539. {
  540. img.at<Vec3b>(i, j) = Vec3b(0, 255,0);
  541. }
  542.  
  543. if (i>img.rows/2 && j>img.cols/2)
  544. {
  545. img.at<Vec3b>(i, j) = Vec3b(0, 255, 255);
  546. }
  547.  
  548. }
  549. }
  550.  
  551. imshow("Imagine", img);
  552. waitKey(0);
  553.  
  554. }
  555.  
  556. void inv()
  557. {
  558.  
  559.  
  560. }
  561.  
  562. //***************** LAB 2 *************************
  563. void copiazaCanale()
  564. {
  565.  
  566. char fname[MAX_PATH];
  567. while (openFileDlg(fname))
  568. {
  569. Mat src;
  570.  
  571. src = imread(fname,CV_LOAD_IMAGE_COLOR);
  572. Mat img1(src.rows, src.cols, CV_8UC1);
  573. Mat img2(src.rows, src.cols, CV_8UC1);
  574. Mat img3(src.rows, src.cols, CV_8UC1);
  575.  
  576. for (int i = 0; i < src.rows; i++)
  577. {
  578. for (int j = 0; j < src.cols; j++)
  579. {
  580. img1.at<uchar>(i, j) = src.at<Vec3b>(i, j)[2];
  581. img2.at<uchar>(i, j) = src.at<Vec3b>(i, j)[1];
  582. img3.at<uchar>(i, j) = src.at<Vec3b>(i, j)[0];
  583. }
  584. }
  585.  
  586. imshow("Imagine", src);
  587. imshow("Imagine1", img1);
  588. imshow("Imagine2", img2);
  589. imshow("Imagine3", img3);
  590. waitKey(0);
  591.  
  592. }
  593.  
  594. }
  595.  
  596. void colorToGray()
  597. {
  598. char fname[MAX_PATH];
  599. while (openFileDlg(fname))
  600. {
  601. Mat src;
  602.  
  603. src = imread(fname, CV_LOAD_IMAGE_COLOR);
  604. Mat an(src.rows, src.cols, CV_8UC1);
  605. for (int i = 0; i < src.rows; i++)
  606. {
  607. for (int j = 0; j < src.cols; j++)
  608. {
  609. an.at<uchar>(i, j) = (src.at<Vec3b>(i, j)[0] + src.at<Vec3b>(i, j)[1] + src.at<Vec3b>(i, j)[2]) / 3;
  610. }
  611. }
  612.  
  613. imshow("Imagine", src);
  614. imshow("GreyScale", an);
  615. waitKey(0);
  616.  
  617. }
  618. }
  619.  
  620. void grayToALb()
  621. {
  622. char fname[MAX_PATH];
  623. while (openFileDlg(fname))
  624. {
  625. Mat src;
  626.  
  627. src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
  628. int prag;
  629. std::cout << " Prag: " << std::endl;
  630. std::cin >> prag;
  631.  
  632. Mat an(src.rows, src.cols, CV_8UC1);
  633. for (int i = 0; i < src.rows; i++)
  634. {
  635. for (int j = 0; j < src.cols; j++)
  636. {
  637. if (src.at<uchar>(i, j) < prag)
  638. {
  639. an.at<uchar>(i, j) = 0;
  640. }
  641.  
  642. if (src.at<uchar>(i, j) >= prag)
  643. {
  644. an.at<uchar>(i, j) = 255;
  645. }
  646.  
  647. }
  648. }
  649.  
  650. imshow("Imagine", src);
  651. imshow("Alb-Negru", an);
  652. }
  653. }
  654.  
  655.  
  656. void convertHSV()
  657. {
  658. float r, g, b, R, G, B, m, M,C, H, S, V;
  659. char fname[MAX_PATH];
  660. while (openFileDlg(fname))
  661. {
  662. Mat src;
  663.  
  664. src = imread(fname, CV_LOAD_IMAGE_COLOR);
  665. Mat img1(src.rows, src.cols, CV_8UC1);
  666. Mat img2(src.rows, src.cols, CV_8UC1);
  667. Mat img3(src.rows, src.cols, CV_8UC1);
  668.  
  669. for (int i = 0; i < src.rows; i++)
  670. {
  671. for (int j = 0; j < src.cols; j++)
  672. {
  673. R = (float)src.at<Vec3b>(i, j)[2];
  674. r = R / 255;
  675.  
  676. B = (float)src.at<Vec3b>(i, j)[0];
  677. b = B / 255;
  678.  
  679. G = (float)src.at<Vec3b>(i, j)[1];
  680. g = G / 255;
  681.  
  682. M = max(r, g, b);
  683. m = min(r, g, b);
  684. C = M - m;
  685.  
  686. V = M;
  687. if (V != 0) S = C / V;
  688. else S = 0;
  689.  
  690. if (C != 0){
  691. if (M == r) H = 60 * (g - b) / C;
  692. if (M == g) H = 120 + 60 * (b - r) / C;
  693. if (M == b) H = 240 + 60 * (r - g) / C;
  694. }
  695. else H = 0;
  696. if (H < 0) H = H + 360;
  697.  
  698. img1.at<uchar>(i, j) = H * 255 / 360;
  699. img2.at<uchar>(i, j) = S * 255;
  700. img3.at<uchar>(i, j) = V * 255;
  701. }
  702. }
  703.  
  704. imshow("Imagine", src);
  705. imshow("Hue", img1);
  706. imshow("Saturation", img2);
  707. imshow("Value", img3);
  708. waitKey(0);
  709. }
  710.  
  711. }
  712.  
  713. void isInside(Mat img, int i,int j)
  714. {
  715. if (img.rows > i && i >= 0)
  716.  
  717. if (img.cols > j && j >= 0)
  718.  
  719. std::cout << "SE AFLA IN INTERIOR";
  720.  
  721. getchar();
  722. getchar();
  723. }
  724.  
  725.  
  726. //***************** LAB 3 *************
  727.  
  728. void DrawCross(Mat& img, Point p, int size, Scalar color, int thickness)
  729. {
  730. line(img, Point(p.x - size / 2, p.y), Point(p.x + size / 2, p.y), color, thickness, 8);
  731. line(img, Point(p.x, p.y - size / 2), Point(p.x, p.y + size / 2), color, thickness, 8);
  732. }
  733.  
  734.  
  735. void proprietati(int event, int x, int y, int flags, void* param)
  736. {
  737. //More examples: http://opencvexamples.blogspot.com/2014/01/detect-mouse-clicks-and-moves-on-image.html
  738. Mat* src = (Mat*)param;
  739. Vec3b culoare;
  740. int aria = 0;
  741. int ri = 0;
  742. int ci = 0;
  743. int perim = 0;
  744. float phi = 0;
  745. int factor = 0;
  746. int a = 0, a1 = 0, a2 = 0;
  747. int rmax = 0,cmax=0;
  748. int rmin = (*src).rows;
  749. int cmin = (*src).cols;
  750.  
  751. Mat img1((*src).rows, (*src).cols, CV_8UC3);
  752.  
  753. for (int i = 0; i < (*src).rows; i++)
  754. {
  755. for (int j = 0; j < (*src).cols; j++)
  756. {
  757. img1.at<Vec3b>(i, j) = (*src).at<Vec3b>(i, j);
  758. }
  759. }
  760.  
  761.  
  762. if (event == CV_EVENT_LBUTTONDOWN)
  763. {
  764.  
  765. culoare = (*src).at<Vec3b>(y, x);
  766.  
  767.  
  768. for (int i = 0; i < (*src).rows; i++)
  769. {
  770. for (int j = 0; j < (*src).cols; j++)
  771. {
  772. if ((*src).at<Vec3b>(i,j) == culoare)
  773. {
  774. if (i >= rmax)
  775. {
  776. rmax = i;
  777. }
  778. else if (i <= rmin)
  779. {
  780. rmin = i;
  781. }
  782. if (j>=cmax)
  783. {
  784. cmax = j;
  785. }
  786. else if (j <= cmin)
  787. {
  788. cmin = j;
  789. }
  790. aria++;
  791. ri += i;
  792. ci += j;
  793. }
  794. }
  795. }
  796. ri = ri/aria;
  797. ci = ci/ aria;
  798.  
  799. for (int i = 0; i < (*src).rows; i++)
  800. {
  801. for (int j = 0; j < (*src).cols; j++)
  802. {
  803. if ((*src).at<Vec3b>(i, j) == culoare)
  804. {
  805. a += (i - ri)*(j - ci);
  806. a1 += (j - ci)*(j - ci);
  807. a2 += (i - ri)*(i - ri);
  808. }
  809. }
  810. }
  811.  
  812. phi = atan2(2*a, (a1 - a2))/2;
  813.  
  814. for (int i = 0; i < (*src).rows; i++)
  815. {
  816. for (int j = 0; j < (*src).cols; j++)
  817. {
  818. if ((*src).at<Vec3b>(i, j) == culoare)
  819. {
  820. if ((*src).at<Vec3b>(i - 1, j - 1) != culoare || (*src).at<Vec3b>(i - 1, j) != culoare
  821. || (*src).at<Vec3b>(i - 1, j + 1) != culoare || (*src).at<Vec3b>(i, j - 1) != culoare
  822. || (*src).at<Vec3b>(i, j + 1) != culoare || (*src).at<Vec3b>(i + 1, j) != culoare
  823. || (*src).at<Vec3b>(i + 1, j - 1) != culoare || (*src).at<Vec3b>(i + 1, j + 1) != culoare){
  824. perim++;
  825. img1.at<Vec3b>(i, j) = Vec3b(0, 0, 0);
  826.  
  827. }
  828. }
  829. }
  830.  
  831.  
  832. }
  833.  
  834.  
  835.  
  836. float factor = 4 *PI*aria / (perim*perim);
  837. float aspect = (cmax - cmin + 1) / (rmax - rmin + 1);
  838.  
  839. DrawCross(img1, Point(ci, ri), 20, Scalar(255, 255, 255), 2);
  840.  
  841. int delta = 30; // arbitrary value
  842. Point P1, P2;
  843. P1.x = ci - delta;
  844. P1.y = ri - (int)(delta*tan(phi)); // teta is the elongation angle in radians
  845. P2.x = ci + delta;
  846. P2.y = ri + (int)(delta*tan(phi));
  847. line(img1, P1, P2, Scalar(0, 0, 0), 1, 8);
  848.  
  849.  
  850. std::cout << "Aria este : " << aria << std::endl;
  851. std::cout << " Centrul de masa este: " << ri << " + " << ci << std::endl;
  852. std::cout << "Axa de alungire : " << phi*180/PI<< std::endl;
  853. std::cout << "Perimetru este : " << perim << std::endl;
  854. std::cout << "Subtiere : " << factor<< std::endl;
  855. std::cout << " Aspect ratio : " << aspect<< std::endl;
  856.  
  857.  
  858. /*Mat dest((*src).rows, (*src).cols, CV_8UC3);
  859. int x_vec[500] = {0};
  860. int y_vec[500] = {0};
  861. for (int i = 0; i < (*src).rows; i++) {
  862. int value = 0;
  863. for (int j = 0; j < (*src).cols; j++) {
  864.  
  865. if ((*src).at<Vec3b>(i, j) == culoare) {
  866. value++;
  867. }
  868. }
  869. x_vec[i] = value;
  870. }
  871.  
  872.  
  873. for (int i = 0; i < (*src).cols; i++) {
  874. int value = 0;
  875. for (int j = 0; j < (*src).rows; j++) {
  876. if ((*src).at<Vec3b>( j,i) == culoare) {
  877. value++;
  878. }
  879. }
  880. y_vec[i] = value;
  881. }
  882.  
  883.  
  884.  
  885. h[i] = value; k < dest.cols; k++) {
  886. line(dest, Point(k, 0), Point(k, y_vec[k]), 5);
  887. }
  888. for (int k = 0; k < dest.rows; k++) {
  889. line(dest, Point(k, 0), Point(k, x_vec[k]), 5);
  890. }*/
  891.  
  892.  
  893. Mat dst2 = (*src).clone();
  894. Mat proj = Mat((*src).size(), CV_8UC3);
  895.  
  896. int horizontalProj[1000] = { 0 };
  897. int verticalProj[1000] = { 0 };
  898.  
  899.  
  900. for (int i = 0; i < dst2.rows; i++) {
  901. for (int j = 0; j < dst2.cols; j++) {
  902. if (dst2.at<Vec3b>(i, j)==culoare) {
  903. horizontalProj[j]++;
  904. verticalProj[i]++;
  905. }
  906. }
  907. }
  908.  
  909. for (int j = 0; j < dst2.cols; j++) {
  910. line(proj, Point(j, 0), Point(j, horizontalProj[j]), Scalar(255, 255, 255), 3);
  911. }
  912.  
  913. for (int i = 0; i < dst2.rows; i++) {
  914. line(proj, Point(0, i), Point(verticalProj[i], i), Scalar(255, 255, 255), 3);
  915. }
  916.  
  917.  
  918. imshow("Proiectii", proj);
  919.  
  920.  
  921.  
  922.  
  923.  
  924. imshow("Perimetru", img1);
  925.  
  926.  
  927.  
  928.  
  929.  
  930.  
  931.  
  932. }
  933.  
  934.  
  935. //imshow("1", img1);
  936. //waitKey(0);
  937. }
  938.  
  939. void testMouseClickProprietati()
  940. {
  941. Mat src;
  942. // Read image from file
  943.  
  944. src = imread("Obiecte multiple\\trasaturi_geom.bmp",CV_LOAD_IMAGE_COLOR);
  945. //Create a window
  946. namedWindow("My Window", 1);
  947.  
  948. //set the callback function for any mouse event
  949. setMouseCallback("My Window", proprietati, &src);
  950.  
  951. //show the image
  952. imshow("My Window", src);
  953.  
  954. // Wait until user press some key
  955. waitKey(0);
  956. }
  957.  
  958. /////////////////// LAB 5 ////////////////////
  959.  
  960. void traversare()
  961. {
  962. Mat src = imread("Images/labeling2.bmp", CV_LOAD_IMAGE_GRAYSCALE);
  963. Mat labels = Mat::zeros(src.rows, src.cols, CV_16SC1);
  964. Mat dst = Mat::zeros(src.rows, src.cols, CV_8UC3);
  965.  
  966. int di[8] = {-1, 0, 1, 0 ,1,-1,1,-1};
  967. int dj[8] = { 0, -1, 0, 1 ,1,1,-1,-1};
  968.  
  969.  
  970.  
  971.  
  972. int label = 0;
  973.  
  974. for (int i = 0; i < src.rows; i++)
  975. {
  976. for (int j = 0; j < src.cols; j++)
  977. {
  978. if (src.at<uchar>(i, j) == 0 && labels.at<short>(i, j) == 0)
  979. { std::queue<Point2i> Q;
  980. label++;
  981. Q.push({i, j});
  982. labels.at<short>(i, j) = label;
  983. while (!Q.empty())
  984. {
  985. Point q = Q.front();
  986. Q.pop();
  987. for (int k = 0; k < 8; k++)
  988. {
  989. if ( src.at<uchar>(q.x + di[k], q.y + dj[k]) == 0 && labels.at<short>(q.x + di[k], q.y + dj[k]) == 0)
  990. {
  991. labels.at<short>(q.x + di[k], q.y + dj[k]) = label;
  992. Q.push({ q.x + di[k], q.y + dj[k] });
  993. }
  994. }
  995. }
  996. }
  997. }
  998. }
  999.  
  1000. Scalar colorLUT[1000] = { 0 };
  1001. Scalar color;
  1002. for (int i = 1; i < 1000; i++)
  1003. {
  1004. Scalar color(rand() & 255, rand() & 255, rand() & 255);
  1005. colorLUT[i] = color;
  1006. }
  1007. colorLUT[0] = Scalar(255, 255, 255);
  1008. for (int i = 1; i < dst.rows - 1; i++)
  1009. for (int j = 1; j < dst.cols - 1; j++)
  1010. {
  1011. Scalar color = colorLUT[labels.at<short>(i, j)]; // valabil pt. Met. 1 BFS
  1012. dst.at<Vec3b>(i, j)[0] = color[0];
  1013. dst.at<Vec3b>(i, j)[1] = color[1];
  1014. dst.at<Vec3b>(i, j)[2] = color[2];
  1015. }
  1016.  
  1017. imshow("img", dst);
  1018. waitKey(0);
  1019.  
  1020.  
  1021.  
  1022.  
  1023. }
  1024.  
  1025. void alg2()
  1026. {
  1027. Mat src = imread("Images/labeling2.bmp", CV_LOAD_IMAGE_GRAYSCALE);
  1028. Mat labels = Mat::zeros(src.rows, src.cols, CV_16SC1);
  1029. Mat dstP = Mat::zeros(src.rows, src.cols, CV_8UC3);
  1030. Mat dstF = Mat::zeros(src.rows, src.cols, CV_8UC3);
  1031.  
  1032. int di[4] = { -1,-1,-1,0 };
  1033. int dj[4] = { -1,0,1,-1 };
  1034.  
  1035. int label = 0;
  1036.  
  1037. std::vector<std::vector<int>> edges;
  1038.  
  1039. for (int i = 0; i < src.rows; i++)
  1040. {
  1041. for (int j = 0; j < src.cols; j++)
  1042. {
  1043. if (src.at<uchar>(i, j) == 0 && labels.at<short>(i, j) == 0)
  1044. {
  1045. std::vector<int> L;
  1046. for (int k = 0; k < 4; k++)
  1047. {
  1048. if (labels.at<short>(i + di[k], j + dj[k]) > 0)
  1049. {
  1050. L.push_back(labels.at<short>(i + di[k], j + dj[k]));
  1051. }
  1052. }
  1053. if (L.size() == 0)
  1054. {
  1055. label++;
  1056. labels.at<short>(i, j) = label;
  1057. }
  1058. else
  1059. {
  1060. int x = *min_element(L.begin(), L.end());
  1061. labels.at<short>(i, j) = x;
  1062. for (int y :L)
  1063. {
  1064. if (L[y] != x)
  1065. {
  1066. edges.resize(label + 1);
  1067. edges[x].push_back(y);
  1068. edges[y].push_back(x);
  1069.  
  1070. }
  1071. }
  1072. }
  1073. }
  1074. }
  1075. }
  1076.  
  1077.  
  1078. int newlabel = 0;
  1079.  
  1080. int* newlabels = (int*)calloc(label+1, sizeof(int));
  1081. for (int i = 1; i <= label; i++)
  1082. {
  1083. if (newlabels[i] == 0)
  1084. {
  1085. newlabel++;
  1086. std::queue<int> Q;
  1087. newlabels[i] = newlabel;
  1088. Q.push(i);
  1089. while (!Q.empty())
  1090. {
  1091. int x = Q.front();
  1092. Q.pop();
  1093. for (int t:edges[x])
  1094. {
  1095.  
  1096. if (newlabels[t] == 0)
  1097. {
  1098. newlabels[t] = newlabel;
  1099. Q.push(t);
  1100. }
  1101. }
  1102. }
  1103. }
  1104. }
  1105.  
  1106.  
  1107.  
  1108.  
  1109. free(newlabels);
  1110.  
  1111. }
  1112.  
  1113. ////////////////// LAB 6 ////////////////////////////////
  1114.  
  1115.  
  1116.  
  1117.  
  1118. typedef struct {
  1119. int i, j; // coordonata pixelului de contur
  1120. byte c; //codul inlantuit
  1121. }point;
  1122.  
  1123.  
  1124. void border()
  1125. {
  1126. char fname[MAX_PATH];
  1127. while (openFileDlg(fname))
  1128. {
  1129. int dj[8] = { 1, 1, 0, -1, -1, -1, 0, 1 }; // rand (coordonata orizontala)
  1130. int di[8] = { 0, -1, -1, -1, 0, 1, 1, 1 }; // coloana (coordonata verticala)
  1131.  
  1132. Mat src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
  1133. int height = src.rows;
  1134. int width = src.cols;
  1135.  
  1136. Mat dst = Mat(height, width, CV_8UC1, Scalar(255));
  1137.  
  1138.  
  1139. std::vector <point> contur;
  1140. Point start;
  1141. bool primul = false;
  1142. for (int i = 0; (i < height) && primul == false; i++)
  1143. {
  1144. for (int j = 0; j < width; j++)
  1145. {
  1146. if (src.at<uchar>(i, j) == 0)
  1147. {
  1148. dst.at<uchar>(i, j) = 0;
  1149. start = { i, j };
  1150. primul = true;
  1151. break;
  1152.  
  1153. }
  1154. }
  1155.  
  1156. }
  1157. int dir = 7;
  1158. contur.push_back(point{ start.x, start.y,7 });
  1159. int n = 0;
  1160. bool finish = false;
  1161.  
  1162. int i = start.x;
  1163. int j = start.y;
  1164.  
  1165.  
  1166. while (!finish)
  1167. {
  1168.  
  1169. if (dir % 2 == 0) {
  1170. dir = (dir + 7) % 8;
  1171. }else
  1172. {
  1173. dir = (dir + 6) % 8;
  1174.  
  1175. }
  1176.  
  1177.  
  1178.  
  1179. while(src.at<uchar>(i+di[dir],j+dj[dir])!=0)
  1180. {
  1181.  
  1182. dir = dir + 1;
  1183. if (dir == 8) {
  1184. dir = 0;
  1185. }
  1186. }
  1187.  
  1188. contur.push_back(point{ i + di[dir], j + dj[dir], (byte)dir });
  1189. i += di[dir];
  1190. j += dj[dir];
  1191.  
  1192.  
  1193. n++;
  1194.  
  1195. if (n > 2 && contur.at(0).i == contur.at(n - 1).i && contur.at(0).j == contur.at(n - 1).j && contur.at(1).i == contur.at(n).i && contur.at(1).j == contur.at(n).j) {
  1196. finish = true;
  1197. }
  1198. }
  1199.  
  1200. int d;
  1201. printf("cod inlantuit: ");
  1202. for (int i = 1; i < contur.size() - 1; i++)
  1203. {
  1204.  
  1205. dst.at<uchar>(contur.at(i).i, contur.at(i).j) = 0;
  1206. printf("%d ", contur.at(i).c);
  1207.  
  1208. }
  1209. printf("\n\n");
  1210.  
  1211. printf("derivata : ");
  1212.  
  1213. for (int i = 0; i < contur.size() - 1; i++)
  1214. {
  1215.  
  1216. //calcularea derivatei
  1217. d = (8 + contur.at(i + 1).c - contur.at(i).c) % 8;
  1218. printf("%d ", d);
  1219. }
  1220.  
  1221. printf("\n\n");
  1222.  
  1223. imshow("contur imagine", dst);
  1224. waitKey(0);
  1225. }
  1226.  
  1227. }
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234. void reconstruct()
  1235. {
  1236. FILE* fp = fopen("Images/reconstruct.txt", "rt");
  1237. if (!fp)
  1238. {
  1239. printf("Error opening the text file!\n");
  1240. }
  1241.  
  1242. int x, y, N, v;
  1243. fscanf(fp, "%d", &x);
  1244. fscanf(fp, "%d", &y);
  1245. fscanf(fp, "%d", &N);
  1246.  
  1247. std::vector<int> vectorint;
  1248.  
  1249. for (int i = 0; i < N; i++)
  1250. {
  1251. fscanf(fp, "%d", &v);
  1252. vectorint.push_back(v);
  1253. }
  1254.  
  1255. printf("%d %d \n %d \n", x, y, N);
  1256.  
  1257.  
  1258. Mat img = imread("Images/gray_background.bmp", CV_LOAD_IMAGE_GRAYSCALE);
  1259. Mat dst = Mat(img.rows, img.cols, CV_8UC1, Scalar(255));
  1260.  
  1261.  
  1262. int dj[8] = { 1, 1, 0, -1, -1, -1, 0, 1 }; // rand (coordonata orizontala)
  1263. int di[8] = { 0, -1, -1, -1, 0, 1, 1, 1 }; // coloana (coordonata verticala)
  1264.  
  1265.  
  1266. for (int i = 0; i < vectorint.size(); i++)
  1267. {
  1268. dst.at<uchar>(x, y) = 0;
  1269. x += di[vectorint.at(i)];
  1270. y += dj[vectorint.at(i)];
  1271.  
  1272.  
  1273. }
  1274. imshow("dst", dst);
  1275. waitKey(0);
  1276.  
  1277.  
  1278. }
  1279.  
  1280. /////////////////////////// LAB 7 /////////////////////
  1281.  
  1282. Mat dilatare(Mat src)
  1283. {
  1284.  
  1285. Mat dst = src.clone();
  1286. int dj[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
  1287. int di[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
  1288.  
  1289. for (int i = 1; i < src.rows - 1; i++)
  1290. {
  1291. for (int j = 1; j < src.cols - 1; j++)
  1292. {
  1293. if (src.at<uchar>(i, j) == 0)
  1294. for (int l = 0; l < 8; l++)
  1295. {
  1296. dst.at<uchar>(di[l] + i, dj[l] + j) = 0;
  1297. }
  1298. }
  1299.  
  1300. }
  1301.  
  1302. imshow("Imagine dilatata", dst);
  1303.  
  1304. waitKey(0);
  1305. return dst;
  1306. }
  1307.  
  1308. Mat eroziune(Mat src)
  1309. {
  1310. Mat dst = src.clone();
  1311. int dj[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
  1312. int di[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
  1313.  
  1314. for (int i = 1; i < src.rows - 1; i++)
  1315. {
  1316. for (int j = 1; j < src.cols - 1; j++)
  1317. {
  1318. if (src.at<uchar>(i, j) == 0)
  1319. for (int l = 0; l < 8; l++)
  1320. {
  1321. if (src.at<uchar>(di[l] + i, dj[l] + j) == 255){
  1322. dst.at<uchar>(i, j) = 255;
  1323. break;
  1324.  
  1325. }
  1326. }
  1327. }
  1328. }
  1329. imshow("Imagine erodata", dst);
  1330.  
  1331. waitKey(0);
  1332. return dst;
  1333.  
  1334. }
  1335.  
  1336. Mat inchidere(Mat src)
  1337. {
  1338.  
  1339. Mat dilatata = dilatare(src);
  1340.  
  1341. Mat erodata = eroziune(dilatata);
  1342.  
  1343. imshow("Imagine finala",erodata);
  1344. waitKey(0);
  1345. return erodata;
  1346.  
  1347. }
  1348.  
  1349. void inchidereapelNori(int n)
  1350. {
  1351. Mat src = imread("Images/4_Close/phn1thr1_bw.bmp", 0);
  1352. imshow("src", src);
  1353. getchar();
  1354.  
  1355.  
  1356. for (int i = 0; i < n; i++)
  1357. {
  1358. src = inchidere(src);
  1359. }
  1360. imshow("Final", src);
  1361. waitKey(0);
  1362. }
  1363.  
  1364. Mat deschidere(Mat src)
  1365. {
  1366.  
  1367.  
  1368. Mat erodata = eroziune(src);
  1369. Mat dilatata = dilatare(erodata);
  1370. imshow("Imagine finala", dilatata);
  1371. //imshow("Imagine originala", src);
  1372.  
  1373. waitKey(0);
  1374. return erodata;
  1375. }
  1376.  
  1377. void deschhidereapelNori(int n)
  1378. {
  1379. Mat src = imread("Images/3_Open/cel4thr3_bw.bmp", 0);
  1380. imshow("src", src);
  1381.  
  1382.  
  1383.  
  1384. for (int i = 0; i < n; i++)
  1385. {
  1386. src = deschidere(src);
  1387. }
  1388. imshow("Final", src);
  1389. waitKey(0);
  1390. }
  1391.  
  1392. void dilatare_apelNori(int n)
  1393. {
  1394. Mat src = imread("Images/1_Dilate/mon1thr1_bw.bmp", 0);
  1395. imshow("src", src);
  1396.  
  1397.  
  1398. for (int i = 0; i < n; i++)
  1399. {
  1400. src = dilatare(src);
  1401. }
  1402. imshow("Final", src);
  1403. waitKey(0);
  1404.  
  1405. }
  1406.  
  1407. void eroziune_apelNori(int n)
  1408. {
  1409. Mat src = imread("Images/1_Dilate/mon1thr1_bw.bmp", 0);
  1410. imshow("src", src);
  1411.  
  1412.  
  1413. for (int i = 0; i < n; i++)
  1414. {
  1415. src = eroziune(src);
  1416. }
  1417. imshow("Final", src);
  1418. waitKey(0);
  1419. }
  1420. void contur()
  1421. {
  1422. Mat src = imread("Images/5_BoundaryExtraction/wdg2thr3_bw.bmp", 0);
  1423. Mat dst = src.clone();
  1424. imshow("src", src);
  1425. Mat temp = eroziune(src);
  1426.  
  1427.  
  1428. for (int i = 0; i < src.rows; i++)
  1429. {
  1430. for (int j = 0; j < src.cols; j++)
  1431. {
  1432. if (src.at<uchar>(i, j) != temp.at<uchar>(i, j))
  1433. dst.at<uchar>(i, j) = 0;//FG
  1434. else dst.at<uchar>(i, j) = 255;//BG
  1435. }
  1436. }
  1437.  
  1438. imshow("Imagine originala", src);
  1439. imshow("Contur", dst);
  1440. waitKey(0);
  1441. }
  1442.  
  1443. void umplere_regiuni(int x, int y)
  1444. {
  1445.  
  1446. Mat src = imread("Images/6_RegionFilling/reg1neg1_bw.bmp", 0);
  1447. Mat compl = Mat(src.rows, src.cols, CV_8UC1, Scalar(255));
  1448. Mat X1 = Mat(src.rows, src.cols, CV_8UC1, Scalar(255));
  1449. Mat X2 = Mat(src.rows, src.cols, CV_8UC1, Scalar(255));
  1450. Mat dst = Mat(src.rows, src.cols, CV_8UC1, Scalar(255));
  1451. Mat temp;
  1452. bool finish = false;
  1453.  
  1454.  
  1455.  
  1456. for (int i = 0; i < src.rows; i++)
  1457. {
  1458. for (int j = 0; j < src.cols; j++)
  1459. {
  1460. compl.at<uchar>(i, j) = 255 - src.at<uchar>(i, j);
  1461. }
  1462. }
  1463.  
  1464.  
  1465.  
  1466.  
  1467. for (int i = 0; i < src.rows; i++)
  1468. {
  1469. for (int j = 0; j < src.cols; j++)
  1470. {
  1471. if (i == x&&y == j)
  1472. {
  1473. X1.at<uchar>(i, j) = 0;
  1474. }
  1475. }
  1476. }
  1477.  
  1478.  
  1479.  
  1480. do
  1481. {
  1482. finish = true;
  1483. temp = dilatare(X1);
  1484.  
  1485.  
  1486. for (int i = 0; i < src.rows; i++)
  1487. {
  1488. for (int j = 0; j < src.cols; j++)
  1489. {
  1490. if (temp.at<uchar>(i, j) == compl.at<uchar>(i, j))
  1491. {
  1492. X2.at<uchar>(i, j) = temp.at<uchar>(i, j);
  1493. }
  1494. else
  1495. {
  1496. X2.at<uchar>(i, j) = 255;
  1497. }
  1498. }
  1499. }
  1500. for (int i = 0; i < src.rows; i++)
  1501. {
  1502. for (int j = 0; j < src.cols; j++)
  1503. {
  1504. if (X1.at<uchar>(i, j) != X2.at<uchar>(i, j))
  1505. {
  1506. finish = false;
  1507. break;
  1508. }
  1509.  
  1510. }
  1511. }
  1512.  
  1513. X1 = X2.clone();
  1514.  
  1515. } while (!finish);
  1516.  
  1517. for (int i = 0; i < src.rows; i++)
  1518. {
  1519. for (int j = 0; j < src.cols; j++)
  1520. {
  1521. if (X2.at<uchar>(i, j) == 0 || src.at<uchar>(i, j) == 0)
  1522. {
  1523. dst.at<uchar>(i, j) = 0;
  1524. }
  1525. }
  1526. }
  1527. imshow("src", src);
  1528. imshow("complement", compl);
  1529. imshow("Final", dst);
  1530. waitKey(0);
  1531. }
  1532.  
  1533. ///////////////////////////////////// LAB 8//////////////////////////
  1534.  
  1535. int* calculHistograma(Mat img) {
  1536.  
  1537. int *hist = (int*)malloc(sizeof(int) * 256);
  1538.  
  1539. for (int i = 0; i < 256; i++)
  1540. hist[i] = 0;
  1541.  
  1542. for (int i = 0; i < img.rows; i++)
  1543. for (int j = 0; j < img.cols; j++)
  1544. hist[img.at<uchar>(i, j)]++;
  1545.  
  1546. return hist;
  1547. }
  1548.  
  1549. void calcule(Mat img) {
  1550.  
  1551. int M = img.rows * img.cols;
  1552.  
  1553. int* hist = calculHistograma(img);
  1554.  
  1555. showHistogram("histogram", hist, 256, 200);
  1556.  
  1557. // niv maxim de intensitate
  1558. int L = 255;
  1559.  
  1560. float fdp[256];
  1561.  
  1562. for (int i = 0; i <= L; i++)
  1563. fdp[i] = 0;
  1564.  
  1565.  
  1566. for (int g = 0; g <= L; g++)
  1567. fdp[g] = (float)hist[g] / M;
  1568.  
  1569. for (int g = 0; g <= L; g++)
  1570. printf("%f.", fdp[g]);
  1571.  
  1572. // val medie a niv de intensitate
  1573. float medie = 0.0;
  1574. for (int g = 0; g <= L; g++)
  1575. medie += fdp[g] * g;
  1576.  
  1577. // deviatie standard
  1578. float deviatie = 0.0;
  1579. for (int g = 0; g <= L; g++)
  1580. deviatie += pow(g - medie, 2) * fdp[g];
  1581. deviatie = sqrt(deviatie);
  1582.  
  1583. printf("Valoare medie: %f.\n", medie);
  1584. printf("Deviatie standard: %f.\n", deviatie);
  1585. }
  1586.  
  1587. void testHistograma()
  1588. {
  1589. char fname[MAX_PATH];
  1590.  
  1591. while (openFileDlg(fname)) {
  1592. Mat img = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
  1593.  
  1594. int* histograma = calculHistograma(img);
  1595.  
  1596. showHistogram("histogram", histograma, 256, 200);
  1597. imshow("src", img);
  1598. waitKey(0);
  1599. }
  1600.  
  1601.  
  1602. }
  1603.  
  1604. void testHistogramaFDP() {
  1605.  
  1606. Mat img = imread("Images/balloons.bmp", CV_LOAD_IMAGE_GRAYSCALE);
  1607.  
  1608. imshow("src", img);
  1609.  
  1610. calcule(img);
  1611.  
  1612. waitKey(0);
  1613.  
  1614. }
  1615.  
  1616. void pragBinarizare(Mat img) {
  1617.  
  1618. // nr de pixeli ai imaginii
  1619. int M = img.rows * img.cols;
  1620.  
  1621. int* hist = calculHistograma(img);
  1622.  
  1623. showHistogram("histogram", hist, 256, 200);
  1624.  
  1625. // fdp
  1626. float fdp[256] = {};
  1627.  
  1628. for (int g = 0; g < 256; g++)
  1629. fdp[g] = (float)hist[g] / M;
  1630.  
  1631. float T;
  1632. int iMin = 0, iMax = 256;
  1633.  
  1634. T = (iMax + iMin) / 2.0;
  1635.  
  1636. float Tn;
  1637.  
  1638. do
  1639. {
  1640. int Nmic = 0, Nmare = 0;
  1641. float medieMica = 0, medieMare = 0;
  1642.  
  1643. for (int g = 0; g <= T; g++)
  1644. Nmic += hist[g];
  1645. for (int g = 255; g > T; g--)
  1646. Nmare += hist[g];
  1647.  
  1648. for (int g = 0; g <= T; g++)
  1649. medieMica += hist[g] * g;
  1650. for (int g = 255; g > T; g--)
  1651. medieMare += hist[g] * g;
  1652.  
  1653. Tn = T;
  1654. float min = medieMica / Nmic;
  1655. float max = medieMare / Nmare;
  1656. T = (min +max) / 2.0;
  1657.  
  1658. } while (abs(Tn - T) > 0.5);
  1659.  
  1660. printf("Prag de binarizare: %f.\n", T);
  1661.  
  1662. Mat dest = img.clone();
  1663. for (int i = 0; i < img.rows; i++)
  1664. for (int j = 0; j < img.cols; j++)
  1665. if (img.at<uchar>(i, j) < 165)
  1666. dest.at<uchar>(i, j) = 0;
  1667. else
  1668. dest.at<uchar>(i, j) = 255;
  1669.  
  1670. imshow("Binarizare", dest);
  1671. }
  1672.  
  1673. void testPragBinarizare() {
  1674.  
  1675. Mat img = imread("Images/eight.bmp", CV_LOAD_IMAGE_GRAYSCALE);
  1676.  
  1677. imshow("src", img);
  1678.  
  1679. pragBinarizare(img);
  1680.  
  1681. waitKey(0);
  1682. }
  1683.  
  1684. void LumGamma(Mat img,int offset,float gamma, int gOUTmin, int gOUTmax) {
  1685.  
  1686. imshow("Src", img);
  1687. showHistogram("src", calculHistograma(img), 256, 200);
  1688.  
  1689. Mat lum = img.clone();
  1690.  
  1691.  
  1692. printf("Luminozitate: offset = %d\n", offset);
  1693.  
  1694. for (int i = 0; i < img.rows; i++)
  1695. for (int j = 0; j < img.cols; j++) {
  1696. int suma = img.at<uchar>(i, j) + offset;
  1697. if (suma > 255)suma = 255;
  1698. if (suma < 0) suma = 0;
  1699. lum.at<uchar>(i, j) = suma;
  1700. }
  1701. imshow("Luminozitate", lum);
  1702. showHistogram("luminozitate", calculHistograma(lum), 256, 200);
  1703.  
  1704. // corectia gamma
  1705. Mat gam = img.clone();
  1706.  
  1707.  
  1708. printf("Corectie gamma: gamma = %f\n", gamma);
  1709.  
  1710. for (int i = 0; i < img.rows; i++)
  1711. for (int j = 0; j < img.cols; j++) {
  1712. float aux = pow((float)img.at<uchar>(i, j) / 255, gamma) * 255;
  1713. if (aux > 255)
  1714. aux = 255;
  1715. if (aux < 0)
  1716. aux = 0;
  1717. gam.at<uchar>(i, j) = (int)aux;
  1718. }
  1719. imshow("Corectia gamma", gam);
  1720. showHistogram("gamma", calculHistograma(gam), 256, 200);
  1721.  
  1722.  
  1723. // modificarea contrastului
  1724. int gmin = 255;
  1725. int gmax = 0;
  1726.  
  1727.  
  1728. int* hist = calculHistograma(img);
  1729.  
  1730. for (int i = 0; i < 255; i++) {
  1731. if (hist[i] != 0 && i < gmin)
  1732. gmin = i;
  1733. if (hist[i] != 0 && i > gmax)
  1734. gmax = i;
  1735. }
  1736.  
  1737. Mat contrast = img.clone();
  1738.  
  1739. printf("Contrast:\n");
  1740. printf("G in min = %d\n", gmin);
  1741. printf("G in max = %d\n", gmax);
  1742. printf("G out min = %d\n", gOUTmin);
  1743. printf("G out max = %d\n", gOUTmax);
  1744.  
  1745. for (int i = 0; i < img.rows; i++)
  1746. for (int j = 0; j < img.cols; j++) {
  1747. float aux = gOUTmin + (img.at<uchar>(i, j) - gmin) * (gOUTmax - gOUTmin) / (gmax - gmin);
  1748. if (aux > 255)
  1749. aux = 255;
  1750. if (aux < 0)
  1751. aux = 0;
  1752. contrast.at<uchar>(i, j) = (int)aux;
  1753. }
  1754. imshow("Contrast", contrast);
  1755. showHistogram("contrast", calculHistograma(contrast), 256, 200);
  1756.  
  1757. }
  1758.  
  1759. void testCalculeHistograma(int offset,float gamma, int gOUTmin, int gOUTmax) {
  1760.  
  1761. Mat img = imread("Images/wilderness.bmp", CV_LOAD_IMAGE_GRAYSCALE);
  1762.  
  1763. imshow("src", img);
  1764.  
  1765. LumGamma(img,offset,gamma,gOUTmin, gOUTmax);
  1766.  
  1767. waitKey(0);
  1768. }
  1769.  
  1770. void egalizareHisto(Mat img) {
  1771.  
  1772. int *hist = calculHistograma(img);
  1773.  
  1774. showHistogram("histogram SRC", hist, 256, 200);
  1775.  
  1776. int hc[256] ;
  1777. int tab[256];
  1778. hc[0] = 0;
  1779.  
  1780. for (int g = 1; g < 256; g++)
  1781. tab[g] = 0;
  1782.  
  1783. for (int g = 1; g < 256; g++)
  1784. hc[g] = hc[g - 1] + hist[g];
  1785.  
  1786. Mat dst = img.clone();
  1787.  
  1788. int M = img.rows * img.cols;
  1789.  
  1790. for (int g = 0; g < 256; g++)
  1791. tab[g] = 255 * hc[g] / M;
  1792.  
  1793. for (int i = 0; i < img.rows; i++)
  1794. for (int j = 0; j < img.cols; j++)
  1795. dst.at<uchar>(i, j) = tab[img.at<uchar>(i, j)];
  1796.  
  1797. int *histDst = calculHistograma(dst);
  1798.  
  1799. imshow("dst", dst);
  1800. showHistogram("histogram DST", histDst, 256, 200);
  1801. }
  1802.  
  1803. void testEgalizareHisto() {
  1804.  
  1805. Mat img = imread("Images\baloons.bmp", CV_LOAD_IMAGE_GRAYSCALE);
  1806. imshow("src", img);
  1807. egalizareHisto(img);
  1808. waitKey(0);
  1809. }
  1810.  
  1811.  
  1812.  
  1813. /////////////////////////// LAB 9 //////////////////
  1814. Mat filtru1(Mat src, Mat filtru)
  1815. {
  1816. Mat dst = Mat(src.rows, src.cols, CV_8UC1);
  1817. int i, j, i2 = 0, j2 = 0;
  1818. int pixel = 0;
  1819. int sum = 0;
  1820.  
  1821. for (i = 0; i < filtru.rows; i++)
  1822. for (j = 0; j < filtru.cols; j++)
  1823. {
  1824. sum = sum + filtru.at<short>(i, j);
  1825. }
  1826.  
  1827. for (i = 1; i < src.rows - 1; i++)
  1828. for (j = 1; j < src.cols - 1; j++)
  1829. {
  1830. pixel = 0;
  1831. for (i2 = 0; i2 < filtru.rows; i2++)
  1832. for (j2 = 0; j2 < filtru.cols; j2++)
  1833. pixel = pixel + (filtru.at<short>(i2, j2) * src.at<uchar>(i + i2 - 1, j + j2 - 1));
  1834.  
  1835. if (sum != 0)
  1836. {
  1837. pixel /= sum;
  1838. }
  1839. if (pixel >= 255) {
  1840. pixel = 255;
  1841. }
  1842. if (pixel <= 0)
  1843. {
  1844. pixel = 0;
  1845. }
  1846. dst.at<uchar>(i, j) = pixel;
  1847. }
  1848.  
  1849. printf("Sum=%d \n", sum);
  1850. return dst;
  1851. }
  1852.  
  1853. Mat convolutie(Mat src, Mat filtru)
  1854. {
  1855. Mat dst = Mat(src.rows, src.cols, CV_8UC1);
  1856. int i, j, i2 = 0, j2 = 0;
  1857. int pixel = 0;
  1858. int sum = 0;
  1859.  
  1860. for (i = 0; i < filtru.rows; i++)
  1861. for (j = 0; j < filtru.cols; j++)
  1862. {
  1863. sum = sum + filtru.at<short>(i, j);
  1864. }
  1865.  
  1866. for (i = 1; i < src.rows - 1; i++)
  1867. for (j = 1; j < src.cols - 1; j++)
  1868. {
  1869. pixel = 0;
  1870. for (i2 = 0; i2 < filtru.rows; i2++)
  1871. for (j2 = 0; j2 < filtru.cols; j2++)
  1872. pixel = pixel + (filtru.at<short>(i2, j2) * src.at<uchar>(i + i2 - 1, j + j2 - 1));
  1873.  
  1874.  
  1875. if (pixel >= 255) {
  1876. pixel = 255;
  1877. }
  1878. if (pixel <= 0)
  1879. {
  1880. pixel = 0;
  1881. }
  1882. dst.at<uchar>(i, j) = pixel;
  1883. }
  1884.  
  1885. printf("Sum=%d \n", sum);
  1886. return dst;
  1887. }
  1888.  
  1889. Mat filtruMedie() {
  1890. Mat filtru = Mat(3, 3, CV_16SC1);
  1891. filtru.at<short>(0, 0) = 1;
  1892. filtru.at<short>(0, 1) = 1;
  1893. filtru.at<short>(0, 2) = 1;
  1894. filtru.at<short>(1, 0) = 1;
  1895. filtru.at<short>(1, 1) = 1;
  1896. filtru.at<short>(1, 2) = 1;
  1897. filtru.at<short>(2, 0) = 1;
  1898. filtru.at<short>(2, 1) = 1;
  1899. filtru.at<short>(2, 2) = 1;
  1900. return filtru;
  1901. }
  1902.  
  1903. void apelFiltruMedie() {
  1904. char fname[MAX_PATH];
  1905. while (openFileDlg(fname)) {
  1906. Mat source;
  1907. source = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
  1908. Mat dest = filtru1(source, filtruMedie());
  1909. imshow("image", source);
  1910. imshow("dst", dest);
  1911. waitKey();
  1912. }
  1913. }
  1914.  
  1915. Mat filtruGaussian()
  1916. {
  1917. Mat filtru = Mat(3, 3, CV_16SC1);
  1918. filtru.at<short>(0, 0) = 1;
  1919. filtru.at<short>(0, 1) = 2;
  1920. filtru.at<short>(0, 2) = 1;
  1921. filtru.at<short>(1, 0) = 2;
  1922. filtru.at<short>(1, 1) = 4;
  1923. filtru.at<short>(1, 2) = 2;
  1924. filtru.at<short>(2, 0) = 1;
  1925. filtru.at<short>(2, 1) = 2;
  1926. filtru.at<short>(2, 2) = 1;
  1927. return filtru;
  1928.  
  1929.  
  1930. }
  1931.  
  1932. void apelFiltruGauss() {
  1933. char fname[MAX_PATH];
  1934. while (openFileDlg(fname)) {
  1935. Mat source;
  1936. source = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
  1937. Mat dest = filtru1(source, filtruGaussian());
  1938. imshow("image", source);
  1939. imshow("dst", dest);
  1940. waitKey();
  1941. }
  1942. }
  1943.  
  1944. Mat filtru2(Mat src, Mat filtru)
  1945. {
  1946.  
  1947. Mat dst = Mat(src.rows, src.cols, CV_32SC1);
  1948. Mat dst2 = Mat(src.rows, src.cols, CV_8UC1);
  1949. int i, j, i2 = 0, j2 = 0;
  1950. int pixel = 0;
  1951. int sum = 0;
  1952. int min = 32000, max = 0;
  1953.  
  1954.  
  1955.  
  1956. for (i = 1; i < src.rows - 1; i++)
  1957. for (j = 1; j < src.cols - 1; j++)
  1958. {
  1959. pixel = 0;
  1960. for (i2 = 0; i2 < filtru.rows; i2++)
  1961. for (j2 = 0; j2 < filtru.cols; j2++)
  1962. pixel = pixel + (filtru.at<short>(i2, j2) * src.at<uchar>(i + i2 - 1, j + j2 - 1));
  1963.  
  1964. if (pixel >= 255) {
  1965. pixel = 255;
  1966. }
  1967. //modul de imagine
  1968. if (pixel <= 0)
  1969. {
  1970. pixel = 0;
  1971. }
  1972. dst.at<int>(i, j) = pixel;
  1973. }
  1974. for (i = 1; i < src.rows - 1; i++)
  1975. for (j = 1; j < src.cols - 1; j++) {
  1976. if (min > dst.at<int>(i, j)) { min = dst.at<int>(i, j); }
  1977. if (max < dst.at<int>(i, j)) { max = dst.at<int>(i, j); }
  1978. }
  1979. for (i = 1; i < src.rows - 1; i++) {
  1980. for (j = 1; j < src.cols - 1; j++) {
  1981. dst2.at<uchar>(i, j) = ((dst.at<int>(i, j) - min) * 255) / (max - min);
  1982. }
  1983. }
  1984.  
  1985. return dst2;
  1986.  
  1987. }
  1988.  
  1989. Mat filtruLaplace()
  1990. {
  1991. Mat filtru = Mat(3, 3, CV_16SC1);
  1992. filtru.at<short>(0, 0) = -1;
  1993. filtru.at<short>(0, 1) = -1;
  1994. filtru.at<short>(0, 2) = -1;
  1995. filtru.at<short>(1, 0) = -1;
  1996. filtru.at<short>(1, 1) = 8;
  1997. filtru.at<short>(1, 2) = -1;
  1998. filtru.at<short>(2, 0) = -1;
  1999. filtru.at<short>(2, 1) = -1;
  2000. filtru.at<short>(2, 2) = -1;
  2001. return filtru;
  2002.  
  2003. }
  2004.  
  2005. void apelLaPlace()
  2006. {
  2007. char fname[MAX_PATH];
  2008. while (openFileDlg(fname)) {
  2009. Mat source;
  2010. source = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
  2011. Mat dest = filtru2(source, filtruLaplace());
  2012. imshow("image", source);
  2013. imshow("dst", dest);
  2014. waitKey();
  2015. }
  2016. }
  2017.  
  2018. Mat filtruHigh()
  2019. {
  2020. Mat filtru = Mat(3, 3, CV_16SC1);
  2021. filtru.at<short>(0, 0) = -1;
  2022. filtru.at<short>(0, 1) = -1;
  2023. filtru.at<short>(0, 2) = -1;
  2024. filtru.at<short>(1, 0) = -1;
  2025. filtru.at<short>(1, 1) = 9;
  2026. filtru.at<short>(1, 2) = -1;
  2027. filtru.at<short>(2, 0) = -1;
  2028. filtru.at<short>(2, 1) = -1;
  2029. filtru.at<short>(2, 2) = -1;
  2030. return filtru;
  2031.  
  2032. }
  2033.  
  2034. void apelHigh()
  2035. {
  2036. char fname[MAX_PATH];
  2037. while (openFileDlg(fname)) {
  2038. Mat source;
  2039. source = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
  2040. Mat dest = filtru2(source, filtruHigh());
  2041. imshow("image", source);
  2042. imshow("dst", dest);
  2043. waitKey();
  2044. }
  2045. }
  2046.  
  2047. /////////////////////////////// LAB 10 /////////////////////
  2048.  
  2049. void filtruMedian(Mat src, int w) {
  2050. double t = (double)getTickCount();
  2051. Mat dst = src.clone();
  2052. int k = w / 2;
  2053. int index;
  2054.  
  2055. std::vector <uchar> V = {};
  2056. imshow("Original", src);
  2057.  
  2058. for (int y = k; y < src.rows - k; y++) {
  2059. for (int x = k; x < src.cols - k; x++) {
  2060. int index = 0;
  2061. for (int i = -k; i <= k; i++) {
  2062. for (int j = -k; j <= k; j++) {
  2063. V.push_back(src.at<uchar>(y + i, x + j));
  2064. index++;
  2065. }
  2066. }
  2067. std::sort(V.begin(), V.end());
  2068. uchar mean = V[w*w / 2];
  2069. dst.at<uchar>(y, x) = mean;
  2070. V.clear();
  2071. }
  2072. }
  2073.  
  2074. imshow("Rez", dst);
  2075. t = ((double)getTickCount() - t) / getTickFrequency();
  2076. // Display (in the console window) the processing time in [ms]
  2077. printf("Time = %.3f [ms]\n", t * 1000);
  2078.  
  2079.  
  2080. }
  2081.  
  2082. void apelareMedian()
  2083. {
  2084.  
  2085. char fname[MAX_PATH];
  2086. while (openFileDlg(fname)) {
  2087. Mat src;
  2088. src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
  2089. filtruMedian(src, 3);
  2090.  
  2091.  
  2092. waitKey();
  2093. }
  2094.  
  2095. }
  2096.  
  2097. Mat filtruGaussian(Mat src, int w) {
  2098. double t = (double)getTickCount(); // Get the current time [ms]
  2099. Mat dst = src.clone();
  2100.  
  2101.  
  2102.  
  2103. float G[7][7] = { 0 };
  2104. float sigma = (float)w / 6;
  2105. int k = w / 2;
  2106.  
  2107. for (int x = 0; x < w; x++) {
  2108. for (int y = 0; y < w; y++) {
  2109. G[x][y] = 1.0 / (2 * PI*sigma*sigma) * exp(-(((x - w/2)*(x - w/2) + (y - w/2)*(y - w/2)) / (2 * sigma*sigma)));
  2110. }
  2111. }
  2112.  
  2113. for (int x = k; x < src.rows - k; x++)
  2114. for (int y = k; y < src.cols - k; y++)
  2115. {
  2116. int aux = 0;
  2117. for (int i = -k; i <= k; i++)
  2118. for (int j = -k; j <= k; j++)
  2119. {
  2120. aux += src.at<uchar>(x + j, y + i)*G[j + k][i + k];
  2121. }
  2122.  
  2123. dst.at<uchar>(x, y) = aux;
  2124.  
  2125.  
  2126. }
  2127. imshow("Original", src);
  2128. imshow("Rezultat", dst);
  2129. //Mat dest = filtru1(dst, filtruGaussian());
  2130. //imshow("Dupa convolutie", dest);
  2131. t = ((double)getTickCount() - t) / getTickFrequency();
  2132. // Display (in the console window) the processing time in [ms]
  2133. printf("Time = %.3f [ms]\n", t * 1000);
  2134. return dst;
  2135. }
  2136.  
  2137. void apelareGaussian()
  2138. {
  2139.  
  2140. Mat src;
  2141. src = imread("Images/imagini_zgomot/portrait_Gauss1.bmp", 0);
  2142. Mat dst=filtruGaussian(src, 7);
  2143.  
  2144.  
  2145.  
  2146.  
  2147. waitKey();
  2148.  
  2149.  
  2150. }
  2151.  
  2152. void filtruGaussian2(Mat img ,int w) {
  2153.  
  2154.  
  2155. double t = (double)getTickCount(); // Get the current time [ms]
  2156. float sigma = (float)(w / 6.0);
  2157.  
  2158.  
  2159. Mat clone = img.clone();
  2160. int k = w/ 2;
  2161.  
  2162. uchar V[50] = { 0 };
  2163. float Gx[7] = { 0 };
  2164. float Gy[7]= { 0 };
  2165.  
  2166. for (int x = 0; x < w; x++)
  2167. for (int y = 0; y < w; y++) {
  2168. if (y == w / 2) Gy[x] = 1.0 / (2 * PI*sigma)*exp(-(((y - w/2)*(y - w/2)) / (2 * sigma*sigma)));
  2169. if (x == w / 2) Gx[y] = 1.0 / (2 * PI*sigma)*exp(-(((x - w/2)*(x - w/2)) / (2 * sigma*sigma)));
  2170.  
  2171.  
  2172. }
  2173.  
  2174. for (int x = k; x < img.rows - k; x++)
  2175. for (int y = k; y < img.cols - k; y++)
  2176. {
  2177. float aux = 0;
  2178. for (int i = -k; i <= k; i++)
  2179. for (int j = -k; j <= k; j++)
  2180. {
  2181. aux += Gx[j + k] * Gy[i + k] * img.at<uchar>(x + j, y + i);
  2182. }
  2183.  
  2184. clone.at<uchar>(x, y) = aux;
  2185.  
  2186.  
  2187. }
  2188.  
  2189.  
  2190. imshow("original", img);
  2191. imshow("rezultat", clone);
  2192. t = ((double)getTickCount() - t) / getTickFrequency();
  2193. // Display (in the console window) the processing time in [ms]
  2194. printf("Time = %.3f [ms]\n", t * 1000);
  2195. waitKey(0);
  2196. }
  2197.  
  2198. void apelareGaussian2()
  2199. {
  2200.  
  2201. Mat src;
  2202. src = imread("Images/imagini_zgomot/portrait_Gauss1.bmp", 0);
  2203. //filtruGaussian(src,7);
  2204. filtruGaussian2(src, 7);
  2205.  
  2206.  
  2207.  
  2208. waitKey();
  2209.  
  2210.  
  2211. }
  2212.  
  2213.  
  2214.  
  2215. /////////////////////////// LAB 11 /////////////////////////
  2216.  
  2217.  
  2218. void prewitt(Mat src)
  2219. {
  2220.  
  2221. int Hx[3][3] = { { -1, 0, 1 },
  2222. { -1, 0, 1 },
  2223. { -1, 0, 1 } };
  2224.  
  2225. int Hy[3][3] = { { 1, 1, 1 },
  2226. { 0, 0, 0 },
  2227. { -1, -1, -1 } };
  2228.  
  2229. Mat dstx = src.clone();
  2230. Mat dsty = src.clone();
  2231. int k = 1;
  2232. int pixelx, pixely;
  2233. for (int y = 1; y < src.rows - 1; y++)
  2234. {
  2235. for (int x = 1; x < src.cols -1; x++)
  2236. {
  2237. int aux1 = 0, aux2 = 0;
  2238. for (int i = -1; i <= 1; i++)
  2239. {
  2240. for (int j = -1; j <= 1; j++)
  2241. {
  2242. aux1 += src.at<uchar>(x + j, y + i) * Hx[j + 1][i + 1];
  2243. aux2 += src.at<uchar>(x + j, y + i) * Hy[j + 1][i + 1];
  2244. }
  2245.  
  2246.  
  2247.  
  2248. }
  2249. if (aux1 < 0)
  2250. dstx.at<uchar>(x, y) = 0;
  2251. else if (aux1 > 255)
  2252. dstx.at<uchar>(x, y) = 255;
  2253. else
  2254. dstx.at<uchar>(x, y) = aux1;
  2255.  
  2256. if (aux2 < 0)
  2257. dsty.at<uchar>(x, y) = 0;
  2258. else if (aux2 > 255)
  2259. dsty.at<uchar>(x, y) = 255;
  2260. else
  2261. dsty.at<uchar>(x, y) = aux2;
  2262. }
  2263. }
  2264.  
  2265. imshow("Original", src);
  2266. imshow("X component", dstx);
  2267. imshow("Y component", dsty);
  2268. waitKey(0);
  2269. }
  2270.  
  2271. void apelarePrewitt()
  2272. {
  2273.  
  2274. Mat src;
  2275. src = imread("Images/imagini_muchii/cameraman.bmp", 0);
  2276. prewitt(src);
  2277.  
  2278.  
  2279.  
  2280. waitKey();
  2281.  
  2282. }
  2283.  
  2284. void sobel(Mat src)
  2285. {
  2286.  
  2287. int Hx[3][3] = { { -1, 0, 1 },
  2288. { -2, 0, 2 },
  2289. { -1, 0, 1 } };
  2290.  
  2291. int Hy[3][3] = { { 1, 2, 1 },
  2292. { 0, 0, 0 },
  2293. { -1, -2, -1 } };
  2294.  
  2295. Mat dstx = src.clone();
  2296. Mat dsty = src.clone();
  2297. int k = 1;
  2298. int pixelx, pixely;
  2299. for (int y = k; y < src.rows - k; y++)
  2300. {
  2301. for (int x = k; x < src.cols - k; x++)
  2302. {
  2303. int aux1 = 0, aux2 = 0;
  2304. for (int i = -k; i <= k; i++)
  2305. {
  2306. for (int j = -k; j <= k; j++)
  2307. {
  2308. aux1 += src.at<uchar>(x + j, y + i) * Hx[j + k][i + k];
  2309. aux2 += src.at<uchar>(x + j, y + i) * Hy[j + k][i + k];
  2310. }
  2311.  
  2312.  
  2313.  
  2314. }
  2315. if (aux1 < 0)
  2316. dstx.at<uchar>(x, y) = 0;
  2317. else if (aux1 > 255)
  2318. dstx.at<uchar>(x, y) = 255;
  2319. else
  2320. dstx.at<uchar>(x, y) = aux1;
  2321.  
  2322. if (aux2 < 0)
  2323. dsty.at<uchar>(x, y) = 0;
  2324. else if (aux2 > 255)
  2325. dsty.at<uchar>(x, y) = 255;
  2326. else
  2327. dsty.at<uchar>(x, y) = aux2;
  2328. }
  2329. }
  2330.  
  2331. imshow("Original", src);
  2332. imshow("X component", dstx);
  2333. imshow("Y component", dsty);
  2334. waitKey(0);
  2335. }
  2336.  
  2337. void apelareSobel()
  2338. {
  2339.  
  2340. Mat src;
  2341. src = imread("Images/imagini_muchii/cameraman.bmp", 0);
  2342. sobel(src);
  2343.  
  2344.  
  2345.  
  2346. waitKey();
  2347.  
  2348. }
  2349.  
  2350. void Roberts(Mat src)
  2351. {
  2352. int Hx[2][2] = { { 1, 0 },
  2353. { 0, -1 } };
  2354.  
  2355. int Hy[2][2] = { { 0, -1 },
  2356. { 1, 0 } };
  2357.  
  2358. Mat dest_x = src.clone();
  2359. Mat dest_y = src.clone();
  2360. int k = 1;
  2361. for (int y = k; y < src.rows - k; y++)
  2362. {
  2363. for (int x = k; x < src.cols - k; x++)
  2364. {
  2365. int aux1 = 0, aux2 = 0;
  2366. for (int i = -k; i < k; i++)
  2367. {
  2368. for (int j = -k; j < k; j++)
  2369. {
  2370. aux1 += src.at<uchar>(x + j, y + i) * Hx[j + k][i + k];
  2371. aux2 += src.at<uchar>(x + j, y + i) * Hy[j + k][i + k];
  2372. }
  2373.  
  2374. if (aux1 < 0)
  2375. dest_x.at<uchar>(x, y) = 0;
  2376. else if (aux1 > 255)
  2377. dest_x.at<uchar>(x, y) = 255;
  2378. else
  2379. dest_x.at<uchar>(x, y) = aux1;
  2380.  
  2381. if (aux2 < 0)
  2382. dest_y.at<uchar>(x, y) = 0;
  2383. else if (aux2 > 255)
  2384. dest_y.at<uchar>(x, y) = 255;
  2385. else
  2386. dest_y.at<uchar>(x, y) = aux2;
  2387.  
  2388. }
  2389. }
  2390. }
  2391.  
  2392. imshow("Original", src);
  2393. imshow("X component", dest_x);
  2394. imshow("Y component", dest_y);
  2395. waitKey(0);
  2396.  
  2397. }
  2398.  
  2399. void canny(Mat src)
  2400. {
  2401. Mat temp = src.clone(); //matrice temporara
  2402. Mat modul = Mat::zeros(src.size(), CV_8UC1); //matricea pt. modulul gradientului
  2403. Mat directie = Mat::zeros(src.size(), CV_8UC1); //matricea pt. directia gradientului
  2404.  
  2405. int Sx[3][3] = { { -1, 0, 1 },{ -2, 0, 2 },{ -1, 0, 1 } };
  2406. int Sy[3][3] = { { 1, 2, 1 },{ 0, 0, 0 },{ -1, -2, -1 } };
  2407.  
  2408. int w;
  2409. float teta;
  2410. int dir;
  2411. Mat canny_res;
  2412.  
  2413.  
  2414. temp = filtruGaussian(src, 5);
  2415. imshow("Gauss res", temp);
  2416. //waitKey(0);
  2417.  
  2418. for (int i = 2; i < temp.rows - 2; i++)
  2419. {
  2420. for (int j = 2; j < temp.cols - 2; j++)
  2421. {
  2422. float gradX = 0, gradY = 0;
  2423.  
  2424. for (int l1 = 0; l1 < 3; l1++)
  2425. {
  2426. for (int l2 = 0; l2 < 3; l2++)
  2427. {
  2428. gradX += temp.at<uchar>(i + l1 - 1, j + l2 - 1) * Sx[l1][l2];
  2429. gradY += temp.at<uchar>(i + l1 - 1, j + l2 - 1) * Sy[l1][l2];
  2430. }
  2431. }
  2432.  
  2433.  
  2434. ;
  2435. modul.at<uchar>(i, j) = sqrt(gradX * gradX + gradY * gradY) / 5.65;
  2436.  
  2437. teta = atan2((float)gradY, (float)gradX);
  2438. if ((teta > 3 * PI / 8 && teta < 5 * PI / 8) || (teta > -5 * PI / 8 && teta < -3 * PI / 8))
  2439. {
  2440. dir = 0;
  2441. }
  2442.  
  2443. if ((teta > PI / 8 && teta < 3 * PI / 8) || (teta > -7 * PI / 8 && teta < -5 * PI / 8))
  2444. {
  2445. dir = 1;
  2446. }
  2447.  
  2448. if ((teta > -PI / 8 && teta < PI / 8) || teta > 7 * PI / 8 && teta < -7 * PI / 8)
  2449. {
  2450. dir = 2;
  2451. }
  2452.  
  2453. if ((teta > 5 * PI / 8 && teta < 7 * PI / 8) || (teta > -3 * PI / 8 && teta < -PI / 8))
  2454. {
  2455. dir = 3;
  2456. }
  2457.  
  2458. directie.at<uchar>(i, j) = dir;
  2459. }
  2460. }
  2461.  
  2462.  
  2463. // sobel
  2464. Mat tempSobelX = temp.clone();
  2465.  
  2466. for (int i = 1; i < temp.rows - 1; i++)
  2467. {
  2468. for (int j = 1; j < temp.cols - 1; j++)
  2469. {
  2470. tempSobelX.at<uchar>(i, j) = (
  2471. -1 * src.at<uchar>(i - 1, j - 1) +
  2472. 0 * src.at<uchar>(i - 1, j) +
  2473. 1 * src.at<uchar>(i - 1, j + 1) +
  2474. -2 * src.at<uchar>(i, j - 1) +
  2475. 0 * src.at<uchar>(i, j) +
  2476. 2 * src.at<uchar>(i, j + 1) +
  2477. -1 * src.at<uchar>(i + 1, j - 1) +
  2478. 0 * src.at<uchar>(i + 1, j) +
  2479. 1 * src.at<uchar>(i + 1, j + 1)) / 16;
  2480. }
  2481. }
  2482.  
  2483. //imshow("Res Sobel X", tempSobelX);
  2484.  
  2485.  
  2486. Mat tempSobelY = temp.clone();
  2487.  
  2488. for (int i = 1; i < temp.rows - 1; i++)
  2489. {
  2490. for (int j = 1; j < temp.cols - 1; j++)
  2491. {
  2492. tempSobelY.at<uchar>(i, j) = (
  2493. 1 * src.at<uchar>(i - 1, j - 1) +
  2494. 2 * src.at<uchar>(i - 1, j) +
  2495. 1 * src.at<uchar>(i - 1, j + 1) +
  2496. 0 * src.at<uchar>(i, j - 1) +
  2497. 0 * src.at<uchar>(i, j) +
  2498. 0 * src.at<uchar>(i, j + 1) +
  2499. -1 * src.at<uchar>(i + 1, j - 1) +
  2500. -2 * src.at<uchar>(i + 1, j) +
  2501. -1 * src.at<uchar>(i + 1, j + 1)) / 16;
  2502. }
  2503. }
  2504. //
  2505. //imshow("Res Sobel Y", tempSobelY);
  2506.  
  2507. imshow("Modul res", modul);
  2508.  
  2509.  
  2510.  
  2511.  
  2512.  
  2513.  
  2514. Mat nms = modul.clone();
  2515. for (int i = 1; i < src.rows - 1; ++i)
  2516. {
  2517. for (int j = 1; j < src.cols - 1; ++j)
  2518. {
  2519. int dir = directie.at<uchar>(i, j);
  2520. switch (dir)
  2521. {
  2522. case 0:
  2523. {
  2524. if (i == 0)
  2525. {
  2526. if (modul.at<uchar>(i, j) < modul.at<uchar>(i + 1, j))
  2527. {
  2528. nms.at<uchar>(i, j) = 0;
  2529. }
  2530. }
  2531. else if (i == src.rows - 1)
  2532. {
  2533. if (modul.at<uchar>(i, j) < modul.at<uchar>(i - 1, j))
  2534. {
  2535. nms.at<uchar>(i, j) = 0;
  2536. }
  2537. }
  2538. else
  2539. {
  2540. if (modul.at<uchar>(i, j) < modul.at<uchar>(i - 1, j) ||
  2541. modul.at<uchar>(i, j) < modul.at<uchar>(i + 1, j)
  2542. )
  2543. {
  2544. nms.at<uchar>(i, j) = 0;
  2545. }
  2546. }
  2547. break;
  2548. }
  2549. case 1:
  2550. {
  2551.  
  2552. if (modul.at<uchar>(i, j) < modul.at<uchar>(i - 1, j + 1) ||
  2553. modul.at<uchar>(i, j) < modul.at<uchar>(i + 1, j - 1)
  2554. )
  2555. {
  2556. nms.at<uchar>(i, j) = 0;
  2557. }
  2558. break;
  2559. }
  2560. case 2:
  2561. {
  2562. if (j == 0)
  2563. {
  2564. if (modul.at<uchar>(i, j) < modul.at<uchar>(i, j + 1))
  2565. {
  2566. nms.at<uchar>(i, j) = 0;
  2567. }
  2568. }
  2569. else if (j == src.cols - 1)
  2570. {
  2571. if (modul.at<uchar>(i, j) < modul.at<uchar>(i, j - 1))
  2572. {
  2573. nms.at<uchar>(i, j) = 0;
  2574. }
  2575. }
  2576. else
  2577. {
  2578. if (modul.at<uchar>(i, j) < modul.at<uchar>(i, j - 1) ||
  2579. modul.at<uchar>(i, j) < modul.at<uchar>(i, j + 1)
  2580. )
  2581. {
  2582. nms.at<uchar>(i, j) = 0;
  2583. }
  2584. }
  2585. break;
  2586. }
  2587. default:
  2588. {
  2589. if (modul.at<uchar>(i, j) < modul.at<uchar>(i - 1, j - 1) ||
  2590. modul.at<uchar>(i, j) < modul.at<uchar>(i + 1, j + 1)
  2591. )
  2592. {
  2593. nms.at<uchar>(i, j) = 0;
  2594. }
  2595. break;
  2596. }
  2597. }
  2598. }
  2599. }
  2600.  
  2601. imshow("Non-max suppression", nms);
  2602.  
  2603.  
  2604.  
  2605.  
  2606. //compute histogram
  2607.  
  2608. int hist[256];
  2609. for (int i = 0; i < 255; ++i)
  2610. {
  2611. hist[i] = 0;
  2612. }
  2613. for (int i = 0; i < src.rows; ++i)
  2614. {
  2615. for (int j = 0; j < src.cols; ++j)
  2616. {
  2617. hist[nms.data[i * src.cols + j]]++;
  2618. }
  2619. }
  2620.  
  2621.  
  2622. float k = 0.4;
  2623. float nrnonmuchie = 0.9 * (nms.rows * nms.cols - hist[0]);
  2624. int pragadaptiv;
  2625. int sum = 0;
  2626.  
  2627. for (int i = 1; i < 255; i++)
  2628. {
  2629. sum += hist[i];
  2630. if (sum > nrnonmuchie)
  2631. {
  2632. pragadaptiv =hist[i];
  2633. break;
  2634. }
  2635.  
  2636. }
  2637. int x;
  2638. printf("prag adaptiv + %d", pragadaptiv);
  2639. scanf("%d",&x);
  2640.  
  2641. float pH = pragadaptiv;
  2642. float pL = 0.4 * pH;
  2643.  
  2644. /* double threshold */
  2645.  
  2646. Mat thr = nms.clone();
  2647. for (int i = 0; i < src.rows; ++i)
  2648. {
  2649. for (int j = 0; j < src.cols; ++j)
  2650. {
  2651. if (nms.data[i * src.cols + j] < pL)
  2652. {
  2653. thr.data[i * src.cols + j] = 0;
  2654. }
  2655. else if (nms.data[i * src.cols + j] > pH)
  2656. {
  2657. thr.data[i * src.cols + j] = STRONG;
  2658. }
  2659. else if (nms.data[i * src.cols + j] < pH && nms.data[i * src.cols + j] > pL)
  2660. {
  2661. thr.data[i * src.cols + j] = WEAK;
  2662. }
  2663. }
  2664. }
  2665.  
  2666. imshow("thr", thr);
  2667.  
  2668.  
  2669.  
  2670.  
  2671.  
  2672.  
  2673.  
  2674.  
  2675. waitKey(0);
  2676. }
  2677.  
  2678. void cannyTest()
  2679. {
  2680. Mat src;
  2681. src = imread("Images/saturn.bmp", 0);
  2682. canny(src);
  2683. waitKey(0);
  2684. }
  2685.  
  2686.  
  2687. int main()
  2688. {
  2689. int op;
  2690. Mat src,src1,src2,src3;
  2691. do
  2692. {
  2693. system("cls");
  2694. destroyAllWindows();
  2695. printf("Menu:\n");
  2696. printf(" 1 - Open image\n");
  2697. printf(" 2 - Open BMP images from folder\n");
  2698. printf(" 3 - Image negative - diblook style\n");
  2699. printf(" 4 - BGR->HSV\n");
  2700. printf(" 5 - Resize image\n");
  2701. printf(" 6 - Canny edge detection\n");
  2702. printf(" 7 - L1 Negative Image \n");
  2703. printf(" 8 - Snap frame from live video\n");
  2704. printf(" 9 - Mouse callback demo\n");
  2705. printf(" 10 - Imagine cu factor aditiv\n");
  2706. printf(" 11 - Imagine cu factor multiplicativ\n");
  2707. printf(" 12 - Imagine 4 sectoare\n");
  2708. printf(" 13 - Inversa matricii\n");
  2709. printf(" 14 - Copiaza Canale\n");
  2710. printf(" 15 - Imagine GrayScale\n");
  2711. printf(" 16 - Imagine Alb-Negru\n");
  2712. printf(" 17 - Imagine HSV\n");
  2713. printf(" 18 - In imagine\n");
  2714. printf(" 19 - Proprietati geometrice\n");
  2715. printf(" 20 - Algoritm 1 – Traversarea în lăţime\n");
  2716. printf(" 21 - Draw Border\n");
  2717. printf(" 22 - Reconstruct\n");
  2718. printf(" 23 - Dilatare\n");
  2719. printf(" 24 - Eroziune\n");
  2720. printf(" 25 - Inchidere\n");
  2721. printf(" 26 - Inchidere de N ori\n");
  2722. printf(" 27 - Deschidere\n");
  2723. printf(" 28 - Deschidere de N ori\n");
  2724. printf(" 29 - Dilatare de N ori\n");
  2725. printf(" 30 - Eroziune de N ori\n");
  2726. printf(" 31 - Contur\n");
  2727. printf(" 32 - Umplere Regiuni\n");
  2728. printf(" 33 - Histograma\n");
  2729. printf(" 34 - PDFHistograma\n");
  2730. printf(" 35 - Binarizare\n");
  2731. printf(" 36 - Calcule Histograma\n");
  2732. printf(" 37 - Egalizare\n");
  2733. printf(" 38 - Filtru Medie\n");
  2734. printf(" 39 - Filtru Gaussian\n");
  2735. printf(" 40 - Filtru LaPlace\n");
  2736. printf(" 41 - Filtru High\n");
  2737. printf(" 42 - Filtru Median\n");
  2738. printf(" 43 - Filtru Gaussian\n");
  2739. printf(" 44 - Filtru Gaussian 2\n");
  2740. printf(" 45 - Prewitt\n");
  2741. printf(" 46 - Sobel\n");
  2742. printf(" 47 - Canny\n");
  2743. printf(" 0 - Exit\n\n");
  2744. printf("Option: ");
  2745. scanf("%d",&op);
  2746. switch (op)
  2747. {
  2748. case 1:
  2749. testOpenImage();
  2750. break;
  2751. case 2:
  2752. testOpenImagesFld();
  2753. break;
  2754. case 3:
  2755. testParcurgereSimplaDiblookStyle(); //diblook style
  2756. break;
  2757. case 4:
  2758. //testColor2Gray();
  2759. testBGR2HSV();
  2760. break;
  2761. case 5:
  2762. testResize();
  2763. break;
  2764. case 6:
  2765. testCanny();
  2766. break;
  2767. case 7:
  2768. negative_image();
  2769. break;
  2770. case 8:
  2771. testSnap();
  2772. break;
  2773. case 9:
  2774. testMouseClick();
  2775. break;
  2776. case 10:
  2777. changeGray(100);
  2778. break;
  2779. case 11:
  2780. changeGrayMulti(2);
  2781. break;
  2782. case 12:
  2783. patruSectoare();
  2784. break;
  2785. case 13:
  2786. inv();
  2787. break;
  2788. case 14:
  2789. copiazaCanale();
  2790. break;
  2791. case 15:
  2792. colorToGray();
  2793. break;
  2794. case 16:
  2795. grayToALb();
  2796. break;
  2797. case 17:
  2798. convertHSV();
  2799. break;
  2800. case 18:
  2801.  
  2802. src = imread("Images/Lena_24bits.bmp", CV_LOAD_IMAGE_COLOR);
  2803. isInside(src, 10, 10);
  2804. break;
  2805. case 19:
  2806. testMouseClickProprietati();
  2807. break;
  2808. case 20:
  2809. traversare();
  2810. break;
  2811. case 21:
  2812. border();
  2813. break;
  2814. case 22:
  2815. reconstruct();
  2816. break;
  2817. case 23:
  2818. src = imread("Images/1_Dilate/mon1thr1_bw.bmp", 0);
  2819. dilatare(src);
  2820. break;
  2821. case 24:
  2822. src1 = imread("Images/2_Erode/mon1thr1_bw.bmp", 0);
  2823. eroziune(src1);
  2824. break;
  2825. case 25:
  2826. src2 = imread("Images/4_Close/phn1thr1_bw.bmp", 0);
  2827. inchidere(src2);
  2828. break;
  2829. case 26:
  2830. inchidereapelNori(2);
  2831. break;
  2832. case 27:
  2833. src3 = imread("Images/3_Open/cel4thr3_bw.bmp", 0);
  2834. deschidere(src3);
  2835. break;
  2836. case 28:
  2837. deschhidereapelNori(2);
  2838. break;
  2839. case 29:
  2840. dilatare_apelNori(10);
  2841. break;
  2842. case 30:
  2843. eroziune_apelNori(10);
  2844. break;
  2845. case 31:
  2846. contur();
  2847. break;
  2848. case 32:
  2849. umplere_regiuni(80, 80);
  2850. break;
  2851. case 33:
  2852. testHistograma();
  2853. break;
  2854. case 34:
  2855. testHistogramaFDP();
  2856. break;
  2857. case 35:
  2858. testPragBinarizare(); break;
  2859. case 36:
  2860. testCalculeHistograma(100,2.5,100,250); break;
  2861. case 37:
  2862. testEgalizareHisto();
  2863. break;
  2864. case 38:
  2865. apelFiltruMedie();
  2866. break;
  2867. case 39:
  2868. apelFiltruGauss();
  2869. break;
  2870. case 40:
  2871. apelLaPlace();
  2872. break;
  2873. case 41:
  2874. apelHigh();
  2875. break;
  2876. case 42:
  2877. apelareMedian();
  2878. break;
  2879. case 43:
  2880. apelareGaussian();
  2881. break;
  2882. case 44:
  2883. apelareGaussian2();
  2884. break;
  2885. case 45:
  2886. apelarePrewitt();
  2887. break;
  2888. case 46:
  2889. apelareSobel();
  2890. break;
  2891. case 47:
  2892. cannyTest();
  2893. break;
  2894. }
  2895. }
  2896. while (op!=0);
  2897. return 0;
  2898. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement