-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
72 lines (58 loc) · 1.73 KB
/
main.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
67
68
69
70
71
72
/*
* File: main.cpp
* Author: heshan
*
* Created on March 3, 2018, 10:05 PM
*/
#include <iostream>
#include "opencv2/imgproc.hpp"
#include <opencv2/highgui.hpp>
double thresh;
double maxValue;
cv::Mat globalThreshold(cv::Mat img) {
cv::Mat output;
// Set threshold and maxValue
thresh = 50;
maxValue = 255;
// Binary Threshold
threshold(img, output, thresh, maxValue, cv::THRESH_BINARY);
return output;
}
cv::Mat adaptiveMeanThreshold(cv::Mat img) {
cv::Mat output;
// Set threshold and maxValue
maxValue = 255;
// Adaptive Threshold
adaptiveThreshold(img, output, maxValue, cv::ADAPTIVE_THRESH_MEAN_C, cv::THRESH_BINARY,11,2);
return output;
}
cv::Mat adaptiveGaussianThreshold(cv::Mat img) {
cv::Mat output;
// Set threshold and maxValue
maxValue = 255;
// Adaptive Threshold
adaptiveThreshold(img, output, maxValue, cv::ADAPTIVE_THRESH_GAUSSIAN_C, cv::THRESH_BINARY,11,2);
return output;
}
cv::Mat otsuThreshold(cv::Mat img) {
cv::Mat output;
// Set threshold and maxValue
thresh = 50;
maxValue = 255;
// Otsu Threshold
threshold(img, output, thresh, maxValue, cv::THRESH_BINARY + cv::THRESH_OTSU);
return output;
}
int main() {
cv::Mat input = cv::imread("imgs/input.jpg", 0);
cv::Mat output;
output = globalThreshold(input);
cv::imwrite( "imgs/globalThresholdOut.jpg", output );
output = adaptiveMeanThreshold(input);
cv::imwrite( "imgs/adaptiveMeanThresholdOut.jpg", output );
output = adaptiveGaussianThreshold(input);
cv::imwrite( "imgs/adaptiveGaussianThresholdOut.jpg", output );
output = otsuThreshold(input);
cv::imwrite( "imgs/otsuThresholdOut.jpg", output );
return 0;
}