Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // OpenCVApplication.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "common.h"
- #include <queue>
- #include <stdio.h>
- #include <string>
- #define WEAK 128
- #define STRONG 255
- void testOpenImage()
- {
- char fname[MAX_PATH];
- while(openFileDlg(fname))
- {
- Mat src;
- src = imread(fname);
- imshow("image",src);
- waitKey();
- }
- }
- void testOpenImagesFld()
- {
- char folderName[MAX_PATH];
- if (openFolderDlg(folderName)==0)
- return;
- char fname[MAX_PATH];
- FileGetter fg(folderName,"bmp");
- while(fg.getNextAbsFile(fname))
- {
- Mat src;
- src = imread(fname);
- imshow(fg.getFoundFileName(),src);
- if (waitKey()==27) //ESC pressed
- break;
- }
- }
- void testImageOpenAndSave()
- {
- Mat src, dst;
- src = imread("Images/Lena_24bits.bmp", CV_LOAD_IMAGE_COLOR); // Read the image
- if (!src.data) // Check for invalid input
- {
- printf("Could not open or find the image\n");
- return;
- }
- // Get the image resolution
- Size src_size = Size(src.cols, src.rows);
- // Display window
- const char* WIN_SRC = "Src"; //window for the source image
- namedWindow(WIN_SRC, CV_WINDOW_AUTOSIZE);
- cvMoveWindow(WIN_SRC, 0, 0);
- const char* WIN_DST = "Dst"; //window for the destination (processed) image
- namedWindow(WIN_DST, CV_WINDOW_AUTOSIZE);
- cvMoveWindow(WIN_DST, src_size.width + 10, 0);
- cvtColor(src, dst, CV_BGR2GRAY); //converts the source image to a grayscale one
- imwrite("Images/Lena_24bits_gray.bmp", dst); //writes the destination to file
- imshow(WIN_SRC, src);
- imshow(WIN_DST, dst);
- printf("Press any key to continue ...\n");
- waitKey(0);
- }
- void testNegativeImage()
- {
- char fname[MAX_PATH];
- while(openFileDlg(fname))
- {
- double t = (double)getTickCount(); // Get the current time [s]
- Mat src = imread(fname,CV_LOAD_IMAGE_GRAYSCALE);
- int height = src.rows;
- int width = src.cols;
- Mat dst = Mat(height,width,CV_8UC1);
- // Asa se acceseaaza pixelii individuali pt. o imagine cu 8 biti/pixel
- // Varianta ineficienta (lenta)
- for (int i=0; i<height; i++)
- {
- for (int j=0; j<width; j++)
- {
- uchar val = src.at<uchar>(i,j);
- uchar neg = MAX_PATH-val;
- dst.at<uchar>(i,j) = neg;
- }
- }
- // Get the current time again and compute the time difference [s]
- t = ((double)getTickCount() - t) / getTickFrequency();
- // Print (in the console window) the processing time in [ms]
- printf("Time = %.3f [ms]\n", t * 1000);
- imshow("input image",src);
- imshow("negative image",dst);
- waitKey();
- }
- }
- void testParcurgereSimplaDiblookStyle()
- {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- int height = src.rows;
- int width = src.cols;
- Mat dst = src.clone();
- double t = (double)getTickCount(); // Get the current time [s]
- // the fastest approach using the “diblook style”
- uchar *lpSrc = src.data;
- uchar *lpDst = dst.data;
- int w = (int) src.step; // no dword alignment is done !!!
- for (int i = 0; i<height; i++)
- for (int j = 0; j < width; j++) {
- uchar val = lpSrc[i*w + j];
- lpDst[i*w + j] = 255 - val;
- }
- // Get the current time again and compute the time difference [s]
- t = ((double)getTickCount() - t) / getTickFrequency();
- // Print (in the console window) the processing time in [ms]
- printf("Time = %.3f [ms]\n", t * 1000);
- imshow("input image",src);
- imshow("negative image",dst);
- waitKey();
- }
- }
- void testColor2Gray()
- {
- char fname[MAX_PATH];
- while(openFileDlg(fname))
- {
- Mat src = imread(fname);
- int height = src.rows;
- int width = src.cols;
- Mat dst = Mat(height,width,CV_8UC1);
- // Asa se acceseaaza pixelii individuali pt. o imagine RGB 24 biti/pixel
- // Varianta ineficienta (lenta)
- for (int i=0; i<height; i++)
- {
- for (int j=0; j<width; j++)
- {
- Vec3b v3 = src.at<Vec3b>(i,j);
- uchar b = v3[0];
- uchar g = v3[1];
- uchar r = v3[2];
- dst.at<uchar>(i,j) = (r+g+b)/3;
- }
- }
- imshow("input image",src);
- imshow("gray image",dst);
- waitKey();
- }
- }
- void testBGR2HSV()
- {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src = imread(fname);
- int height = src.rows;
- int width = src.cols;
- // Componentele d eculoare ale modelului HSV
- Mat H = Mat(height, width, CV_8UC1);
- Mat S = Mat(height, width, CV_8UC1);
- Mat V = Mat(height, width, CV_8UC1);
- // definire pointeri la matricele (8 biti/pixeli) folosite la afisarea componentelor individuale H,S,V
- uchar* lpH = H.data;
- uchar* lpS = S.data;
- uchar* lpV = V.data;
- Mat hsvImg;
- cvtColor(src, hsvImg, CV_BGR2HSV);
- // definire pointer la matricea (24 biti/pixeli) a imaginii HSV
- uchar* hsvDataPtr = hsvImg.data;
- for (int i = 0; i<height; i++)
- {
- for (int j = 0; j<width; j++)
- {
- int hi = i*width * 3 + j * 3;
- int gi = i*width + j;
- lpH[gi] = hsvDataPtr[hi] * 510 / 360; // lpH = 0 .. 255
- lpS[gi] = hsvDataPtr[hi + 1]; // lpS = 0 .. 255
- lpV[gi] = hsvDataPtr[hi + 2]; // lpV = 0 .. 255
- }
- }
- imshow("input image", src);
- imshow("H", H);
- imshow("S", S);
- imshow("V", V);
- waitKey();
- }
- }
- void testResize()
- {
- char fname[MAX_PATH];
- while(openFileDlg(fname))
- {
- Mat src;
- src = imread(fname);
- Mat dst1,dst2;
- //without interpolation
- resizeImg(src,dst1,320,false);
- //with interpolation
- resizeImg(src,dst2,320,true);
- imshow("input image",src);
- imshow("resized image (without interpolation)",dst1);
- imshow("resized image (with interpolation)",dst2);
- waitKey();
- }
- }
- void testCanny()
- {
- char fname[MAX_PATH];
- while(openFileDlg(fname))
- {
- Mat src,dst,gauss;
- src = imread(fname,CV_LOAD_IMAGE_GRAYSCALE);
- double k = 0.4;
- int pH = 50;
- int pL = (int) k*pH;
- GaussianBlur(src, gauss, Size(5, 5), 0.8, 0.8);
- Canny(gauss,dst,pL,pH,3);
- imshow("input image",src);
- imshow("canny",dst);
- waitKey();
- }
- }
- void testVideoSequence()
- {
- VideoCapture cap("Videos/rubic.avi"); // off-line video from file
- //VideoCapture cap(0); // live video from web cam
- if (!cap.isOpened()) {
- printf("Cannot open video capture device.\n");
- waitKey(0);
- return;
- }
- Mat edges;
- Mat frame;
- char c;
- while (cap.read(frame))
- {
- Mat grayFrame;
- cvtColor(frame, grayFrame, CV_BGR2GRAY);
- Canny(grayFrame,edges,40,100,3);
- imshow("source", frame);
- imshow("gray", grayFrame);
- imshow("edges", edges);
- c = cvWaitKey(0); // waits a key press to advance to the next frame
- if (c == 27) {
- // press ESC to exit
- printf("ESC pressed - capture finished\n");
- break; //ESC pressed
- };
- }
- }
- void testSnap()
- {
- VideoCapture cap(0); // open the deafult camera (i.e. the built in web cam)
- if (!cap.isOpened()) // openenig the video device failed
- {
- printf("Cannot open video capture device.\n");
- return;
- }
- Mat frame;
- char numberStr[256];
- char fileName[256];
- // video resolution
- Size capS = Size((int)cap.get(CV_CAP_PROP_FRAME_WIDTH),
- (int)cap.get(CV_CAP_PROP_FRAME_HEIGHT));
- // Display window
- const char* WIN_SRC = "Src"; //window for the source frame
- namedWindow(WIN_SRC, CV_WINDOW_AUTOSIZE);
- cvMoveWindow(WIN_SRC, 0, 0);
- const char* WIN_DST = "Snapped"; //window for showing the snapped frame
- namedWindow(WIN_DST, CV_WINDOW_AUTOSIZE);
- cvMoveWindow(WIN_DST, capS.width + 10, 0);
- char c;
- int frameNum = -1;
- int frameCount = 0;
- for (;;)
- {
- cap >> frame; // get a new frame from camera
- if (frame.empty())
- {
- printf("End of the video file\n");
- break;
- }
- ++frameNum;
- imshow(WIN_SRC, frame);
- c = cvWaitKey(10); // waits a key press to advance to the next frame
- if (c == 27) {
- // press ESC to exit
- printf("ESC pressed - capture finished");
- break; //ESC pressed
- }
- if (c == 115){ //'s' pressed - snapp the image to a file
- frameCount++;
- fileName[0] = NULL;
- sprintf(numberStr, "%d", frameCount);
- strcat(fileName, "Images/A");
- strcat(fileName, numberStr);
- strcat(fileName, ".bmp");
- bool bSuccess = imwrite(fileName, frame);
- if (!bSuccess)
- {
- printf("Error writing the snapped image\n");
- }
- else
- imshow(WIN_DST, frame);
- }
- }
- }
- void MyCallBackFunc(int event, int x, int y, int flags, void* param)
- {
- //More examples: http://opencvexamples.blogspot.com/2014/01/detect-mouse-clicks-and-moves-on-image.html
- Mat* src = (Mat*)param;
- if (event == CV_EVENT_LBUTTONDOWN)
- {
- /*printf("Pos(x,y): %d,%d Color(RGB): %d,%d,%d\n",
- x, y,
- (int)(*src).at<Vec3b>(y, x)[2],
- (int)(*src).at<Vec3b>(y, x)[1],
- (int)(*src).at<Vec3b>(y, x)[0]);*/
- }
- }
- void testMouseClick()
- {
- Mat src;
- // Read image from file
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- src = imread(fname);
- //Create a window
- namedWindow("My Window", 1);
- //set the callback function for any mouse event
- setMouseCallback("My Window", MyCallBackFunc, &src);
- //show the image
- imshow("My Window", src);
- // Wait until user press some key
- waitKey(0);
- }
- }
- /* Histogram display function - display a histogram using bars (simlilar to L3 / PI)
- Input:
- name - destination (output) window name
- hist - pointer to the vector containing the histogram values
- hist_cols - no. of bins (elements) in the histogram = histogram image width
- hist_height - height of the histogram image
- Call example:
- showHistogram ("MyHist", hist_dir, 255, 200);
- */
- void showHistogram(const std::string& name, int* hist, const int hist_cols, const int hist_height)
- {
- Mat imgHist(hist_height, hist_cols, CV_8UC3, CV_RGB(255, 255, 255)); // constructs a white image
- //computes histogram maximum
- int max_hist = 0;
- for (int i = 0; i<hist_cols; i++)
- if (hist[i] > max_hist)
- max_hist = hist[i];
- double scale = 1.0;
- scale = (double)hist_height / max_hist;
- int baseline = hist_height - 1;
- for (int x = 0; x < hist_cols; x++) {
- Point p1 = Point(x, baseline);
- Point p2 = Point(x, baseline - cvRound(hist[x] * scale));
- line(imgHist, p1, p2, CV_RGB(255, 0, 255)); // histogram bins colored in magenta
- }
- imshow(name, imgHist);
- }
- //************* lab 1 **************
- void negative_image()
- {
- Mat img = imread("Images/cameraman.bmp",CV_LOAD_IMAGE_GRAYSCALE);
- for (int i = 0; i<img.rows; i++) {
- for (int j = 0; j<img.cols; j++) {
- img.at<uchar>(i, j) = 255 - img.at<uchar>(i, j);
- }
- }
- imshow("negative image", img);
- waitKey(0);
- }
- //Implementaţi o funcţie care schimbă nivelele de gri cu un factor aditiv
- void changeGray(int factor)
- {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src;
- src = imread(fname,CV_LOAD_IMAGE_GRAYSCALE);
- Mat img(src.rows, src.cols, CV_8UC1);
- for (int i = 0; i < src.rows; i++)
- {
- for (int j = 0; j < src.cols; j++)
- {
- if (src.at<uchar>(i, j) + factor > 255)
- {
- img.at<uchar>(i, j) = 255;
- }
- else {
- img.at<uchar>(i, j) =src.at<uchar>(i,j)+ factor;
- }
- }
- }
- imshow("Imagine", src);
- imshow("Imagine schimbata", img);
- waitKey(0);
- }
- }
- //Implementaţi o funcţie care schimbă nivelele de gri cu un factor multiplicativ. Salvaţi
- //imaginea rezultat.
- void changeGrayMulti(int factor)
- {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src;
- src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- Mat img(src.rows, src.cols, CV_8UC1);
- for (int i = 0; i < src.rows; i++)
- {
- for (int j = 0; j < src.cols; j++)
- {
- if (src.at<uchar>(i, j) * factor > 255)
- {
- img.at<uchar>(i, j) = 255;
- }
- else {
- img.at<uchar>(i,j)=src.at<uchar>(i, j) * factor;
- }
- }
- }
- imshow("Imagine", src);
- imshow("Imagine schimbata", img);
- waitKey(0);
- imwrite("Imagine.png", img);
- }
- }
- /*Creaţi o imagine color de dimensiune 256 x 256. Împărţiţi imaginea în 4 sectoare pătrate,
- şi coloraţi aceste sectoare, din stânga-sus până în dreapta-jos, astfel: alb, roşu, verde,
- galben.*/
- void patruSectoare()
- {
- Mat img(256, 256, CV_8UC3);
- for (int i = 0; i < img.rows; i++)
- {
- for (int j = 0; j < img.cols; j++)
- {
- if (i < img.rows/2 && j < img.cols/2)
- {
- img.at<Vec3b>(i, j) = Vec3b(255, 255, 255);
- }
- if (i<img.rows/2 && j>img.cols/2)
- {
- img.at<Vec3b>(i, j) = Vec3b(0, 0, 255);
- }
- if (i>img.rows/2 && j<img.cols/2)
- {
- img.at<Vec3b>(i, j) = Vec3b(0, 255,0);
- }
- if (i>img.rows/2 && j>img.cols/2)
- {
- img.at<Vec3b>(i, j) = Vec3b(0, 255, 255);
- }
- }
- }
- imshow("Imagine", img);
- waitKey(0);
- }
- void inv()
- {
- }
- //***************** LAB 2 *************************
- void copiazaCanale()
- {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src;
- src = imread(fname,CV_LOAD_IMAGE_COLOR);
- Mat img1(src.rows, src.cols, CV_8UC1);
- Mat img2(src.rows, src.cols, CV_8UC1);
- Mat img3(src.rows, src.cols, CV_8UC1);
- for (int i = 0; i < src.rows; i++)
- {
- for (int j = 0; j < src.cols; j++)
- {
- img1.at<uchar>(i, j) = src.at<Vec3b>(i, j)[2];
- img2.at<uchar>(i, j) = src.at<Vec3b>(i, j)[1];
- img3.at<uchar>(i, j) = src.at<Vec3b>(i, j)[0];
- }
- }
- imshow("Imagine", src);
- imshow("Imagine1", img1);
- imshow("Imagine2", img2);
- imshow("Imagine3", img3);
- waitKey(0);
- }
- }
- void colorToGray()
- {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src;
- src = imread(fname, CV_LOAD_IMAGE_COLOR);
- Mat an(src.rows, src.cols, CV_8UC1);
- for (int i = 0; i < src.rows; i++)
- {
- for (int j = 0; j < src.cols; j++)
- {
- an.at<uchar>(i, j) = (src.at<Vec3b>(i, j)[0] + src.at<Vec3b>(i, j)[1] + src.at<Vec3b>(i, j)[2]) / 3;
- }
- }
- imshow("Imagine", src);
- imshow("GreyScale", an);
- waitKey(0);
- }
- }
- void grayToALb()
- {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src;
- src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- int prag;
- std::cout << " Prag: " << std::endl;
- std::cin >> prag;
- Mat an(src.rows, src.cols, CV_8UC1);
- for (int i = 0; i < src.rows; i++)
- {
- for (int j = 0; j < src.cols; j++)
- {
- if (src.at<uchar>(i, j) < prag)
- {
- an.at<uchar>(i, j) = 0;
- }
- if (src.at<uchar>(i, j) >= prag)
- {
- an.at<uchar>(i, j) = 255;
- }
- }
- }
- imshow("Imagine", src);
- imshow("Alb-Negru", an);
- }
- }
- void convertHSV()
- {
- float r, g, b, R, G, B, m, M,C, H, S, V;
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src;
- src = imread(fname, CV_LOAD_IMAGE_COLOR);
- Mat img1(src.rows, src.cols, CV_8UC1);
- Mat img2(src.rows, src.cols, CV_8UC1);
- Mat img3(src.rows, src.cols, CV_8UC1);
- for (int i = 0; i < src.rows; i++)
- {
- for (int j = 0; j < src.cols; j++)
- {
- R = (float)src.at<Vec3b>(i, j)[2];
- r = R / 255;
- B = (float)src.at<Vec3b>(i, j)[0];
- b = B / 255;
- G = (float)src.at<Vec3b>(i, j)[1];
- g = G / 255;
- M = max(r, g, b);
- m = min(r, g, b);
- C = M - m;
- V = M;
- if (V != 0) S = C / V;
- else S = 0;
- if (C != 0){
- if (M == r) H = 60 * (g - b) / C;
- if (M == g) H = 120 + 60 * (b - r) / C;
- if (M == b) H = 240 + 60 * (r - g) / C;
- }
- else H = 0;
- if (H < 0) H = H + 360;
- img1.at<uchar>(i, j) = H * 255 / 360;
- img2.at<uchar>(i, j) = S * 255;
- img3.at<uchar>(i, j) = V * 255;
- }
- }
- imshow("Imagine", src);
- imshow("Hue", img1);
- imshow("Saturation", img2);
- imshow("Value", img3);
- waitKey(0);
- }
- }
- void isInside(Mat img, int i,int j)
- {
- if (img.rows > i && i >= 0)
- if (img.cols > j && j >= 0)
- std::cout << "SE AFLA IN INTERIOR";
- getchar();
- getchar();
- }
- //***************** LAB 3 *************
- void DrawCross(Mat& img, Point p, int size, Scalar color, int thickness)
- {
- line(img, Point(p.x - size / 2, p.y), Point(p.x + size / 2, p.y), color, thickness, 8);
- line(img, Point(p.x, p.y - size / 2), Point(p.x, p.y + size / 2), color, thickness, 8);
- }
- void proprietati(int event, int x, int y, int flags, void* param)
- {
- //More examples: http://opencvexamples.blogspot.com/2014/01/detect-mouse-clicks-and-moves-on-image.html
- Mat* src = (Mat*)param;
- Vec3b culoare;
- int aria = 0;
- int ri = 0;
- int ci = 0;
- int perim = 0;
- float phi = 0;
- int factor = 0;
- int a = 0, a1 = 0, a2 = 0;
- int rmax = 0,cmax=0;
- int rmin = (*src).rows;
- int cmin = (*src).cols;
- Mat img1((*src).rows, (*src).cols, CV_8UC3);
- for (int i = 0; i < (*src).rows; i++)
- {
- for (int j = 0; j < (*src).cols; j++)
- {
- img1.at<Vec3b>(i, j) = (*src).at<Vec3b>(i, j);
- }
- }
- if (event == CV_EVENT_LBUTTONDOWN)
- {
- culoare = (*src).at<Vec3b>(y, x);
- for (int i = 0; i < (*src).rows; i++)
- {
- for (int j = 0; j < (*src).cols; j++)
- {
- if ((*src).at<Vec3b>(i,j) == culoare)
- {
- if (i >= rmax)
- {
- rmax = i;
- }
- else if (i <= rmin)
- {
- rmin = i;
- }
- if (j>=cmax)
- {
- cmax = j;
- }
- else if (j <= cmin)
- {
- cmin = j;
- }
- aria++;
- ri += i;
- ci += j;
- }
- }
- }
- ri = ri/aria;
- ci = ci/ aria;
- for (int i = 0; i < (*src).rows; i++)
- {
- for (int j = 0; j < (*src).cols; j++)
- {
- if ((*src).at<Vec3b>(i, j) == culoare)
- {
- a += (i - ri)*(j - ci);
- a1 += (j - ci)*(j - ci);
- a2 += (i - ri)*(i - ri);
- }
- }
- }
- phi = atan2(2*a, (a1 - a2))/2;
- for (int i = 0; i < (*src).rows; i++)
- {
- for (int j = 0; j < (*src).cols; j++)
- {
- if ((*src).at<Vec3b>(i, j) == culoare)
- {
- if ((*src).at<Vec3b>(i - 1, j - 1) != culoare || (*src).at<Vec3b>(i - 1, j) != culoare
- || (*src).at<Vec3b>(i - 1, j + 1) != culoare || (*src).at<Vec3b>(i, j - 1) != culoare
- || (*src).at<Vec3b>(i, j + 1) != culoare || (*src).at<Vec3b>(i + 1, j) != culoare
- || (*src).at<Vec3b>(i + 1, j - 1) != culoare || (*src).at<Vec3b>(i + 1, j + 1) != culoare){
- perim++;
- img1.at<Vec3b>(i, j) = Vec3b(0, 0, 0);
- }
- }
- }
- }
- float factor = 4 *PI*aria / (perim*perim);
- float aspect = (cmax - cmin + 1) / (rmax - rmin + 1);
- DrawCross(img1, Point(ci, ri), 20, Scalar(255, 255, 255), 2);
- int delta = 30; // arbitrary value
- Point P1, P2;
- P1.x = ci - delta;
- P1.y = ri - (int)(delta*tan(phi)); // teta is the elongation angle in radians
- P2.x = ci + delta;
- P2.y = ri + (int)(delta*tan(phi));
- line(img1, P1, P2, Scalar(0, 0, 0), 1, 8);
- std::cout << "Aria este : " << aria << std::endl;
- std::cout << " Centrul de masa este: " << ri << " + " << ci << std::endl;
- std::cout << "Axa de alungire : " << phi*180/PI<< std::endl;
- std::cout << "Perimetru este : " << perim << std::endl;
- std::cout << "Subtiere : " << factor<< std::endl;
- std::cout << " Aspect ratio : " << aspect<< std::endl;
- /*Mat dest((*src).rows, (*src).cols, CV_8UC3);
- int x_vec[500] = {0};
- int y_vec[500] = {0};
- for (int i = 0; i < (*src).rows; i++) {
- int value = 0;
- for (int j = 0; j < (*src).cols; j++) {
- if ((*src).at<Vec3b>(i, j) == culoare) {
- value++;
- }
- }
- x_vec[i] = value;
- }
- for (int i = 0; i < (*src).cols; i++) {
- int value = 0;
- for (int j = 0; j < (*src).rows; j++) {
- if ((*src).at<Vec3b>( j,i) == culoare) {
- value++;
- }
- }
- y_vec[i] = value;
- }
- h[i] = value; k < dest.cols; k++) {
- line(dest, Point(k, 0), Point(k, y_vec[k]), 5);
- }
- for (int k = 0; k < dest.rows; k++) {
- line(dest, Point(k, 0), Point(k, x_vec[k]), 5);
- }*/
- Mat dst2 = (*src).clone();
- Mat proj = Mat((*src).size(), CV_8UC3);
- int horizontalProj[1000] = { 0 };
- int verticalProj[1000] = { 0 };
- for (int i = 0; i < dst2.rows; i++) {
- for (int j = 0; j < dst2.cols; j++) {
- if (dst2.at<Vec3b>(i, j)==culoare) {
- horizontalProj[j]++;
- verticalProj[i]++;
- }
- }
- }
- for (int j = 0; j < dst2.cols; j++) {
- line(proj, Point(j, 0), Point(j, horizontalProj[j]), Scalar(255, 255, 255), 3);
- }
- for (int i = 0; i < dst2.rows; i++) {
- line(proj, Point(0, i), Point(verticalProj[i], i), Scalar(255, 255, 255), 3);
- }
- imshow("Proiectii", proj);
- imshow("Perimetru", img1);
- }
- //imshow("1", img1);
- //waitKey(0);
- }
- void testMouseClickProprietati()
- {
- Mat src;
- // Read image from file
- src = imread("Obiecte multiple\\trasaturi_geom.bmp",CV_LOAD_IMAGE_COLOR);
- //Create a window
- namedWindow("My Window", 1);
- //set the callback function for any mouse event
- setMouseCallback("My Window", proprietati, &src);
- //show the image
- imshow("My Window", src);
- // Wait until user press some key
- waitKey(0);
- }
- /////////////////// LAB 5 ////////////////////
- void traversare()
- {
- Mat src = imread("Images/labeling2.bmp", CV_LOAD_IMAGE_GRAYSCALE);
- Mat labels = Mat::zeros(src.rows, src.cols, CV_16SC1);
- Mat dst = Mat::zeros(src.rows, src.cols, CV_8UC3);
- int di[8] = {-1, 0, 1, 0 ,1,-1,1,-1};
- int dj[8] = { 0, -1, 0, 1 ,1,1,-1,-1};
- int label = 0;
- for (int i = 0; i < src.rows; i++)
- {
- for (int j = 0; j < src.cols; j++)
- {
- if (src.at<uchar>(i, j) == 0 && labels.at<short>(i, j) == 0)
- { std::queue<Point2i> Q;
- label++;
- Q.push({i, j});
- labels.at<short>(i, j) = label;
- while (!Q.empty())
- {
- Point q = Q.front();
- Q.pop();
- for (int k = 0; k < 8; k++)
- {
- 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)
- {
- labels.at<short>(q.x + di[k], q.y + dj[k]) = label;
- Q.push({ q.x + di[k], q.y + dj[k] });
- }
- }
- }
- }
- }
- }
- Scalar colorLUT[1000] = { 0 };
- Scalar color;
- for (int i = 1; i < 1000; i++)
- {
- Scalar color(rand() & 255, rand() & 255, rand() & 255);
- colorLUT[i] = color;
- }
- colorLUT[0] = Scalar(255, 255, 255);
- for (int i = 1; i < dst.rows - 1; i++)
- for (int j = 1; j < dst.cols - 1; j++)
- {
- Scalar color = colorLUT[labels.at<short>(i, j)]; // valabil pt. Met. 1 BFS
- dst.at<Vec3b>(i, j)[0] = color[0];
- dst.at<Vec3b>(i, j)[1] = color[1];
- dst.at<Vec3b>(i, j)[2] = color[2];
- }
- imshow("img", dst);
- waitKey(0);
- }
- void alg2()
- {
- Mat src = imread("Images/labeling2.bmp", CV_LOAD_IMAGE_GRAYSCALE);
- Mat labels = Mat::zeros(src.rows, src.cols, CV_16SC1);
- Mat dstP = Mat::zeros(src.rows, src.cols, CV_8UC3);
- Mat dstF = Mat::zeros(src.rows, src.cols, CV_8UC3);
- int di[4] = { -1,-1,-1,0 };
- int dj[4] = { -1,0,1,-1 };
- int label = 0;
- std::vector<std::vector<int>> edges;
- for (int i = 0; i < src.rows; i++)
- {
- for (int j = 0; j < src.cols; j++)
- {
- if (src.at<uchar>(i, j) == 0 && labels.at<short>(i, j) == 0)
- {
- std::vector<int> L;
- for (int k = 0; k < 4; k++)
- {
- if (labels.at<short>(i + di[k], j + dj[k]) > 0)
- {
- L.push_back(labels.at<short>(i + di[k], j + dj[k]));
- }
- }
- if (L.size() == 0)
- {
- label++;
- labels.at<short>(i, j) = label;
- }
- else
- {
- int x = *min_element(L.begin(), L.end());
- labels.at<short>(i, j) = x;
- for (int y :L)
- {
- if (L[y] != x)
- {
- edges.resize(label + 1);
- edges[x].push_back(y);
- edges[y].push_back(x);
- }
- }
- }
- }
- }
- }
- int newlabel = 0;
- int* newlabels = (int*)calloc(label+1, sizeof(int));
- for (int i = 1; i <= label; i++)
- {
- if (newlabels[i] == 0)
- {
- newlabel++;
- std::queue<int> Q;
- newlabels[i] = newlabel;
- Q.push(i);
- while (!Q.empty())
- {
- int x = Q.front();
- Q.pop();
- for (int t:edges[x])
- {
- if (newlabels[t] == 0)
- {
- newlabels[t] = newlabel;
- Q.push(t);
- }
- }
- }
- }
- }
- free(newlabels);
- }
- ////////////////// LAB 6 ////////////////////////////////
- typedef struct {
- int i, j; // coordonata pixelului de contur
- byte c; //codul inlantuit
- }point;
- void border()
- {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- int dj[8] = { 1, 1, 0, -1, -1, -1, 0, 1 }; // rand (coordonata orizontala)
- int di[8] = { 0, -1, -1, -1, 0, 1, 1, 1 }; // coloana (coordonata verticala)
- Mat src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- int height = src.rows;
- int width = src.cols;
- Mat dst = Mat(height, width, CV_8UC1, Scalar(255));
- std::vector <point> contur;
- Point start;
- bool primul = false;
- for (int i = 0; (i < height) && primul == false; i++)
- {
- for (int j = 0; j < width; j++)
- {
- if (src.at<uchar>(i, j) == 0)
- {
- dst.at<uchar>(i, j) = 0;
- start = { i, j };
- primul = true;
- break;
- }
- }
- }
- int dir = 7;
- contur.push_back(point{ start.x, start.y,7 });
- int n = 0;
- bool finish = false;
- int i = start.x;
- int j = start.y;
- while (!finish)
- {
- if (dir % 2 == 0) {
- dir = (dir + 7) % 8;
- }else
- {
- dir = (dir + 6) % 8;
- }
- while(src.at<uchar>(i+di[dir],j+dj[dir])!=0)
- {
- dir = dir + 1;
- if (dir == 8) {
- dir = 0;
- }
- }
- contur.push_back(point{ i + di[dir], j + dj[dir], (byte)dir });
- i += di[dir];
- j += dj[dir];
- n++;
- 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) {
- finish = true;
- }
- }
- int d;
- printf("cod inlantuit: ");
- for (int i = 1; i < contur.size() - 1; i++)
- {
- dst.at<uchar>(contur.at(i).i, contur.at(i).j) = 0;
- printf("%d ", contur.at(i).c);
- }
- printf("\n\n");
- printf("derivata : ");
- for (int i = 0; i < contur.size() - 1; i++)
- {
- //calcularea derivatei
- d = (8 + contur.at(i + 1).c - contur.at(i).c) % 8;
- printf("%d ", d);
- }
- printf("\n\n");
- imshow("contur imagine", dst);
- waitKey(0);
- }
- }
- void reconstruct()
- {
- FILE* fp = fopen("Images/reconstruct.txt", "rt");
- if (!fp)
- {
- printf("Error opening the text file!\n");
- }
- int x, y, N, v;
- fscanf(fp, "%d", &x);
- fscanf(fp, "%d", &y);
- fscanf(fp, "%d", &N);
- std::vector<int> vectorint;
- for (int i = 0; i < N; i++)
- {
- fscanf(fp, "%d", &v);
- vectorint.push_back(v);
- }
- printf("%d %d \n %d \n", x, y, N);
- Mat img = imread("Images/gray_background.bmp", CV_LOAD_IMAGE_GRAYSCALE);
- Mat dst = Mat(img.rows, img.cols, CV_8UC1, Scalar(255));
- int dj[8] = { 1, 1, 0, -1, -1, -1, 0, 1 }; // rand (coordonata orizontala)
- int di[8] = { 0, -1, -1, -1, 0, 1, 1, 1 }; // coloana (coordonata verticala)
- for (int i = 0; i < vectorint.size(); i++)
- {
- dst.at<uchar>(x, y) = 0;
- x += di[vectorint.at(i)];
- y += dj[vectorint.at(i)];
- }
- imshow("dst", dst);
- waitKey(0);
- }
- /////////////////////////// LAB 7 /////////////////////
- Mat dilatare(Mat src)
- {
- Mat dst = src.clone();
- int dj[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
- int di[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
- for (int i = 1; i < src.rows - 1; i++)
- {
- for (int j = 1; j < src.cols - 1; j++)
- {
- if (src.at<uchar>(i, j) == 0)
- for (int l = 0; l < 8; l++)
- {
- dst.at<uchar>(di[l] + i, dj[l] + j) = 0;
- }
- }
- }
- imshow("Imagine dilatata", dst);
- waitKey(0);
- return dst;
- }
- Mat eroziune(Mat src)
- {
- Mat dst = src.clone();
- int dj[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
- int di[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
- for (int i = 1; i < src.rows - 1; i++)
- {
- for (int j = 1; j < src.cols - 1; j++)
- {
- if (src.at<uchar>(i, j) == 0)
- for (int l = 0; l < 8; l++)
- {
- if (src.at<uchar>(di[l] + i, dj[l] + j) == 255){
- dst.at<uchar>(i, j) = 255;
- break;
- }
- }
- }
- }
- imshow("Imagine erodata", dst);
- waitKey(0);
- return dst;
- }
- Mat inchidere(Mat src)
- {
- Mat dilatata = dilatare(src);
- Mat erodata = eroziune(dilatata);
- imshow("Imagine finala",erodata);
- waitKey(0);
- return erodata;
- }
- void inchidereapelNori(int n)
- {
- Mat src = imread("Images/4_Close/phn1thr1_bw.bmp", 0);
- imshow("src", src);
- getchar();
- for (int i = 0; i < n; i++)
- {
- src = inchidere(src);
- }
- imshow("Final", src);
- waitKey(0);
- }
- Mat deschidere(Mat src)
- {
- Mat erodata = eroziune(src);
- Mat dilatata = dilatare(erodata);
- imshow("Imagine finala", dilatata);
- //imshow("Imagine originala", src);
- waitKey(0);
- return erodata;
- }
- void deschhidereapelNori(int n)
- {
- Mat src = imread("Images/3_Open/cel4thr3_bw.bmp", 0);
- imshow("src", src);
- for (int i = 0; i < n; i++)
- {
- src = deschidere(src);
- }
- imshow("Final", src);
- waitKey(0);
- }
- void dilatare_apelNori(int n)
- {
- Mat src = imread("Images/1_Dilate/mon1thr1_bw.bmp", 0);
- imshow("src", src);
- for (int i = 0; i < n; i++)
- {
- src = dilatare(src);
- }
- imshow("Final", src);
- waitKey(0);
- }
- void eroziune_apelNori(int n)
- {
- Mat src = imread("Images/1_Dilate/mon1thr1_bw.bmp", 0);
- imshow("src", src);
- for (int i = 0; i < n; i++)
- {
- src = eroziune(src);
- }
- imshow("Final", src);
- waitKey(0);
- }
- void contur()
- {
- Mat src = imread("Images/5_BoundaryExtraction/wdg2thr3_bw.bmp", 0);
- Mat dst = src.clone();
- imshow("src", src);
- Mat temp = eroziune(src);
- for (int i = 0; i < src.rows; i++)
- {
- for (int j = 0; j < src.cols; j++)
- {
- if (src.at<uchar>(i, j) != temp.at<uchar>(i, j))
- dst.at<uchar>(i, j) = 0;//FG
- else dst.at<uchar>(i, j) = 255;//BG
- }
- }
- imshow("Imagine originala", src);
- imshow("Contur", dst);
- waitKey(0);
- }
- void umplere_regiuni(int x, int y)
- {
- Mat src = imread("Images/6_RegionFilling/reg1neg1_bw.bmp", 0);
- Mat compl = Mat(src.rows, src.cols, CV_8UC1, Scalar(255));
- Mat X1 = Mat(src.rows, src.cols, CV_8UC1, Scalar(255));
- Mat X2 = Mat(src.rows, src.cols, CV_8UC1, Scalar(255));
- Mat dst = Mat(src.rows, src.cols, CV_8UC1, Scalar(255));
- Mat temp;
- bool finish = false;
- for (int i = 0; i < src.rows; i++)
- {
- for (int j = 0; j < src.cols; j++)
- {
- compl.at<uchar>(i, j) = 255 - src.at<uchar>(i, j);
- }
- }
- for (int i = 0; i < src.rows; i++)
- {
- for (int j = 0; j < src.cols; j++)
- {
- if (i == x&&y == j)
- {
- X1.at<uchar>(i, j) = 0;
- }
- }
- }
- do
- {
- finish = true;
- temp = dilatare(X1);
- for (int i = 0; i < src.rows; i++)
- {
- for (int j = 0; j < src.cols; j++)
- {
- if (temp.at<uchar>(i, j) == compl.at<uchar>(i, j))
- {
- X2.at<uchar>(i, j) = temp.at<uchar>(i, j);
- }
- else
- {
- X2.at<uchar>(i, j) = 255;
- }
- }
- }
- for (int i = 0; i < src.rows; i++)
- {
- for (int j = 0; j < src.cols; j++)
- {
- if (X1.at<uchar>(i, j) != X2.at<uchar>(i, j))
- {
- finish = false;
- break;
- }
- }
- }
- X1 = X2.clone();
- } while (!finish);
- for (int i = 0; i < src.rows; i++)
- {
- for (int j = 0; j < src.cols; j++)
- {
- if (X2.at<uchar>(i, j) == 0 || src.at<uchar>(i, j) == 0)
- {
- dst.at<uchar>(i, j) = 0;
- }
- }
- }
- imshow("src", src);
- imshow("complement", compl);
- imshow("Final", dst);
- waitKey(0);
- }
- ///////////////////////////////////// LAB 8//////////////////////////
- int* calculHistograma(Mat img) {
- int *hist = (int*)malloc(sizeof(int) * 256);
- for (int i = 0; i < 256; i++)
- hist[i] = 0;
- for (int i = 0; i < img.rows; i++)
- for (int j = 0; j < img.cols; j++)
- hist[img.at<uchar>(i, j)]++;
- return hist;
- }
- void calcule(Mat img) {
- int M = img.rows * img.cols;
- int* hist = calculHistograma(img);
- showHistogram("histogram", hist, 256, 200);
- // niv maxim de intensitate
- int L = 255;
- float fdp[256];
- for (int i = 0; i <= L; i++)
- fdp[i] = 0;
- for (int g = 0; g <= L; g++)
- fdp[g] = (float)hist[g] / M;
- for (int g = 0; g <= L; g++)
- printf("%f.", fdp[g]);
- // val medie a niv de intensitate
- float medie = 0.0;
- for (int g = 0; g <= L; g++)
- medie += fdp[g] * g;
- // deviatie standard
- float deviatie = 0.0;
- for (int g = 0; g <= L; g++)
- deviatie += pow(g - medie, 2) * fdp[g];
- deviatie = sqrt(deviatie);
- printf("Valoare medie: %f.\n", medie);
- printf("Deviatie standard: %f.\n", deviatie);
- }
- void testHistograma()
- {
- char fname[MAX_PATH];
- while (openFileDlg(fname)) {
- Mat img = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- int* histograma = calculHistograma(img);
- showHistogram("histogram", histograma, 256, 200);
- imshow("src", img);
- waitKey(0);
- }
- }
- void testHistogramaFDP() {
- Mat img = imread("Images/balloons.bmp", CV_LOAD_IMAGE_GRAYSCALE);
- imshow("src", img);
- calcule(img);
- waitKey(0);
- }
- void pragBinarizare(Mat img) {
- // nr de pixeli ai imaginii
- int M = img.rows * img.cols;
- int* hist = calculHistograma(img);
- showHistogram("histogram", hist, 256, 200);
- // fdp
- float fdp[256] = {};
- for (int g = 0; g < 256; g++)
- fdp[g] = (float)hist[g] / M;
- float T;
- int iMin = 0, iMax = 256;
- T = (iMax + iMin) / 2.0;
- float Tn;
- do
- {
- int Nmic = 0, Nmare = 0;
- float medieMica = 0, medieMare = 0;
- for (int g = 0; g <= T; g++)
- Nmic += hist[g];
- for (int g = 255; g > T; g--)
- Nmare += hist[g];
- for (int g = 0; g <= T; g++)
- medieMica += hist[g] * g;
- for (int g = 255; g > T; g--)
- medieMare += hist[g] * g;
- Tn = T;
- float min = medieMica / Nmic;
- float max = medieMare / Nmare;
- T = (min +max) / 2.0;
- } while (abs(Tn - T) > 0.5);
- printf("Prag de binarizare: %f.\n", T);
- Mat dest = img.clone();
- for (int i = 0; i < img.rows; i++)
- for (int j = 0; j < img.cols; j++)
- if (img.at<uchar>(i, j) < 165)
- dest.at<uchar>(i, j) = 0;
- else
- dest.at<uchar>(i, j) = 255;
- imshow("Binarizare", dest);
- }
- void testPragBinarizare() {
- Mat img = imread("Images/eight.bmp", CV_LOAD_IMAGE_GRAYSCALE);
- imshow("src", img);
- pragBinarizare(img);
- waitKey(0);
- }
- void LumGamma(Mat img,int offset,float gamma, int gOUTmin, int gOUTmax) {
- imshow("Src", img);
- showHistogram("src", calculHistograma(img), 256, 200);
- Mat lum = img.clone();
- printf("Luminozitate: offset = %d\n", offset);
- for (int i = 0; i < img.rows; i++)
- for (int j = 0; j < img.cols; j++) {
- int suma = img.at<uchar>(i, j) + offset;
- if (suma > 255)suma = 255;
- if (suma < 0) suma = 0;
- lum.at<uchar>(i, j) = suma;
- }
- imshow("Luminozitate", lum);
- showHistogram("luminozitate", calculHistograma(lum), 256, 200);
- // corectia gamma
- Mat gam = img.clone();
- printf("Corectie gamma: gamma = %f\n", gamma);
- for (int i = 0; i < img.rows; i++)
- for (int j = 0; j < img.cols; j++) {
- float aux = pow((float)img.at<uchar>(i, j) / 255, gamma) * 255;
- if (aux > 255)
- aux = 255;
- if (aux < 0)
- aux = 0;
- gam.at<uchar>(i, j) = (int)aux;
- }
- imshow("Corectia gamma", gam);
- showHistogram("gamma", calculHistograma(gam), 256, 200);
- // modificarea contrastului
- int gmin = 255;
- int gmax = 0;
- int* hist = calculHistograma(img);
- for (int i = 0; i < 255; i++) {
- if (hist[i] != 0 && i < gmin)
- gmin = i;
- if (hist[i] != 0 && i > gmax)
- gmax = i;
- }
- Mat contrast = img.clone();
- printf("Contrast:\n");
- printf("G in min = %d\n", gmin);
- printf("G in max = %d\n", gmax);
- printf("G out min = %d\n", gOUTmin);
- printf("G out max = %d\n", gOUTmax);
- for (int i = 0; i < img.rows; i++)
- for (int j = 0; j < img.cols; j++) {
- float aux = gOUTmin + (img.at<uchar>(i, j) - gmin) * (gOUTmax - gOUTmin) / (gmax - gmin);
- if (aux > 255)
- aux = 255;
- if (aux < 0)
- aux = 0;
- contrast.at<uchar>(i, j) = (int)aux;
- }
- imshow("Contrast", contrast);
- showHistogram("contrast", calculHistograma(contrast), 256, 200);
- }
- void testCalculeHistograma(int offset,float gamma, int gOUTmin, int gOUTmax) {
- Mat img = imread("Images/wilderness.bmp", CV_LOAD_IMAGE_GRAYSCALE);
- imshow("src", img);
- LumGamma(img,offset,gamma,gOUTmin, gOUTmax);
- waitKey(0);
- }
- void egalizareHisto(Mat img) {
- int *hist = calculHistograma(img);
- showHistogram("histogram SRC", hist, 256, 200);
- int hc[256] ;
- int tab[256];
- hc[0] = 0;
- for (int g = 1; g < 256; g++)
- tab[g] = 0;
- for (int g = 1; g < 256; g++)
- hc[g] = hc[g - 1] + hist[g];
- Mat dst = img.clone();
- int M = img.rows * img.cols;
- for (int g = 0; g < 256; g++)
- tab[g] = 255 * hc[g] / M;
- for (int i = 0; i < img.rows; i++)
- for (int j = 0; j < img.cols; j++)
- dst.at<uchar>(i, j) = tab[img.at<uchar>(i, j)];
- int *histDst = calculHistograma(dst);
- imshow("dst", dst);
- showHistogram("histogram DST", histDst, 256, 200);
- }
- void testEgalizareHisto() {
- Mat img = imread("Images\baloons.bmp", CV_LOAD_IMAGE_GRAYSCALE);
- imshow("src", img);
- egalizareHisto(img);
- waitKey(0);
- }
- /////////////////////////// LAB 9 //////////////////
- Mat filtru1(Mat src, Mat filtru)
- {
- Mat dst = Mat(src.rows, src.cols, CV_8UC1);
- int i, j, i2 = 0, j2 = 0;
- int pixel = 0;
- int sum = 0;
- for (i = 0; i < filtru.rows; i++)
- for (j = 0; j < filtru.cols; j++)
- {
- sum = sum + filtru.at<short>(i, j);
- }
- for (i = 1; i < src.rows - 1; i++)
- for (j = 1; j < src.cols - 1; j++)
- {
- pixel = 0;
- for (i2 = 0; i2 < filtru.rows; i2++)
- for (j2 = 0; j2 < filtru.cols; j2++)
- pixel = pixel + (filtru.at<short>(i2, j2) * src.at<uchar>(i + i2 - 1, j + j2 - 1));
- if (sum != 0)
- {
- pixel /= sum;
- }
- if (pixel >= 255) {
- pixel = 255;
- }
- if (pixel <= 0)
- {
- pixel = 0;
- }
- dst.at<uchar>(i, j) = pixel;
- }
- printf("Sum=%d \n", sum);
- return dst;
- }
- Mat convolutie(Mat src, Mat filtru)
- {
- Mat dst = Mat(src.rows, src.cols, CV_8UC1);
- int i, j, i2 = 0, j2 = 0;
- int pixel = 0;
- int sum = 0;
- for (i = 0; i < filtru.rows; i++)
- for (j = 0; j < filtru.cols; j++)
- {
- sum = sum + filtru.at<short>(i, j);
- }
- for (i = 1; i < src.rows - 1; i++)
- for (j = 1; j < src.cols - 1; j++)
- {
- pixel = 0;
- for (i2 = 0; i2 < filtru.rows; i2++)
- for (j2 = 0; j2 < filtru.cols; j2++)
- pixel = pixel + (filtru.at<short>(i2, j2) * src.at<uchar>(i + i2 - 1, j + j2 - 1));
- if (pixel >= 255) {
- pixel = 255;
- }
- if (pixel <= 0)
- {
- pixel = 0;
- }
- dst.at<uchar>(i, j) = pixel;
- }
- printf("Sum=%d \n", sum);
- return dst;
- }
- Mat filtruMedie() {
- Mat filtru = Mat(3, 3, CV_16SC1);
- filtru.at<short>(0, 0) = 1;
- filtru.at<short>(0, 1) = 1;
- filtru.at<short>(0, 2) = 1;
- filtru.at<short>(1, 0) = 1;
- filtru.at<short>(1, 1) = 1;
- filtru.at<short>(1, 2) = 1;
- filtru.at<short>(2, 0) = 1;
- filtru.at<short>(2, 1) = 1;
- filtru.at<short>(2, 2) = 1;
- return filtru;
- }
- void apelFiltruMedie() {
- char fname[MAX_PATH];
- while (openFileDlg(fname)) {
- Mat source;
- source = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- Mat dest = filtru1(source, filtruMedie());
- imshow("image", source);
- imshow("dst", dest);
- waitKey();
- }
- }
- Mat filtruGaussian()
- {
- Mat filtru = Mat(3, 3, CV_16SC1);
- filtru.at<short>(0, 0) = 1;
- filtru.at<short>(0, 1) = 2;
- filtru.at<short>(0, 2) = 1;
- filtru.at<short>(1, 0) = 2;
- filtru.at<short>(1, 1) = 4;
- filtru.at<short>(1, 2) = 2;
- filtru.at<short>(2, 0) = 1;
- filtru.at<short>(2, 1) = 2;
- filtru.at<short>(2, 2) = 1;
- return filtru;
- }
- void apelFiltruGauss() {
- char fname[MAX_PATH];
- while (openFileDlg(fname)) {
- Mat source;
- source = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- Mat dest = filtru1(source, filtruGaussian());
- imshow("image", source);
- imshow("dst", dest);
- waitKey();
- }
- }
- Mat filtru2(Mat src, Mat filtru)
- {
- Mat dst = Mat(src.rows, src.cols, CV_32SC1);
- Mat dst2 = Mat(src.rows, src.cols, CV_8UC1);
- int i, j, i2 = 0, j2 = 0;
- int pixel = 0;
- int sum = 0;
- int min = 32000, max = 0;
- for (i = 1; i < src.rows - 1; i++)
- for (j = 1; j < src.cols - 1; j++)
- {
- pixel = 0;
- for (i2 = 0; i2 < filtru.rows; i2++)
- for (j2 = 0; j2 < filtru.cols; j2++)
- pixel = pixel + (filtru.at<short>(i2, j2) * src.at<uchar>(i + i2 - 1, j + j2 - 1));
- if (pixel >= 255) {
- pixel = 255;
- }
- //modul de imagine
- if (pixel <= 0)
- {
- pixel = 0;
- }
- dst.at<int>(i, j) = pixel;
- }
- for (i = 1; i < src.rows - 1; i++)
- for (j = 1; j < src.cols - 1; j++) {
- if (min > dst.at<int>(i, j)) { min = dst.at<int>(i, j); }
- if (max < dst.at<int>(i, j)) { max = dst.at<int>(i, j); }
- }
- for (i = 1; i < src.rows - 1; i++) {
- for (j = 1; j < src.cols - 1; j++) {
- dst2.at<uchar>(i, j) = ((dst.at<int>(i, j) - min) * 255) / (max - min);
- }
- }
- return dst2;
- }
- Mat filtruLaplace()
- {
- Mat filtru = Mat(3, 3, CV_16SC1);
- filtru.at<short>(0, 0) = -1;
- filtru.at<short>(0, 1) = -1;
- filtru.at<short>(0, 2) = -1;
- filtru.at<short>(1, 0) = -1;
- filtru.at<short>(1, 1) = 8;
- filtru.at<short>(1, 2) = -1;
- filtru.at<short>(2, 0) = -1;
- filtru.at<short>(2, 1) = -1;
- filtru.at<short>(2, 2) = -1;
- return filtru;
- }
- void apelLaPlace()
- {
- char fname[MAX_PATH];
- while (openFileDlg(fname)) {
- Mat source;
- source = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- Mat dest = filtru2(source, filtruLaplace());
- imshow("image", source);
- imshow("dst", dest);
- waitKey();
- }
- }
- Mat filtruHigh()
- {
- Mat filtru = Mat(3, 3, CV_16SC1);
- filtru.at<short>(0, 0) = -1;
- filtru.at<short>(0, 1) = -1;
- filtru.at<short>(0, 2) = -1;
- filtru.at<short>(1, 0) = -1;
- filtru.at<short>(1, 1) = 9;
- filtru.at<short>(1, 2) = -1;
- filtru.at<short>(2, 0) = -1;
- filtru.at<short>(2, 1) = -1;
- filtru.at<short>(2, 2) = -1;
- return filtru;
- }
- void apelHigh()
- {
- char fname[MAX_PATH];
- while (openFileDlg(fname)) {
- Mat source;
- source = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- Mat dest = filtru2(source, filtruHigh());
- imshow("image", source);
- imshow("dst", dest);
- waitKey();
- }
- }
- /////////////////////////////// LAB 10 /////////////////////
- void filtruMedian(Mat src, int w) {
- double t = (double)getTickCount();
- Mat dst = src.clone();
- int k = w / 2;
- int index;
- std::vector <uchar> V = {};
- imshow("Original", src);
- for (int y = k; y < src.rows - k; y++) {
- for (int x = k; x < src.cols - k; x++) {
- int index = 0;
- for (int i = -k; i <= k; i++) {
- for (int j = -k; j <= k; j++) {
- V.push_back(src.at<uchar>(y + i, x + j));
- index++;
- }
- }
- std::sort(V.begin(), V.end());
- uchar mean = V[w*w / 2];
- dst.at<uchar>(y, x) = mean;
- V.clear();
- }
- }
- imshow("Rez", dst);
- t = ((double)getTickCount() - t) / getTickFrequency();
- // Display (in the console window) the processing time in [ms]
- printf("Time = %.3f [ms]\n", t * 1000);
- }
- void apelareMedian()
- {
- char fname[MAX_PATH];
- while (openFileDlg(fname)) {
- Mat src;
- src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- filtruMedian(src, 3);
- waitKey();
- }
- }
- Mat filtruGaussian(Mat src, int w) {
- double t = (double)getTickCount(); // Get the current time [ms]
- Mat dst = src.clone();
- float G[7][7] = { 0 };
- float sigma = (float)w / 6;
- int k = w / 2;
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < w; y++) {
- 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)));
- }
- }
- for (int x = k; x < src.rows - k; x++)
- for (int y = k; y < src.cols - k; y++)
- {
- int aux = 0;
- for (int i = -k; i <= k; i++)
- for (int j = -k; j <= k; j++)
- {
- aux += src.at<uchar>(x + j, y + i)*G[j + k][i + k];
- }
- dst.at<uchar>(x, y) = aux;
- }
- imshow("Original", src);
- imshow("Rezultat", dst);
- //Mat dest = filtru1(dst, filtruGaussian());
- //imshow("Dupa convolutie", dest);
- t = ((double)getTickCount() - t) / getTickFrequency();
- // Display (in the console window) the processing time in [ms]
- printf("Time = %.3f [ms]\n", t * 1000);
- return dst;
- }
- void apelareGaussian()
- {
- Mat src;
- src = imread("Images/imagini_zgomot/portrait_Gauss1.bmp", 0);
- Mat dst=filtruGaussian(src, 7);
- waitKey();
- }
- void filtruGaussian2(Mat img ,int w) {
- double t = (double)getTickCount(); // Get the current time [ms]
- float sigma = (float)(w / 6.0);
- Mat clone = img.clone();
- int k = w/ 2;
- uchar V[50] = { 0 };
- float Gx[7] = { 0 };
- float Gy[7]= { 0 };
- for (int x = 0; x < w; x++)
- for (int y = 0; y < w; y++) {
- if (y == w / 2) Gy[x] = 1.0 / (2 * PI*sigma)*exp(-(((y - w/2)*(y - w/2)) / (2 * sigma*sigma)));
- if (x == w / 2) Gx[y] = 1.0 / (2 * PI*sigma)*exp(-(((x - w/2)*(x - w/2)) / (2 * sigma*sigma)));
- }
- for (int x = k; x < img.rows - k; x++)
- for (int y = k; y < img.cols - k; y++)
- {
- float aux = 0;
- for (int i = -k; i <= k; i++)
- for (int j = -k; j <= k; j++)
- {
- aux += Gx[j + k] * Gy[i + k] * img.at<uchar>(x + j, y + i);
- }
- clone.at<uchar>(x, y) = aux;
- }
- imshow("original", img);
- imshow("rezultat", clone);
- t = ((double)getTickCount() - t) / getTickFrequency();
- // Display (in the console window) the processing time in [ms]
- printf("Time = %.3f [ms]\n", t * 1000);
- waitKey(0);
- }
- void apelareGaussian2()
- {
- Mat src;
- src = imread("Images/imagini_zgomot/portrait_Gauss1.bmp", 0);
- //filtruGaussian(src,7);
- filtruGaussian2(src, 7);
- waitKey();
- }
- /////////////////////////// LAB 11 /////////////////////////
- void prewitt(Mat src)
- {
- int Hx[3][3] = { { -1, 0, 1 },
- { -1, 0, 1 },
- { -1, 0, 1 } };
- int Hy[3][3] = { { 1, 1, 1 },
- { 0, 0, 0 },
- { -1, -1, -1 } };
- Mat dstx = src.clone();
- Mat dsty = src.clone();
- int k = 1;
- int pixelx, pixely;
- for (int y = 1; y < src.rows - 1; y++)
- {
- for (int x = 1; x < src.cols -1; x++)
- {
- int aux1 = 0, aux2 = 0;
- for (int i = -1; i <= 1; i++)
- {
- for (int j = -1; j <= 1; j++)
- {
- aux1 += src.at<uchar>(x + j, y + i) * Hx[j + 1][i + 1];
- aux2 += src.at<uchar>(x + j, y + i) * Hy[j + 1][i + 1];
- }
- }
- if (aux1 < 0)
- dstx.at<uchar>(x, y) = 0;
- else if (aux1 > 255)
- dstx.at<uchar>(x, y) = 255;
- else
- dstx.at<uchar>(x, y) = aux1;
- if (aux2 < 0)
- dsty.at<uchar>(x, y) = 0;
- else if (aux2 > 255)
- dsty.at<uchar>(x, y) = 255;
- else
- dsty.at<uchar>(x, y) = aux2;
- }
- }
- imshow("Original", src);
- imshow("X component", dstx);
- imshow("Y component", dsty);
- waitKey(0);
- }
- void apelarePrewitt()
- {
- Mat src;
- src = imread("Images/imagini_muchii/cameraman.bmp", 0);
- prewitt(src);
- waitKey();
- }
- void sobel(Mat src)
- {
- int Hx[3][3] = { { -1, 0, 1 },
- { -2, 0, 2 },
- { -1, 0, 1 } };
- int Hy[3][3] = { { 1, 2, 1 },
- { 0, 0, 0 },
- { -1, -2, -1 } };
- Mat dstx = src.clone();
- Mat dsty = src.clone();
- int k = 1;
- int pixelx, pixely;
- for (int y = k; y < src.rows - k; y++)
- {
- for (int x = k; x < src.cols - k; x++)
- {
- int aux1 = 0, aux2 = 0;
- for (int i = -k; i <= k; i++)
- {
- for (int j = -k; j <= k; j++)
- {
- aux1 += src.at<uchar>(x + j, y + i) * Hx[j + k][i + k];
- aux2 += src.at<uchar>(x + j, y + i) * Hy[j + k][i + k];
- }
- }
- if (aux1 < 0)
- dstx.at<uchar>(x, y) = 0;
- else if (aux1 > 255)
- dstx.at<uchar>(x, y) = 255;
- else
- dstx.at<uchar>(x, y) = aux1;
- if (aux2 < 0)
- dsty.at<uchar>(x, y) = 0;
- else if (aux2 > 255)
- dsty.at<uchar>(x, y) = 255;
- else
- dsty.at<uchar>(x, y) = aux2;
- }
- }
- imshow("Original", src);
- imshow("X component", dstx);
- imshow("Y component", dsty);
- waitKey(0);
- }
- void apelareSobel()
- {
- Mat src;
- src = imread("Images/imagini_muchii/cameraman.bmp", 0);
- sobel(src);
- waitKey();
- }
- void Roberts(Mat src)
- {
- int Hx[2][2] = { { 1, 0 },
- { 0, -1 } };
- int Hy[2][2] = { { 0, -1 },
- { 1, 0 } };
- Mat dest_x = src.clone();
- Mat dest_y = src.clone();
- int k = 1;
- for (int y = k; y < src.rows - k; y++)
- {
- for (int x = k; x < src.cols - k; x++)
- {
- int aux1 = 0, aux2 = 0;
- for (int i = -k; i < k; i++)
- {
- for (int j = -k; j < k; j++)
- {
- aux1 += src.at<uchar>(x + j, y + i) * Hx[j + k][i + k];
- aux2 += src.at<uchar>(x + j, y + i) * Hy[j + k][i + k];
- }
- if (aux1 < 0)
- dest_x.at<uchar>(x, y) = 0;
- else if (aux1 > 255)
- dest_x.at<uchar>(x, y) = 255;
- else
- dest_x.at<uchar>(x, y) = aux1;
- if (aux2 < 0)
- dest_y.at<uchar>(x, y) = 0;
- else if (aux2 > 255)
- dest_y.at<uchar>(x, y) = 255;
- else
- dest_y.at<uchar>(x, y) = aux2;
- }
- }
- }
- imshow("Original", src);
- imshow("X component", dest_x);
- imshow("Y component", dest_y);
- waitKey(0);
- }
- void canny(Mat src)
- {
- Mat temp = src.clone(); //matrice temporara
- Mat modul = Mat::zeros(src.size(), CV_8UC1); //matricea pt. modulul gradientului
- Mat directie = Mat::zeros(src.size(), CV_8UC1); //matricea pt. directia gradientului
- int Sx[3][3] = { { -1, 0, 1 },{ -2, 0, 2 },{ -1, 0, 1 } };
- int Sy[3][3] = { { 1, 2, 1 },{ 0, 0, 0 },{ -1, -2, -1 } };
- int w;
- float teta;
- int dir;
- Mat canny_res;
- temp = filtruGaussian(src, 5);
- imshow("Gauss res", temp);
- //waitKey(0);
- for (int i = 2; i < temp.rows - 2; i++)
- {
- for (int j = 2; j < temp.cols - 2; j++)
- {
- float gradX = 0, gradY = 0;
- for (int l1 = 0; l1 < 3; l1++)
- {
- for (int l2 = 0; l2 < 3; l2++)
- {
- gradX += temp.at<uchar>(i + l1 - 1, j + l2 - 1) * Sx[l1][l2];
- gradY += temp.at<uchar>(i + l1 - 1, j + l2 - 1) * Sy[l1][l2];
- }
- }
- ;
- modul.at<uchar>(i, j) = sqrt(gradX * gradX + gradY * gradY) / 5.65;
- teta = atan2((float)gradY, (float)gradX);
- if ((teta > 3 * PI / 8 && teta < 5 * PI / 8) || (teta > -5 * PI / 8 && teta < -3 * PI / 8))
- {
- dir = 0;
- }
- if ((teta > PI / 8 && teta < 3 * PI / 8) || (teta > -7 * PI / 8 && teta < -5 * PI / 8))
- {
- dir = 1;
- }
- if ((teta > -PI / 8 && teta < PI / 8) || teta > 7 * PI / 8 && teta < -7 * PI / 8)
- {
- dir = 2;
- }
- if ((teta > 5 * PI / 8 && teta < 7 * PI / 8) || (teta > -3 * PI / 8 && teta < -PI / 8))
- {
- dir = 3;
- }
- directie.at<uchar>(i, j) = dir;
- }
- }
- // sobel
- Mat tempSobelX = temp.clone();
- for (int i = 1; i < temp.rows - 1; i++)
- {
- for (int j = 1; j < temp.cols - 1; j++)
- {
- tempSobelX.at<uchar>(i, j) = (
- -1 * src.at<uchar>(i - 1, j - 1) +
- 0 * src.at<uchar>(i - 1, j) +
- 1 * src.at<uchar>(i - 1, j + 1) +
- -2 * src.at<uchar>(i, j - 1) +
- 0 * src.at<uchar>(i, j) +
- 2 * src.at<uchar>(i, j + 1) +
- -1 * src.at<uchar>(i + 1, j - 1) +
- 0 * src.at<uchar>(i + 1, j) +
- 1 * src.at<uchar>(i + 1, j + 1)) / 16;
- }
- }
- //imshow("Res Sobel X", tempSobelX);
- Mat tempSobelY = temp.clone();
- for (int i = 1; i < temp.rows - 1; i++)
- {
- for (int j = 1; j < temp.cols - 1; j++)
- {
- tempSobelY.at<uchar>(i, j) = (
- 1 * src.at<uchar>(i - 1, j - 1) +
- 2 * src.at<uchar>(i - 1, j) +
- 1 * src.at<uchar>(i - 1, j + 1) +
- 0 * src.at<uchar>(i, j - 1) +
- 0 * src.at<uchar>(i, j) +
- 0 * src.at<uchar>(i, j + 1) +
- -1 * src.at<uchar>(i + 1, j - 1) +
- -2 * src.at<uchar>(i + 1, j) +
- -1 * src.at<uchar>(i + 1, j + 1)) / 16;
- }
- }
- //
- //imshow("Res Sobel Y", tempSobelY);
- imshow("Modul res", modul);
- Mat nms = modul.clone();
- for (int i = 1; i < src.rows - 1; ++i)
- {
- for (int j = 1; j < src.cols - 1; ++j)
- {
- int dir = directie.at<uchar>(i, j);
- switch (dir)
- {
- case 0:
- {
- if (i == 0)
- {
- if (modul.at<uchar>(i, j) < modul.at<uchar>(i + 1, j))
- {
- nms.at<uchar>(i, j) = 0;
- }
- }
- else if (i == src.rows - 1)
- {
- if (modul.at<uchar>(i, j) < modul.at<uchar>(i - 1, j))
- {
- nms.at<uchar>(i, j) = 0;
- }
- }
- else
- {
- if (modul.at<uchar>(i, j) < modul.at<uchar>(i - 1, j) ||
- modul.at<uchar>(i, j) < modul.at<uchar>(i + 1, j)
- )
- {
- nms.at<uchar>(i, j) = 0;
- }
- }
- break;
- }
- case 1:
- {
- if (modul.at<uchar>(i, j) < modul.at<uchar>(i - 1, j + 1) ||
- modul.at<uchar>(i, j) < modul.at<uchar>(i + 1, j - 1)
- )
- {
- nms.at<uchar>(i, j) = 0;
- }
- break;
- }
- case 2:
- {
- if (j == 0)
- {
- if (modul.at<uchar>(i, j) < modul.at<uchar>(i, j + 1))
- {
- nms.at<uchar>(i, j) = 0;
- }
- }
- else if (j == src.cols - 1)
- {
- if (modul.at<uchar>(i, j) < modul.at<uchar>(i, j - 1))
- {
- nms.at<uchar>(i, j) = 0;
- }
- }
- else
- {
- if (modul.at<uchar>(i, j) < modul.at<uchar>(i, j - 1) ||
- modul.at<uchar>(i, j) < modul.at<uchar>(i, j + 1)
- )
- {
- nms.at<uchar>(i, j) = 0;
- }
- }
- break;
- }
- default:
- {
- if (modul.at<uchar>(i, j) < modul.at<uchar>(i - 1, j - 1) ||
- modul.at<uchar>(i, j) < modul.at<uchar>(i + 1, j + 1)
- )
- {
- nms.at<uchar>(i, j) = 0;
- }
- break;
- }
- }
- }
- }
- imshow("Non-max suppression", nms);
- //compute histogram
- int hist[256];
- for (int i = 0; i < 255; ++i)
- {
- hist[i] = 0;
- }
- for (int i = 0; i < src.rows; ++i)
- {
- for (int j = 0; j < src.cols; ++j)
- {
- hist[nms.data[i * src.cols + j]]++;
- }
- }
- float k = 0.4;
- float nrnonmuchie = 0.9 * (nms.rows * nms.cols - hist[0]);
- int pragadaptiv;
- int sum = 0;
- for (int i = 1; i < 255; i++)
- {
- sum += hist[i];
- if (sum > nrnonmuchie)
- {
- pragadaptiv =hist[i];
- break;
- }
- }
- int x;
- printf("prag adaptiv + %d", pragadaptiv);
- scanf("%d",&x);
- float pH = pragadaptiv;
- float pL = 0.4 * pH;
- /* double threshold */
- Mat thr = nms.clone();
- for (int i = 0; i < src.rows; ++i)
- {
- for (int j = 0; j < src.cols; ++j)
- {
- if (nms.data[i * src.cols + j] < pL)
- {
- thr.data[i * src.cols + j] = 0;
- }
- else if (nms.data[i * src.cols + j] > pH)
- {
- thr.data[i * src.cols + j] = STRONG;
- }
- else if (nms.data[i * src.cols + j] < pH && nms.data[i * src.cols + j] > pL)
- {
- thr.data[i * src.cols + j] = WEAK;
- }
- }
- }
- imshow("thr", thr);
- waitKey(0);
- }
- void cannyTest()
- {
- Mat src;
- src = imread("Images/saturn.bmp", 0);
- canny(src);
- waitKey(0);
- }
- int main()
- {
- int op;
- Mat src,src1,src2,src3;
- do
- {
- system("cls");
- destroyAllWindows();
- printf("Menu:\n");
- printf(" 1 - Open image\n");
- printf(" 2 - Open BMP images from folder\n");
- printf(" 3 - Image negative - diblook style\n");
- printf(" 4 - BGR->HSV\n");
- printf(" 5 - Resize image\n");
- printf(" 6 - Canny edge detection\n");
- printf(" 7 - L1 Negative Image \n");
- printf(" 8 - Snap frame from live video\n");
- printf(" 9 - Mouse callback demo\n");
- printf(" 10 - Imagine cu factor aditiv\n");
- printf(" 11 - Imagine cu factor multiplicativ\n");
- printf(" 12 - Imagine 4 sectoare\n");
- printf(" 13 - Inversa matricii\n");
- printf(" 14 - Copiaza Canale\n");
- printf(" 15 - Imagine GrayScale\n");
- printf(" 16 - Imagine Alb-Negru\n");
- printf(" 17 - Imagine HSV\n");
- printf(" 18 - In imagine\n");
- printf(" 19 - Proprietati geometrice\n");
- printf(" 20 - Algoritm 1 – Traversarea în lăţime\n");
- printf(" 21 - Draw Border\n");
- printf(" 22 - Reconstruct\n");
- printf(" 23 - Dilatare\n");
- printf(" 24 - Eroziune\n");
- printf(" 25 - Inchidere\n");
- printf(" 26 - Inchidere de N ori\n");
- printf(" 27 - Deschidere\n");
- printf(" 28 - Deschidere de N ori\n");
- printf(" 29 - Dilatare de N ori\n");
- printf(" 30 - Eroziune de N ori\n");
- printf(" 31 - Contur\n");
- printf(" 32 - Umplere Regiuni\n");
- printf(" 33 - Histograma\n");
- printf(" 34 - PDFHistograma\n");
- printf(" 35 - Binarizare\n");
- printf(" 36 - Calcule Histograma\n");
- printf(" 37 - Egalizare\n");
- printf(" 38 - Filtru Medie\n");
- printf(" 39 - Filtru Gaussian\n");
- printf(" 40 - Filtru LaPlace\n");
- printf(" 41 - Filtru High\n");
- printf(" 42 - Filtru Median\n");
- printf(" 43 - Filtru Gaussian\n");
- printf(" 44 - Filtru Gaussian 2\n");
- printf(" 45 - Prewitt\n");
- printf(" 46 - Sobel\n");
- printf(" 47 - Canny\n");
- printf(" 0 - Exit\n\n");
- printf("Option: ");
- scanf("%d",&op);
- switch (op)
- {
- case 1:
- testOpenImage();
- break;
- case 2:
- testOpenImagesFld();
- break;
- case 3:
- testParcurgereSimplaDiblookStyle(); //diblook style
- break;
- case 4:
- //testColor2Gray();
- testBGR2HSV();
- break;
- case 5:
- testResize();
- break;
- case 6:
- testCanny();
- break;
- case 7:
- negative_image();
- break;
- case 8:
- testSnap();
- break;
- case 9:
- testMouseClick();
- break;
- case 10:
- changeGray(100);
- break;
- case 11:
- changeGrayMulti(2);
- break;
- case 12:
- patruSectoare();
- break;
- case 13:
- inv();
- break;
- case 14:
- copiazaCanale();
- break;
- case 15:
- colorToGray();
- break;
- case 16:
- grayToALb();
- break;
- case 17:
- convertHSV();
- break;
- case 18:
- src = imread("Images/Lena_24bits.bmp", CV_LOAD_IMAGE_COLOR);
- isInside(src, 10, 10);
- break;
- case 19:
- testMouseClickProprietati();
- break;
- case 20:
- traversare();
- break;
- case 21:
- border();
- break;
- case 22:
- reconstruct();
- break;
- case 23:
- src = imread("Images/1_Dilate/mon1thr1_bw.bmp", 0);
- dilatare(src);
- break;
- case 24:
- src1 = imread("Images/2_Erode/mon1thr1_bw.bmp", 0);
- eroziune(src1);
- break;
- case 25:
- src2 = imread("Images/4_Close/phn1thr1_bw.bmp", 0);
- inchidere(src2);
- break;
- case 26:
- inchidereapelNori(2);
- break;
- case 27:
- src3 = imread("Images/3_Open/cel4thr3_bw.bmp", 0);
- deschidere(src3);
- break;
- case 28:
- deschhidereapelNori(2);
- break;
- case 29:
- dilatare_apelNori(10);
- break;
- case 30:
- eroziune_apelNori(10);
- break;
- case 31:
- contur();
- break;
- case 32:
- umplere_regiuni(80, 80);
- break;
- case 33:
- testHistograma();
- break;
- case 34:
- testHistogramaFDP();
- break;
- case 35:
- testPragBinarizare(); break;
- case 36:
- testCalculeHistograma(100,2.5,100,250); break;
- case 37:
- testEgalizareHisto();
- break;
- case 38:
- apelFiltruMedie();
- break;
- case 39:
- apelFiltruGauss();
- break;
- case 40:
- apelLaPlace();
- break;
- case 41:
- apelHigh();
- break;
- case 42:
- apelareMedian();
- break;
- case 43:
- apelareGaussian();
- break;
- case 44:
- apelareGaussian2();
- break;
- case 45:
- apelarePrewitt();
- break;
- case 46:
- apelareSobel();
- break;
- case 47:
- cannyTest();
- break;
- }
- }
- while (op!=0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement