Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // OpenCVApplication.cpp : Defines the entry point for the console application.
- // Laborator PI, Nagy Imola, gr 30234
- #include "stdafx.h"
- #include "common.h"
- #include <queue>
- #include <random>
- #include <vector>
- 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 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 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);
- imshow("source", frame);
- imshow("gray", grayFrame);
- 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 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);
- }
- /*Laborator 1*/
- void negative_image(){
- char fname[MAX_PATH];
- while (openFileDlg(fname)) {
- Mat img = imread(fname, 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);
- }
- }
- void gray_level_add_factor() {
- int factor = 35;
- 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 = Mat(height, width, CV_8UC1);
- for (int i = 0; i < height; i++)
- for (int j = 0; j < width; j++)
- {
- int temp = src.at<uchar>(i, j) + factor;
- if (temp > 255)
- {
- dst.at<uchar>(i, j) = 255;
- }
- else
- {
- if (temp < 0)
- {
- dst.at<uchar>(i, j) = 0;
- }
- else
- {
- dst.at<uchar>(i, j) = temp;
- }
- }
- }
- imshow("input image", src);
- imshow("output image", dst);
- imwrite("Images/negative_image.bmp", dst);
- waitKey();
- }
- }
- void gray_level_mul_factor() {
- float factor = 3.5;
- 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 = Mat(height, width, CV_8UC1);
- for (int i = 0; i < height; i++)
- for (int j = 0; j < width; j++)
- {
- float temp = src.at<uchar>(i, j) * factor;
- if (temp > 255)
- {
- dst.at<uchar>(i, j) = 255;
- }
- else
- {
- if (temp < 0)
- {
- dst.at<uchar>(i, j) = 0;
- }
- else
- {
- dst.at<uchar>(i, j) = temp;
- }
- }
- }
- imshow("input image", src);
- imshow("output image", dst);
- imwrite("Images/negative.bmp", dst);
- waitKey();
- }
- }
- void createColorImage() {
- int len = 256;
- Mat img(len, len, CV_8UC3);
- // up left
- for (int i = 0; i < len/2; i++){
- for (int j = 0; j < len/2; j++)
- {
- Vec3b pixel = img.at< Vec3b>(i, j);
- pixel[0] = 255;
- pixel[1] = 255;
- pixel[2] = 255;
- img.at<Vec3b>(i, j) = pixel;
- }
- }
- // up right
- for (int i = 0; i < len/2; i++)
- for (int j = len/2; j < len; j++)
- {
- Vec3b pixel = img.at< Vec3b>(i, j);
- pixel[0] = 0;
- pixel[1] = 0;
- pixel[2] = 255;
- img.at<Vec3b>(i, j) = pixel;
- }
- // down left
- for (int i = len/2; i < len; i++)
- for (int j = 0; j < 128; j++)
- {
- Vec3b pixel = img.at< Vec3b>(i, j);
- pixel[0] = 0;
- pixel[1] = 255;
- pixel[2] = 0;
- img.at<Vec3b>(i, j) = pixel;
- }
- // down right
- for (int i = len/2; i < len; i++)
- for (int j = len/2; j < len; j++)
- {
- Vec3b pixel = img.at< Vec3b>(i, j);
- pixel[0] = 0;
- pixel[1] = 255;
- pixel[2] = 255;
- img.at<Vec3b>(i, j) = pixel;
- }
- imshow("input image", img);
- waitKey();
- }
- void inverseMatrix()
- {
- double vals[9] = { 1.3, 2.5 , 1, 0, 5.4, -2.4, 4.5, 2, 1 };
- //float vals[9] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- Mat M(3, 3, CV_32FC1, vals);
- std::cout << M << std::endl;
- Mat inverse;
- invert(M, inverse);
- std::cout << inverse << std::endl;
- Mat prod = M*inverse;
- std::cout << prod << std::endl;
- fflush(stdin);
- getchar();
- }
- //lab2
- void separateRGB() {
- Mat img = imread("Images/flowers_24bits.bmp", CV_LOAD_IMAGE_UNCHANGED);
- Mat red(img.rows, img.cols, CV_8UC3);
- Mat green(img.rows, img.cols, CV_8UC3);
- Mat blue(img.rows, img.cols, CV_8UC3);
- Vec3b color; //color of the original pixel at index (i,j)
- for (int i = 0; i < img.rows; i++) {
- for (int j = 0; j < img.cols; j++) {
- color = img.at<Vec3b>(i, j);
- red.at<uchar>(i, j) = color[2];
- green.at<uchar>(i, j) = color[1];
- blue.at<uchar>(i, j) = color[0];
- }
- }
- imshow("red", red);
- imshow("green", green);
- imshow("blue", blue);
- waitKey(0);
- }
- void rgbToGrayscale() {
- Mat img = imread("Images/flowers_24bits.bmp", CV_LOAD_IMAGE_UNCHANGED);
- Mat grayImg(img.rows, img.cols, CV_8UC1);
- Vec3b color; //color of the original pixel at index (i,j)
- for (int i = 0; i < img.rows; i++) {
- for (int j = 0; j < img.cols; j++) {
- color = img.at<Vec3b>(i, j);
- grayImg.at<uchar>(i, j) = (color[0] + color[1] + color[2]) / 3;
- }
- }
- imshow("Grayscale image", grayImg);
- waitKey(0);
- }
- void grayscaleToBinary() {
- Mat img = imread("Images/bacteria.bmp", CV_LOAD_IMAGE_UNCHANGED);
- Mat binary(img.rows, img.cols, CV_8UC1);
- int treshold;
- printf("Enter the treshold:");
- scanf("%d", &treshold);
- imshow("Original image", img);
- for (int i = 0; i < img.rows; i++) {
- for (int j = 0; j < img.cols; j++) {
- if (img.at<uchar>(i, j) < treshold) {
- binary.at<uchar>(i, j) = 0;
- }
- else
- {
- binary.at<uchar>(i, j) = 255;
- }
- }
- }
- imshow("Binary image", binary);
- waitKey(0);
- }
- Mat binerise(Mat img, float threshold) {
- Mat binary(img.rows, img.cols, CV_8UC1);
- for (int i = 0; i < img.rows; i++) {
- for (int j = 0; j < img.cols; j++) {
- if (img.at<uchar>(i, j) < threshold) {
- binary.at<uchar>(i, j) = 0;
- }
- else
- {
- binary.at<uchar>(i, j) = 255;
- }
- }
- }
- return binary;
- }
- void rgbToHSV() {
- Mat img = imread("Images/flowers_24bits.bmp", CV_LOAD_IMAGE_UNCHANGED);
- Mat H(img.rows, img.cols, CV_8UC1);
- Mat S(img.rows, img.cols, CV_8UC1);
- Mat V(img.rows, img.cols, CV_8UC1);
- Vec3b color;
- float r, g, b; // normalized components
- float M, m; //max and min
- float C;
- float h1, s1, v1;
- imshow("original", img);
- for (int i = 0; i < img.rows; i++){
- for (int j = 0; j < img.cols; j++){
- color = img.at<Vec3b>(i, j);
- //ordering is blue , green, red
- b = ((float) color[0]) / 255;
- g = ((float) color[1]) / 255;
- r = ((float) color[2]) / 255;
- M = max(r, g, b);
- m = min(r, g, b);
- C = M - m;
- // Value
- v1 = M;
- // Saturation
- if (v1 != 0)
- s1 = C / v1;
- else // Grayscale
- s1 = 0;
- // Hue
- if (C != 0){
- if (M == r) h1 = 60 * ((g - b) / C);
- if (M == g) h1 = 120 + 60 * ((b - r) / C);
- if (M == b) h1 = 240 + 60 * ((r - g) / C);
- }
- else h1 = 0;
- if (h1 < 0){
- h1 = h1 + 360;
- }
- //normalize values
- h1 = h1 * 255 / 360;
- s1 = s1 * 255;
- v1 = v1 * 255;
- //fill matrices
- H.at<uchar>(i, j) = h1;
- S.at<uchar>(i, j) = s1;
- V.at<uchar>(i, j) = v1;
- }
- }
- imshow("H", H);
- imshow("S", S);
- imshow("V", V);
- waitKey(0);
- }
- bool isInside(int i, int j, Mat img) {
- if (i > 0 && i < img.rows && j > 0 && j < img.cols) {
- return true;
- }
- else {
- return false;
- }
- }
- void isInsideImage() {
- Mat img = imread("Images/kids.bmp", CV_LOAD_IMAGE_UNCHANGED);
- int i, j;
- printf("i = ");
- scanf("%d", &i);
- printf("\nj = ");
- scanf("%d", &j);
- if (isInside(i, j, img)) {
- printf("It is inside.\n");
- }
- else {
- printf("It is outside.\n");
- }
- imshow("Image", img);
- waitKey(0);
- }
- //lab3
- //function to check whether the clicked color is equal to another color of a pixel in the image
- bool equalColor(Vec3b col1, Vec3b col2) {
- if (col1[0] == col2[2] && col1[1] == col2[1] && col1[2] == col2[0])
- return true;
- return false;
- }
- //calculate area of clicked object
- int calculateArea(Vec3b color, Mat img) {
- int area = 0;
- Vec3b imgColor;
- for (int i = 0; i < img.rows; i++) {
- for (int j = 0; j < img.cols; j++) {
- imgColor = img.at<Vec3b>(i, j);
- if (equalColor(imgColor, color))
- area++;
- }
- }
- return area;
- }
- int* centruDeMasa(Vec3b color, Mat img) {
- int area = calculateArea(color, img);
- int r = 0, c = 0;
- Vec3b imgColor;
- for (int i = 0; i < img.rows; i++) {
- for (int j = 0; j < img.cols; j++) {
- imgColor = img.at<Vec3b>(i, j);
- if (equalColor(imgColor, color)) {
- r = r + i;
- c = c + j;
- }
- }
- }
- r = r / area;
- c = c / area;
- int centre[2] = { r, c };
- return centre;
- }
- double elongationAxis(Vec3b color, Mat img) {
- int numarator = 0;
- int numitor1 = 0;
- int numitor2 = 0;
- int numitor;
- //centre[0] = rows, centre[1] = cols
- int* centre = centruDeMasa(color, img);
- Vec3b imgColor;
- for (int i = 0; i < img.rows; i++) {
- for (int j = 0; j < img.cols; j++) {
- imgColor = img.at<Vec3b>(i, j);
- if (equalColor(imgColor, color)) {
- numarator = numarator + (i - centre[0])*(j - centre[1]);
- numitor1 = numitor1 + (j - centre[1])*(j - centre[1]);
- numitor2 = numitor2 + (i - centre[0])*(i - centre[0]);
- }
- }
- }
- numarator = numarator * 2;
- numitor = numitor1 - numitor2;
- double axis = atan2(numarator, numitor);
- Point p(centre[0], centre[1]);
- return axis;
- }
- int calculatePerimeter(Vec3b color, Mat img) {
- //white : RGB (255,255,255)
- int perimeter = 0;
- Vec3b imgColor;
- Vec3b white(255, 255, 255);
- for (int i = 0; i < img.rows; i++) {
- for (int j = 0; j < img.cols; j++) {
- imgColor = img.at<Vec3b>(i, j);
- if (equalColor(imgColor, color) && !equalColor(imgColor, white)) {
- if (equalColor(white, img.at<Vec3b>(i + 1, j)) ||
- equalColor(white, img.at<Vec3b>(i - 1, j)) ||
- equalColor(white, img.at<Vec3b>(i, j + 1)) ||
- equalColor(white, img.at<Vec3b>(i, j - 1))) {
- perimeter++;
- }
- else {
- }
- }
- }
- }
- if (perimeter == 0) {
- printf("Click on an object! You clicked the background!\n");
- }
- return perimeter;
- }
- double thinnessRatio(Vec3b color, Mat img) {
- int perimeter = calculatePerimeter(color, img);
- int area = calculateArea(color, img);
- double thin = 4 * PI * area / (perimeter*perimeter);
- return thin;
- }
- float aspectRatio(Vec3b color, Mat img) {
- int cmin = img.cols;
- int rmin = img.rows;
- int cmax = 0, rmax = 0;
- Vec3b imgColor;
- for (int i = 0; i < img.rows; i++) {
- for (int j = 0; j < img.cols; j++) {
- imgColor = img.at<Vec3b>(i, j);
- if (equalColor(imgColor, color)) {
- if (i < rmin) rmin = i;
- if (i > rmax) rmax = i;
- if (j < cmin) cmin = j;
- if (j > cmax) cmax = j;
- }
- }
- }
- printf("rmin = %d, rmax = %d, cmin = %d, cmax = %d\n", rmin, rmax, cmin, cmax);
- float ratio = (cmax - cmin + 1) / (rmax - rmin + 1);
- return ratio;
- }
- void projections(Vec3b color, int row, int col, Mat img) {
- int horizontal = 0;
- int vertical = 0;
- Vec3b imgColor;
- for (int i = 0; i < img.rows; i++) {
- imgColor = img.at<Vec3b>(i, col);
- if (equalColor(color, imgColor)) {
- vertical++;
- }
- }
- for (int j = 0; j < img.rows; j++) {
- imgColor = img.at<Vec3b>(row, j);
- if (equalColor(color, imgColor)) {
- horizontal++;
- }
- }
- printf("Sum of pixels on row %d = %d\nSum of pixels on column %d = %d\n", row, horizontal, col, vertical);
- }
- void drawObject(Mat img, Vec3b color) {
- Vec3b imgColor;
- for (int i = 0; i < img.rows; i++) {
- for (int j = 0; j < img.cols; j++) {
- imgColor = img.at<Vec3b>(i, j);
- if (equalColor(imgColor, color)) {
- img.at<Vec3b>(i, j) = imgColor;
- }
- else {
- img.at<Vec3b>(i, j) = Vec3b(255, 255, 255);
- }
- }
- }
- }
- void newFunction(Mat img) {
- int areaTH, phi;
- printf("Enter treshold for area:");
- scanf("%d", &areaTH);
- printf("Enter phi:");
- scanf("%d", &phi);
- Vec3b imgColor;
- for (int i = 0; i < img.rows; i++) {
- for (int j = 0; j < img.cols; j++) {
- imgColor = img.at<Vec3b>(i, j);
- if (!equalColor(imgColor, Vec3b(255, 255, 255))) {
- if (calculateArea(imgColor, img) < areaTH) {
- drawObject(img, imgColor);
- }
- }
- }
- }
- }
- void showProperties(Vec3b color, Mat img) {
- printf("Area of selected object = %d\n", calculateArea(color, img));
- int* centre = centruDeMasa(color, img);
- printf("Centrul de masa = (%d,%d)\n", centre[0], centre[1]);
- printf("Elongation axis = %lf\n", elongationAxis(color, img));
- printf("Perimeter = %d\n", calculatePerimeter(color, img));
- printf("Thinnes ratio = %lf\n", thinnessRatio(color, img));
- printf("Aspect ratio = %f\n", aspectRatio(color, img));
- printf("\n --- Select another object --- \n");
- waitKey(0);
- }
- void onMouse(int event, int x, int y, int flags, void* param)
- {
- Mat* src = (Mat*)param;
- Vec3b color;
- if (event == CV_EVENT_LBUTTONDOWN)
- {
- color[0] = (int)(*src).at<Vec3b>(y, x)[2],
- color[1] = (int)(*src).at<Vec3b>(y, x)[1],
- color[2] = (int)(*src).at<Vec3b>(y, x)[0];
- //printf("R= %d , G= %d, B= %d\n", color[0], color[1], color[2]);
- projections(color, x, y, *src);
- showProperties(color, *src);
- }
- }
- //lab4-1
- void calcProperties() {
- char fname[MAX_PATH];
- while (openFileDlg)
- {
- Mat img = imread(fname, CV_8UC3);
- namedWindow("Click on an object", 1);
- setMouseCallback("Click on an object", onMouse, &img);
- imshow("Click on an object", img);
- waitKey(0);
- }
- }
- // Lab 4
- int di[8] = { -1, 0, 1, 0, -1, 1, -1, 1 };
- int dj[8] = { 0, -1, 0, 1, -1, -1, 1, 1 };
- uchar neighbors[4];
- void bfs() {
- Mat img = imread("Images/PI-L5/letters.bmp", CV_LOAD_IMAGE_GRAYSCALE);
- Mat labels = Mat::zeros(img.rows, img.cols, CV_8UC1);
- std::queue<Point2i> Q;
- Point2i p;
- int label = 0;
- for (int i = 0; i < labels.rows; i++) {
- for (int j = 0; j < labels.cols; j++)
- {
- labels.at<uchar>(i, j) = 0;
- }
- }
- for (int i = 1; i < img.rows - 1; i++)
- {
- for (int j = 1; j < img.cols - 1; j++)
- {
- if ((img.at<uchar>(i, j) == 0) && (labels.at<uchar>(i, j) == 0)) {
- label++;
- labels.at<uchar>(i, j) = label;
- Q.push({ i,j });
- while (!Q.empty()) {
- p = Q.front();
- Q.pop();
- for (int k = 0; k < 8; k++) {
- int ni = p.x + di[k];
- int nj = p.y + dj[k];
- if (ni >= 0 && ni < img.rows && nj >= 0 && nj < img.cols && img.at<uchar>(ni, nj) == 0 && labels.at<uchar>(ni, nj) == 0) {
- labels.at<uchar>(ni, nj) = label;
- Q.push({ ni, nj });
- }
- }
- }
- }
- }
- }
- //generare paleta de culori
- 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); // fundalul va fi alb
- Mat dst = Mat::zeros(img.rows, img.cols, CV_8UC3); //matricea destinatie pt. afisare
- for (int i = 1; i < img.rows - 1; i++)
- for (int j = 1; j < img.cols - 1; j++)
- {
- Scalar color = colorLUT[labels.at<uchar>(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("original", img);
- imshow("colorized", dst);
- waitKey(0);
- }
- void generateColorImg() {
- Mat colors(255, 255, CV_8UC1);
- Mat img(255, 255, CV_8UC3);
- std::default_random_engine gen;
- std::uniform_int_distribution<int> d(0, 255);
- uchar r, g, b;
- int nrOfColors = 5;
- std::vector<Vec3b> rand_colors = std::vector<Vec3b>(nrOfColors);
- for (int i = 0; i < 5; i++) {
- r = d(gen);
- g = d(gen);
- b = d(gen);
- rand_colors.at(i) = Vec3b(r, g, b);
- }
- rand_colors.at(0) = Vec3b(255, 255, 255);
- int index;
- for (int i = 0; i < 255; i++) {
- for (int j = 0; j < 255; j++) {
- index = rand() % nrOfColors;
- img.at<Vec3b>(i, j) = rand_colors[index];
- }
- }
- imshow("img", img);
- waitKey(0);
- }
- // lab5
- typedef struct {
- int i, j;
- byte c;
- } my_point;
- void follow_border() {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src;
- src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- Mat dst = Mat(src.size(), CV_8UC1);
- std::vector<my_point> contur;
- bool found = false;
- int i0, j0;
- for (int i = 0; i < src.rows && !found; i++) {
- for (int j = 0; j < src.cols && !found; j++) {
- if (src.at<uchar>(i, j) == 0) {
- i0 = i;
- j0 = j;
- found = true;
- }
- }
- }
- int di[] = { 0, -1, -1, -1, 0, 1, 1, 1 };
- int dj[] = { 1, 1, 0, -1, -1, -1, 0, 1 };
- contur.push_back(my_point{ i0, j0, 7 });
- bool finished = false;
- int x = i0;
- int y = j0;
- int dir = 7;
- while (!finished) {
- if (dir % 2 == 0) {
- dir = (dir + 7) % 8;
- }
- else {
- dir = (dir + 6) % 8;
- }
- while (src.at<uchar>(x + di[dir], y + dj[dir]) != 0) {
- dir = dir + 1;
- if (dir == 8) {
- dir = 0;
- }
- }
- contur.push_back(my_point{ x + di[dir], y + dj[dir], (byte)dir });
- x += di[dir];
- y += dj[dir];
- int n = contur.size();
- if (n > 2 && contur.at(0).i == contur.at(n - 2).i && contur.at(0).j == contur.at(n - 2).j && contur.at(1).i == contur.at(n - 1).i && contur.at(1).j == contur.at(n - 1).j) {
- finished = true;
- }
- }
- for (int i = 0; i < contur.size(); i++) {
- dst.at<uchar>(contur.at(i).i, contur.at(i).j) = 0;
- int v = 7;
- if (i > 0) {
- v = contur.at(i).c - contur.at(i - 1).c;
- }
- if (v < 0)
- v += 8;
- printf("%i ( %i , %i ) %i , %i \n", i, contur.at(i).i, contur.at(i).j, contur.at(i).c, v);
- }
- imshow("original", src);
- imshow("contur", dst);
- waitKey();
- }
- }
- // lab6
- Mat dilatare_param(Mat src) {
- Mat dst = Mat(src.size(), CV_8UC1);
- dst = src.clone();
- int di[] = { 0, -1, -1, -1, 0, 1, 1, 1 };
- int dj[] = { 1, 1, 0, -1, -1, -1, 0, 1 };
- for (int i = 0; i < src.rows; i++)
- {
- for (int j = 0; j < src.cols; j++)
- {
- if (src.at<uchar>(i, j) == 0) { //daca e obiect
- for (int k = 0; k < 8; k++) {
- dst.at<uchar>(i + di[k], j + dj[k]) = 0;
- }
- }
- }
- }
- return dst;
- }
- void dilatare() {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src;
- src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- Mat dst = Mat(src.size(), CV_8UC1);
- dst = dilatare_param(src);
- imshow("original", src);
- imshow("dst", dst);
- waitKey();
- }
- }
- Mat eroziune_param(Mat src) {
- Mat dst = Mat(src.size(), CV_8UC1);
- dst = src.clone();
- int di[] = { 0, -1, -1, -1, 0, 1, 1, 1 };
- int dj[] = { 1, 1, 0, -1, -1, -1, 0, 1 };
- for (int i = 0; i < src.rows; i++)
- {
- for (int j = 0; j < src.cols; j++)
- {
- if (src.at<uchar>(i, j) == 0) { //daca e obiect
- bool ok = true;
- for (int k = 0; (k < 8) && ok; k++) {
- if (src.at<uchar>(i + di[k], j + dj[k]) == 255) {
- dst.at<uchar>(i, j) = 255;
- }
- }
- }
- }
- }
- return dst;
- }
- void eroziune() {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src;
- src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- Mat dst = Mat(src.size(), CV_8UC1);
- dst = eroziune_param(src);
- imshow("original", src);
- imshow("dst", dst);
- waitKey();
- }
- }
- void incidere() {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src;
- src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- Mat temp = Mat(src.size(), CV_8UC1);
- temp = dilatare_param(src);
- Mat dst = Mat(src.size(), CV_8UC1);
- dst = eroziune_param(temp);
- imshow("original", src);
- imshow("dst", dst);
- waitKey();
- }
- }
- void deschidere() {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src;
- src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- Mat temp = Mat(src.size(), CV_8UC1);
- temp = eroziune_param(src);
- Mat dst = Mat(src.size(), CV_8UC1);
- dst = dilatare_param(temp);
- imshow("original", src);
- imshow("dst", dst);
- waitKey();
- }
- }
- void contur() {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src;
- src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- Mat temp = Mat(src.size(), CV_8UC1);
- temp = eroziune_param(src);
- Mat dst = Mat(src.size(), CV_8UC1);
- 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;
- }
- else {
- dst.at<uchar>(i, j) = 255;
- }
- }
- }
- imshow("original", src);
- imshow("dst", dst);
- waitKey();
- }
- }
- void histogram() {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- int h[256];
- int M = src.rows * src.cols;
- float fdp[256];
- float medie = 0;
- float deviatie = 0;
- // initializare vectori
- for (int i = 0; i < 256; i++) {
- h[i] = 0;
- fdp[i] = 0;
- }
- //histograma
- for (int i = 0; i < src.rows; i++) {
- for (int j = 0; j < src.cols; j++)
- {
- h[src.at<uchar>(i, j)] ++;
- }
- }
- showHistogram("Histograma", h, src.cols, src.rows);
- //fdp si medie
- for (int i = 0; i < 256; i++) {
- fdp[i] = h[i] / (float)M;
- medie += fdp[i];
- }
- printf("Medie: %f\n", medie);
- //deviatie
- for (int i = 0; i < src.rows; i++)
- {
- for (int j = 0; j < src.cols; j++)
- {
- deviatie += ((src.at<uchar>(i, j) - medie) * (src.at<uchar>(i, j) - medie));
- }
- }
- deviatie /= M;
- deviatie = sqrt(deviatie);
- printf("Deviatie: %f\n",deviatie);
- imshow("original", src);
- waitKey();
- }
- }
- void automated_binarization() {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src;
- src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- int h[256];
- int imax = 0;
- int imin = 256;
- float eroare = 0.1;
- float tk = 0;
- float tk_1 = 0;
- // initializare vectori
- for (int i = 0; i < 256; i++) {
- h[i] = 0;
- }
- //histograma, Imin, Imax
- for (int i = 0; i < src.rows; i++) {
- for (int j = 0; j < src.cols; j++)
- {
- int intenstity = src.at<uchar>(i, j);
- h[intenstity] ++;
- if (intenstity < imin) {
- imin = intenstity;
- }
- else if (intenstity > imax){
- imax = intenstity;
- }
- }
- }
- //initializare t
- tk = (imin + imax) / 2;
- while (tk - tk_1) {
- // calculare cele doua medii
- float medie1 = 0;
- float medie2 = 0;
- int contor = 0;
- for (int i = 0; i <= tk; i++) {
- medie1 += i * h[i];
- contor += h[i];
- }
- medie1 /= contor;
- contor = 0;
- for (int i = tk + 1; i < 256; i++) {
- medie2 += i * h[i];
- contor += h[i];
- }
- medie2 /= contor;
- // calculare t
- tk = (medie1 + medie2) / 2;
- tk_1 = tk;
- }
- Mat dst = binerise(src, tk);
- imshow("original", src);
- imshow("binary", dst);
- waitKey();
- }
- }
- void negativ() {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- Mat dst = Mat(src.size(), CV_8UC1);
- for (int i = 0; i < src.rows; i++)
- {
- for (int j = 0; j < src.cols; j++)
- {
- dst.at<uchar>(i, j) = 255 - src.at<uchar>(i, j);
- }
- }
- imshow("original", src);
- imshow("dst", dst);
- waitKey();
- }
- }
- void contrast_modif() {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- Mat dst = Mat(src.size(), CV_8UC1);
- int imax = 0;
- int imin = 256;
- //histograma, Imin, Imax
- for (int i = 0; i < src.rows; i++) {
- for (int j = 0; j < src.cols; j++)
- {
- int intenstity = src.at<uchar>(i, j);
- if (intenstity < imin) {
- imin = intenstity;
- }
- else if (intenstity > imax) {
- imax = intenstity;
- }
- }
- }
- int nImax = 0;
- int nImin = 256;
- // read new intensity limits
- printf("Minimum intensity: %d, maximum intensity: %d\n", imin, imax);
- printf("New minimum intensity: \n");
- scanf("%d", &nImin);
- printf("New maximum intensity: \n");
- scanf("%d", &nImax);
- // modify image
- for (int i = 0; i < src.rows; i++) {
- for (int j = 0; j < src.cols; j++)
- {
- dst.at<uchar>(i, j) = nImin + (src.at<uchar>(i, j) - imin) * (nImax - nImin) / (imax - imin);
- }
- }
- imshow("original", src);
- imshow("dst", dst);
- waitKey();
- }
- }
- void gamma_correction() {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- Mat dst = Mat(src.size(), CV_8UC1);
- double gamma = 0.4;
- // modify image
- for (int i = 0; i < src.rows; i++) {
- for (int j = 0; j < src.cols; j++)
- {
- double corrected = 255 * pow((src.at<uchar>(i, j) / (double) 255), gamma);
- corrected = max(0, corrected);
- corrected = min(255, corrected);
- dst.at<uchar>(i, j) = (uchar)corrected;
- }
- }
- imshow("original", src);
- imshow("dst", dst);
- waitKey();
- }
- }
- void light_modif() {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- Mat dst = Mat(src.size(), CV_8UC1);
- int offset = 10;
- // modify image
- for (int i = 0; i < src.rows; i++) {
- for (int j = 0; j < src.cols; j++)
- {
- int corrected = src.at<uchar>(i, j) + offset;
- corrected = max(0, corrected);
- corrected = min(255, corrected);
- dst.at<uchar>(i, j) = (uchar) corrected;
- }
- }
- imshow("original", src);
- imshow("dst", dst);
- waitKey();
- }
- }
- void filtru_trece_jos() {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat img = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- Mat dst = Mat(img.size(), CV_8UC1);
- int H[3][3] =
- { { 1, 1, 1},
- { 1, 1, 1 },
- { 1, 1, 1} };
- int sum = 0;
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++)
- {
- sum += H[i][j];
- }
- }
- for (int i = 1; i < img.rows - 1; i++)
- {
- for (int j = 1; j < img.cols - 1; j++)
- {
- int pixel = 0;
- for (int k = 0; k < 3; k++)
- {
- for (int z = 0; z < 3; z++)
- {
- pixel += (H[k][z] * img.at<uchar>(i + k - 1, z + j - 1));
- }
- }
- if (sum != 0)
- {
- pixel /= sum;
- }
- if (pixel >= 255)
- {
- pixel = 255;
- }
- if (pixel <= 0)
- {
- pixel = 0;
- }
- dst.at<uchar>(i, j) = pixel;
- }
- }
- imshow("original", img);
- imshow("dst", dst);
- waitKey();
- }
- }
- void filtru_trece_sus() {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat img = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- Mat dst = Mat(img.size(), CV_8UC1);
- int H[3][3] =
- { { 0, -1, 0 },
- { -1, 4, -1 },
- { 0, -1, 0 } };
- int sum_poz = 0;
- int sum_neg = 0;
- int sum;
- for (int i = 0; i < 7; i++) {
- for (int j = 0; j < 7; j++)
- {
- if (H[i][j] < 0)
- {
- sum_neg += H[i][j] * (-1);
- }
- else
- {
- sum_poz += H[i][j];
- }
- }
- }
- sum = max(sum_poz, sum_neg);
- for (int i = 0; i < img.rows - 1; i++)
- {
- for (int j = 0; j < img.cols - 1; j++)
- {
- int pixel = 0;
- for (int k = 0; k < 3; k++)
- {
- for (int z = 0; z < 3; z++)
- {
- pixel += H[k][z] * img.at<uchar>(k + i - 1, z + j - 1);
- }
- }
- if (sum != 0)
- {
- pixel /= sum;
- }
- pixel += 128;
- if (pixel >= 255)
- {
- pixel = 255;
- }
- else if (pixel <= 0)
- {
- pixel = 0;
- }
- dst.at<uchar>(i, j) = pixel;
- }
- }
- imshow("original", img);
- imshow("dst", dst);
- waitKey();
- }
- }
- void interschimba(int &a, int &b) {
- int c = a;
- a = b;
- b = c;
- }
- void bubble_sort(int(&v)[9], int n) {
- bool isSorted = false;
- int i = 0;
- while (!isSorted && i < n - 1) {
- isSorted = true;
- for (int j = 1; j < n - i - 1; j++) {
- if (v[j] > v[j + 1]) {
- interschimba(v[j], v[j + 1]);
- isSorted = false;
- }
- }
- }
- }
- void saltPepperFilter()
- {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat img = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- Mat dst = Mat(img.size(), CV_8UC1);
- int filterSize = 8;
- int di[] = { 0, -1, -1, -1, 0, 1, 1, 1 };
- int dj[] = { 1, 1, 0, -1, -1, -1, 0, 1 };
- int filter[9];
- for (int i = 1; i < img.rows - 1; i++)
- {
- for (int j = 1; j < img.cols - 1; j++)
- {
- for (int k = 0; k < 8; k++) {
- filter[k] = img.at<uchar>(i + di[k], j + dj[k]);
- bubble_sort(filter, 8);
- dst.at<uchar>(i, j) = filter[4];
- }
- }
- }
- imshow("original", img);
- imshow("dst", dst);
- waitKey();
- }
- }
- Mat gaussian_filter(Mat src, int w) {
- Mat dst = Mat(src.size(), CV_8UC1);
- float sigma = 0;
- sigma = (float)w/6;
- float nucleu[20][20];
- float sumaNucleu = 0;
- float sigmaPi = sigma*sigma * 2 * CV_PI;
- for (int i = 0; i < w; i++) {
- for (int j = 0; j < w; j++) {
- int k = (i - w / 2)*(i - w / 2) + (j - w / 2)*(j - w / 2);
- nucleu[i][j] = (float)exp((-1)*k / (2 * sigma*sigma)) / sigmaPi;
- sumaNucleu += nucleu[i][j];
- }
- }
- printf("Suma elementelr din nucleu gaussian: %.2f\n", sumaNucleu);
- int value = 0;
- for (int i = w / 2; i < src.rows - w / 2; i++) {
- for (int j = w / 2; j < src.cols - w / 2; j++) {
- for (int ll = -w / 2; ll <= w / 2; ll++) {
- for (int lc = -w / 2; lc <= w / 2; lc++) {
- value += src.at<uchar>(i + ll, j + lc) * nucleu[ll + w / 2][lc + w / 2];
- }
- }
- dst.at<uchar>(i, j) = value / sumaNucleu;
- value = 0;
- }
- }
- imshow("dst", dst);
- return dst;
- }
- void canny() {
- char fname[MAX_PATH];
- while (openFileDlg(fname)) {
- Mat src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- Mat temp = gaussian_filter(src, 3);
- 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} };
- Mat modul = Mat(temp.size(), CV_8UC1);
- Mat directie = Mat(temp.size(), CV_8UC1);
- for (int i = 1; i < temp.rows - 1; i++) {
- for (int j = 1; j < temp.cols - 1; j++) {
- float gradientX = 0;
- float gradientY = 0;
- for (int k = 0; k < 3; k++) {
- for (int l = 0; l < 3; l++) {
- gradientX += sX[k][l] * temp.at<uchar>(i + k - 1, j + l - 1);
- gradientY += sY[k][l] * temp.at<uchar>(i + k - 1, j + l - 1);
- }
- }
- modul.at<uchar>(i, j) = sqrt(gradientX*gradientX + gradientY *gradientY) / 5.65;
- float teta = atan2((float)gradientY, (float)gradientX);
- int dir = 0;
- 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;
- }
- }
- imshow("modul1", modul);
- for (int i = 1; i < temp.rows - 1; i++) {
- for (int j = 1; j < temp.cols - 1; j++) {
- switch (directie.at<uchar>(i, j))
- {
- case 0:
- if (modul.at<uchar>(i, j) != max(modul.at<uchar>(i, j), max(modul.at<uchar>(i - 1, j), modul.at<uchar>(i + 1, j)))) {
- modul.at<uchar>(i, j) = 0;
- }
- break;
- case 1:
- if (modul.at<uchar>(i, j) != max(modul.at<uchar>(i, j), max(modul.at<uchar>(i - 1, j - 1), modul.at<uchar>(i + 1, j + 1)))) {
- modul.at<uchar>(i, j) = 0;
- }
- break;
- case 2:
- if (modul.at<uchar>(i, j) != max(modul.at<uchar>(i, j), max(modul.at<uchar>(i, j + 1), modul.at<uchar>(i - 1, j)))) {
- modul.at<uchar>(i, j) = 0;
- }
- break;
- case 3:
- if (modul.at<uchar>(i, j) != max(modul.at<uchar>(i, j), max(modul.at<uchar>(i + 1, j + 1), modul.at<uchar>(i - 1, j - 1)))) {
- modul.at<uchar>(i, j) = 0;
- }
- default: break;
- }
- }
- }
- imshow("modul", modul);
- // Generare paleta de culori pentru afisarea directiilor gradientului
- Scalar colorLUT[4] = { 0 };
- colorLUT[0] = Scalar(0, 0, 255); //red
- colorLUT[1] = Scalar(0, 255, 0); // green
- colorLUT[2] = Scalar(255, 0, 0); // blue
- colorLUT[3] = Scalar(0, 255, 255); // yellow
- //matricea pt. afisarea muchiilor in codul de culori al directiilor
- Mat_<Scalar> ImgDir = Mat::zeros(modul.size(), CV_8UC3);
- // Afisarea pixelilor de muchie in culoarea codului de directie
- for (int i = 1; i < modul.rows - 1; i++)
- for (int j = 1; j < modul.cols - 1; j++)
- if (modul.at<uchar>(i, j))
- ImgDir(i, j) = colorLUT[directie.at<uchar>(i, j)];
- imshow("Imagine directii", ImgDir);
- int modulHistogram[256];
- for (int i = 0; i < modul.rows; i++) {
- for (int j = 0; j < modul.cols; j++) {
- modulHistogram[modul.at<uchar>(i,j)] ++;
- }
- }
- float p = 0.05;
- int puncMucie = p * (modul.rows * modul.cols - modulHistogram[0]);
- int nonMuchie = (1 - p) * (modul.rows * modul.cols - modulHistogram[0]);
- int pragAdaptiv = 0;
- for (int i = 0; (i < 256) && (pragAdaptiv <= nonMuchie); i++) {
- pragAdaptiv += modulHistogram[i] * i;
- }
- imshow("src", src);
- //imshow("dst", dst);
- waitKey();
- }
- }
- int main()
- {
- int op;
- do
- {
- system("cls");
- destroyAllWindows();
- printf("Menu:\n");
- printf(" 1 - Open image\n");
- printf(" 2 - Open BMP images from folder\n");
- printf(" 3 - Resize image\n");
- printf(" 4 - Process video\n");
- printf(" 5 - Snap frame from live video\n");
- printf(" 6 - Mouse callback demo\n");
- printf(" 7 - L1 Negative Image \n");
- printf(" 8 - Gray level modification with addfactor \n");
- printf(" 9 - Gray level modification with mulfactor \n");
- printf(" 10 - Create color image \n");
- printf(" 11 - Create matrix and calculate reverse. \n");
- printf(" 12 - Separate R, G, B. \n");
- printf(" 13 - RGB to Grayscale. \n");
- printf(" 14 - Grayscale to binary\n");
- printf(" 15 - RGB to HSV\n");
- printf(" 16 - Is point inside the image.\n");
- printf(" 17 - Calculate properties\n");
- printf(" 18 - BFS\n");
- printf(" 19 - Generate color image\n");
- printf(" 20 - Follow border\n" );
- printf(" 21 - Dilatare\n");
- printf(" 22 - Eroziune\n");
- printf(" 23 - Inchidere\n");
- printf(" 24 - Deschidere\n");
- printf(" 25 - Contur\n");
- printf(" 26 - Average, standard deviation, histogram\n");
- printf(" 27 - Automated binarisation\n");
- printf(" 28 - Negative image\n");
- printf(" 29 - Contrast modification\n");
- printf(" 30 - Gamma correction\n");
- printf(" 31 - Light correction\n");
- printf(" 32 - Filtru trece sus\n");
- printf(" 33 - Filtru trece jos\n");
- printf(" 34 - Salt & pepper median filter\n");
- printf(" 35 - Canny.\n");
- printf(" 0 - Exit\n\n");
- printf("Option: ");
- scanf("%d",&op);
- switch (op)
- {
- case 1:
- testOpenImage();
- break;
- case 2:
- testOpenImagesFld();
- break;
- case 3:
- testResize();
- break;
- case 4:
- testVideoSequence();
- break;
- case 5:
- testSnap();
- break;
- case 6:
- testMouseClick();
- break;
- case 7:
- negative_image();
- break;
- case 8:
- gray_level_add_factor();
- break;
- case 9:
- gray_level_mul_factor();
- break;
- case 10:
- createColorImage();
- break;
- case 11:
- inverseMatrix();
- break;
- case 12:
- separateRGB();
- case 13:
- rgbToGrayscale();
- case 14:
- grayscaleToBinary();
- case 15:
- rgbToHSV();
- case 16:
- isInsideImage();
- case 17:
- calcProperties();
- break;
- case 18:
- bfs();
- case 19:
- generateColorImg();
- case 20:
- follow_border();
- case 21:
- dilatare();
- case 22:
- eroziune();
- case 23:
- incidere();
- case 24:
- deschidere();
- case 25:
- contur();
- case 26:
- histogram();
- case 27:
- automated_binarization();
- case 28:
- negativ();
- case 29:
- contrast_modif();
- case 30:
- gamma_correction();
- case 31:
- light_modif();
- case 32:
- filtru_trece_sus();
- case 33:
- filtru_trece_jos();
- case 34:
- saltPepperFilter();
- case 35:
- canny();
- }
- }
- while (op!=0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement