-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolorModifier.cpp
78 lines (61 loc) · 1.95 KB
/
colorModifier.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
73
74
75
76
77
78
#include "colorModifier.h"
using namespace std;
using namespace cv;
void on_trackbar(int, void* param)
{
Mat mainImage, convertImg;
mainImage = *((Mat*)param);
//copy values of pixels from main image to convert image
mainImage.copyTo(convertImg);
int Channel1, Channel2, Channel3;
double slider1, slider2, slider3;
if (First_Channel > 0)
{
for (int i = 0; i < mainImage.rows; i++)
{
for (int j = 0; j < mainImage.cols; j++)
{
slider1 = (double)First_Channel / 100; //get value of the first slider
Channel1 = (int)mainImage.at<Vec3b>(i, j)[0] * slider1; //save new value of pixel
convertImg.at<Vec3b>(i, j)[0] = (uchar)Channel1; //put new value of pixel
}
}
}
//the same things for 2nd and 3th channel like with the first channel
if (Second_Channel > 0)
{
for (int i = 0; i < mainImage.rows; i++)
{
for (int j = 0; j < mainImage.cols; j++)
{
slider2 = (double)Second_Channel / 100;
Channel2 = (int)mainImage.at<Vec3b>(i, j)[1] * slider2;
convertImg.at<Vec3b>(i, j)[1] = (uchar)Channel2;
}
}
}
if (Third_Channel > 0)
{
for (int i = 0; i < mainImage.rows; i++)
{
for (int j = 0; j < mainImage.cols; j++)
{
slider3 = (double)Third_Channel / 100;
Channel3 = (int)mainImage.at<Vec3b>(i, j)[2] * slider3;
convertImg.at<Vec3b>(i, j)[2] = (uchar)Channel3;
}
}
}
imshow(trackbarWindowName, convertImg);
}
void createTrackbars(Mat image)
{
//create window for trackbars
namedWindow(trackbarWindowName, WINDOW_AUTOSIZE);
//create trackbars
createTrackbar("First(%)", trackbarWindowName, &First_Channel, First_Channel_MAX, on_trackbar,&image);
createTrackbar("Second(%)", trackbarWindowName, &Second_Channel, Second_Channel_MAX, on_trackbar,&image);
createTrackbar("Third(%)", trackbarWindowName, &Third_Channel, Third_Channel_MAX, on_trackbar,&image);
imshow(trackbarWindowName, image);
waitKey(0);
}