-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel.cpp
136 lines (127 loc) · 4.56 KB
/
channel.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "channel.h"
Channel::Channel(QWidget *parent, const Mat &image) : QWidget(parent)
{
src = image;
dst = src.clone();
rows = src.rows;
cols = src.cols;
beta = 0;
}
void Channel::valueChanged(int value)
{
QSlider *slider = qobject_cast<QSlider*>(sender());
if(slider == blue)
{
if(src.channels() != 3) return;
alpha_b = (value + 100)/100.00;
dst = Mat::zeros(src.size(), src.type());
for(int row = 0; row < rows; row++)
{
for(int col = 0; col < cols; col++)
{
int b = src.at<Vec3b>(row, col)[0];
int g = src.at<Vec3b>(row, col)[1];
int r = src.at<Vec3b>(row, col)[2];
dst.at<Vec3b>(row, col)[0] = saturate_cast<uchar>(alpha*alpha_b*b + beta);
dst.at<Vec3b>(row, col)[1] = saturate_cast<uchar>(alpha*alpha_g*g + beta);
dst.at<Vec3b>(row, col)[2] = saturate_cast<uchar>(alpha*alpha_r*r + beta);
}
}
}
else if(slider == green)
{
if(src.channels() != 3) return;
alpha_g = (value + 100)/100.00;
dst = Mat::zeros(src.size(), src.type());
for(int row = 0; row < rows; row++)
{
for(int col = 0; col < cols; col++)
{
int b = src.at<Vec3b>(row, col)[0];
int g = src.at<Vec3b>(row, col)[1];
int r = src.at<Vec3b>(row, col)[2];
dst.at<Vec3b>(row, col)[0] = saturate_cast<uchar>(alpha*alpha_b*b + beta);
dst.at<Vec3b>(row, col)[1] = saturate_cast<uchar>(alpha*alpha_g*g + beta);
dst.at<Vec3b>(row, col)[2] = saturate_cast<uchar>(alpha*alpha_r*r + beta);
}
}
}
else if(slider == red)
{
if(src.channels() != 3) return;
alpha_r = (value + 100)/100.00;
dst = Mat::zeros(src.size(), src.type());
for(int row = 0; row < rows; row++)
{
for(int col = 0; col < cols; col++)
{
int b = src.at<Vec3b>(row, col)[0];
int g = src.at<Vec3b>(row, col)[1];
int r = src.at<Vec3b>(row, col)[2];
dst.at<Vec3b>(row, col)[0] = saturate_cast<uchar>(alpha*alpha_b*b + beta);
dst.at<Vec3b>(row, col)[1] = saturate_cast<uchar>(alpha*alpha_g*g + beta);
dst.at<Vec3b>(row, col)[2] = saturate_cast<uchar>(alpha*alpha_r*r + beta);
}
}
}
else if(slider == contrast)
{
alpha = (value + 100)/100.00;
dst = Mat::zeros(src.size(), src.type());
for(int row = 0; row < rows; row++)
{
for(int col = 0; col < cols; col++)
{
if(src.channels() != 3)
{
int p = src.at<uchar>(row, col);
dst.at<uchar>(row, col) = saturate_cast<uchar>(alpha*p + beta);
}
else
{
int b = src.at<Vec3b>(row, col)[0];
int g = src.at<Vec3b>(row, col)[1];
int r = src.at<Vec3b>(row, col)[2];
dst.at<Vec3b>(row, col)[0] = saturate_cast<uchar>(alpha*alpha_b*b + beta);
dst.at<Vec3b>(row, col)[1] = saturate_cast<uchar>(alpha*alpha_g*g + beta);
dst.at<Vec3b>(row, col)[2] = saturate_cast<uchar>(alpha*alpha_r*r + beta);
}
}
}
}
else
{
beta = value;
dst = Mat::zeros(src.size(), src.type());
for(int row = 0; row < rows; row++)
{
for(int col = 0; col < cols; col++)
{
if(src.channels() != 3)
{
int p = src.at<uchar>(row, col);
dst.at<uchar>(row, col) = saturate_cast<uchar>(alpha*p + beta);
}
else
{
int b = src.at<Vec3b>(row, col)[0];
int g = src.at<Vec3b>(row, col)[1];
int r = src.at<Vec3b>(row, col)[2];
dst.at<Vec3b>(row, col)[0] = saturate_cast<uchar>(alpha*alpha_b*b + beta);
dst.at<Vec3b>(row, col)[1] = saturate_cast<uchar>(alpha*alpha_g*g + beta);
dst.at<Vec3b>(row, col)[2] = saturate_cast<uchar>(alpha*alpha_r*r + beta);
}
}
}
}
imshow("Preview", dst);
}
void Channel::rejected()
{
beta = 0;
red->setValue(1.00);
blue->setValue(1.00);
green->setValue(1.00);
contrast->setValue(1.00);
brightness->setValue(1.00);
}