-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex14.cpp
More file actions
44 lines (38 loc) · 694 Bytes
/
Copy pathex14.cpp
File metadata and controls
44 lines (38 loc) · 694 Bytes
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
#include <opencv2/opencv.hpp>
CvScalar function(CvScalar f)
{
CvScalar g = f;
for (int k = 0; k < 3; k++)
{
if (g.val[k] < 128)
{
g.val[k] = 256- g.val[k] * 256 / 128;
}
else
{
g.val[k] = 256 - (512 - g.val[k] * 256 / 128);
}
}
return g;
}
int main()
{
IplImage* src = cvLoadImage("C:\\temp\\Lena.png");
CvSize size = cvGetSize(src);
IplImage* dst = cvCreateImage(size, 8, 3);
int w = size.width;
int h = size.height;
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
CvScalar f = cvGet2D(src, y, x);
CvScalar g = function(f);
cvSet2D(dst, y, x, g);
}
}
cvShowImage("src", src);
cvShowImage("dst", dst);
cvWaitKey();
return 0;
}