forked from spmallick/learnopencv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreshold.cpp
More file actions
47 lines (36 loc) · 1.21 KB
/
Copy paththreshold.cpp
File metadata and controls
47 lines (36 loc) · 1.21 KB
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
/**
* OpenCV Threshold Example
*
* Copyright 2015 by Satya Mallick <[email protected]>
*
**/
#include "opencv2/opencv.hpp"
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
// Read image
Mat src = imread("threshold.png", IMREAD_GRAYSCALE);
Mat dst;
// Basic threhold example
threshold(src,dst,0, 255, THRESH_BINARY);
imwrite("opencv-threshold-example.jpg", dst);
// Thresholding with maxval set to 128
threshold(src, dst, 0, 128, THRESH_BINARY);
imwrite("opencv-thresh-binary-maxval.jpg", dst);
// Thresholding with threshold value set 127
threshold(src,dst,127,255, THRESH_BINARY);
imwrite("opencv-thresh-binary.jpg", dst);
// Thresholding using THRESH_BINARY_INV
threshold(src,dst,127,255, THRESH_BINARY_INV);
imwrite("opencv-thresh-binary-inv.jpg", dst);
// Thresholding using THRESH_TRUNC
threshold(src,dst,127,255, THRESH_TRUNC);
imwrite("opencv-thresh-trunc.jpg", dst);
// Thresholding using THRESH_TOZERO
threshold(src,dst,127,255, THRESH_TOZERO);
imwrite("opencv-thresh-tozero.jpg", dst);
// Thresholding using THRESH_TOZERO_INV
threshold(src,dst,127,255, THRESH_TOZERO_INV);
imwrite("opencv-thresh-to-zero-inv.jpg", dst);
}