-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_images.cpp
67 lines (40 loc) · 1.44 KB
/
process_images.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*using my image processing functions
* written in python for C++ implementation */
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
#include <string>
using namespace cv;
using namespace std;
Mat processRectDivision(Mat image){
//note: this takes in 1-channel images for input
Mat gray, smooth, dst;
cvtColor(image, gray, CV_BGR2GRAY);// gray in case of emergency
Mat kernel = getStructuringElement(MORPH_RECT, Size(5,5));
morphologyEx(gray, smooth, MORPH_DILATE, kernel); //bring out everything
divide(gray, smooth, dst, 255.0);
return dst;
}
Mat processCircDivision(Mat image){
/*take in a 1-channel grayscale image and
* return a division of the processed image
* that brings out the circular features
* used in detectCircles()*/
Mat smooth, div;
Mat rectKernel = getStructuringElement(MORPH_RECT, Size(5,5));
Mat circKernel = getStructuringElement(MORPH_ELLIPSE, Size(5,5));
morphologyEx(image, smooth, MORPH_DILATE, rectKernel);
medianBlur(smooth, smooth, 5);
morphologyEx(smooth, smooth, MORPH_DILATE, circKernel);
divide(image, smooth, div, 255.0);
return div;
}
int main(){
string filename = "data/images/Test21_1.tif";
Mat image = imread(filename);
Mat processed = processRectDivision(image);
imshow("processed image", processed);
waitKey(0);
return 0;
}