-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuccessiveDifferenceOperator.cpp
More file actions
118 lines (44 loc) · 1.3 KB
/
SuccessiveDifferenceOperator.cpp
File metadata and controls
118 lines (44 loc) · 1.3 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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include<opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
int main(int argc, char *argv[])
{
if (argc != 3) {
printf("Enter exeFileName imageFileName\n");
}
Mat image = imread(argv[1], IMREAD_COLOR);
if (image.empty()) {
cout << "Error: No Image to load" << endl;
}
Mat gr(image.rows,image.cols,CV_8UC1,Scalar(0));
cvtColor(image,gr,COLOR_BGR2GRAY);
Mat dest = gr.clone();
int T = atoi(argv[2]);
int gx = 0;
int gy = 0;
int G = 0;
for (int i = 0; i < gr.rows - 1; i++) {
for (int j = 0; j < gr.cols - 1; j++) {
gx = (int)gr.at<uchar>(i, j) - (int)gr.at<uchar>(i, j + 1);
gy = (int)gr.at<uchar>(i, j) - (int)gr.at<uchar>(i+1, j);
G = abs(gx) + abs(gy);
if (G >= T) {
dest.at<uchar>(i, j) = 255;
}
else {
dest.at<uchar>(i, j) = 0;
}
}
}
// display histogram
namedWindow("Gray Image", 1);
imshow("Gray Image", gr);
namedWindow("Edge Detected Image", 1);
imshow("Edge Detected Image", dest);
waitKey();
gr.release();
return 0;
}