-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpixel.cpp
201 lines (171 loc) · 3.51 KB
/
pixel.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include <algorithm>
#include <cmath>
#include "pixel.h"
using namespace std;
namespace imageRegistration
{
//drgb operator + (const drgb & a, const drgb & b)
//{
// drgb c(a);
// c.r += b.r;
// c.g += b.g;
// c.b += b.b;
// return c;
//}
//drgb operator - (const drgb & a, const drgb & b)
//{
// drgb c(a);
// c.r -= b.r;
// c.g -= b.g;
// c.b -= b.b;
// return c;
//}
//drgb operator / (const drgb & a, int b)
//{
// drgb c(a);
// c.r /= b;
// c.g /= b;
// c.b /= b;
// return c;
//}
//drgb operator - (const drgb & a, int b)
//{
// drgb c(a);
// c.r -= b;
// c.g -= b;
// c.b -= b;
// return c;
//}
drgb operator * (const drgb & a, const drgb & b)
{
drgb c(a);
c.r *= b.r;
c.g *= b.g;
c.b *= b.b;
return c;
}
drgb & operator += (drgb & a, const drgb & b)
{
a.r += b.r;
a.g += b.g;
a.b += b.b;
return a;
}
drgb & operator -= (drgb & a, const drgb & b)
{
a.r -= b.r;
a.g -= b.g;
a.b -= b.b;
return a;
}
drgb & operator /= (drgb & a, const int & b)
{
a.r /= b;
a.g /= b;
a.b /= b;
return a;
}
drgb & operator *= (drgb & a, const double & b)
{
a.r *= b;
a.g *= b;
a.b *= b;
return a;
}
drgb& operator /= (drgb& a, const drgb& b)
{
if ((b.r == 0.0) || (b.g == 0.0) || (b.b == 0.0))
throw("division with 0, exiting");
a.r /= b.r;
a.g /= b.g;
a.b /= b.b;
return a;
}
/// Find the maximum color level of a double rgb pixel.
int lMax(drgb point)
{
return(int)(max(max(max(point.r, -point.r), max(point.g, -point.g)), max(point.b, -point.b)));
}
void drgb::write(char & cr, char & cg, char & cb) const
{
cr = (char)(r);
cg = (char)(g);
cb = (char)(b);
}
double drgb::gray() const
{
return (r + g + b) / 3.0;
}
drgb drgb::geomMean(const drgb& a, const drgb& b)
{
return drgb (sqrt(a.r * b.r), sqrt(a.g * b.g), sqrt(a.b * b.b));
}
//void drgb::piecewiseDiv(drgb& a, const drgb& b)
//{
// if (b.r * b.g * b.b == 0.0)
// throw("division with 0, exiting");
// a.r /= b.r;
// a.g /= b.g;
// a.b /= b.b;
// return;
//}
dGray operator * (const dGray & a, const dGray & b)
{
dGray c(a);
c.grayValue *= b.grayValue;
return c;
}
dGray & operator += (dGray & a, const dGray & b)
{
a.grayValue += b.grayValue;
return a;
}
dGray & operator -= (dGray & a, const dGray & b)
{
a.grayValue -= b.grayValue;
return a;
}
dGray & operator /= (dGray & a, const int & b)
{
a.grayValue /= b;
return a;
}
dGray & operator *= (dGray & a, const double & b)
{
a.grayValue *= b;
return a;
}
dGray & operator /= (dGray& a, const dGray& b)
{
if (b.grayValue == 0.0)
throw("division with 0, exiting");
a.grayValue /= b.grayValue;
return a;
}
/// Find the maximum color level of a double rgb pixel.
int lMax(dGray point)
{
return(int)(max(-point.grayValue, point.grayValue));
}
void dGray::write(char & cr, char & cg, char & cb) const
{
cr = (char)(grayValue);
cg = (char)(grayValue);
cb = (char)(grayValue);
}
double dGray::gray() const
{
return grayValue;
}
dGray dGray::geomMean(const dGray& a, const dGray& b)
{
return dGray(sqrt(a.grayValue * b.grayValue));
}
//void dGray::piecewiseDiv(dGray& a, const dGray& b)
//{
// if (b.grayValue == 0.0)
// throw("division with 0, exiting");
// a.grayValue /= b.grayValue;
// return;
//}
}