Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
385bcb76
Commit
385bcb76
authored
Jul 26, 2016
by
sutr90
Browse files
Added support for CIELab color space pixels.
parent
d83b54d2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
486 additions
and
6 deletions
+486
-6
dlib/matrix/matrix_utilities.h
dlib/matrix/matrix_utilities.h
+34
-2
dlib/pixel.h
dlib/pixel.h
+372
-3
dlib/test/pixel.cpp
dlib/test/pixel.cpp
+80
-1
No files found.
dlib/matrix/matrix_utilities.h
View file @
385bcb76
...
...
@@ -2573,7 +2573,8 @@ namespace dlib
pixel_traits
<
P
>
::
grayscale
,
pixel_traits
<
P
>::
rgb
,
pixel_traits
<
P
>::
hsi
,
pixel_traits
<
P
>::
rgb_alpha
pixel_traits
<
P
>::
rgb_alpha
,
pixel_traits
<
P
>::
lab
>::
value
>
struct
pixel_to_vector_helper
;
...
...
@@ -2637,6 +2638,21 @@ namespace dlib
}
};
template
<
typename
P
>
struct
pixel_to_vector_helper
<
P
,
5
>
{
template
<
typename
M
>
static
void
assign
(
M
&
m
,
const
P
&
pixel
)
{
m
(
0
)
=
static_cast
<
typename
M
::
type
>
(
pixel
.
l
);
m
(
1
)
=
static_cast
<
typename
M
::
type
>
(
pixel
.
a
);
m
(
2
)
=
static_cast
<
typename
M
::
type
>
(
pixel
.
b
);
}
};
template
<
typename
T
,
...
...
@@ -2660,7 +2676,8 @@ namespace dlib
pixel_traits
<
P
>
::
grayscale
,
pixel_traits
<
P
>::
rgb
,
pixel_traits
<
P
>::
hsi
,
pixel_traits
<
P
>::
rgb_alpha
pixel_traits
<
P
>::
rgb_alpha
,
pixel_traits
<
P
>::
lab
>::
value
>
struct
vector_to_pixel_helper
;
...
...
@@ -2724,6 +2741,21 @@ namespace dlib
}
};
template
<
typename
P
>
struct
vector_to_pixel_helper
<
P
,
5
>
{
template
<
typename
M
>
static
void
assign
(
P
&
pixel
,
const
M
&
m
)
{
pixel
.
l
=
static_cast
<
signed
char
>
(
m
(
0
));
pixel
.
a
=
static_cast
<
signed
char
>
(
m
(
1
));
pixel
.
b
=
static_cast
<
signed
char
>
(
m
(
2
));
}
};
template
<
typename
P
,
typename
EXP
...
...
dlib/pixel.h
View file @
385bcb76
...
...
@@ -36,6 +36,7 @@ namespace dlib
- bool rgb
- bool rgb_alpha
- bool hsi
- bool lab
- bool has_alpha
...
...
@@ -47,7 +48,7 @@ namespace dlib
- is_unsigned
The above public constants are subject to the following constraints:
- only one of grayscale, rgb, rgb_alpha,
or
hsi is true
- only one of grayscale, rgb, rgb_alpha, hsi
or lab
is true
- if (rgb == true) then
- The type T will be a struct with 3 public members of type
unsigned char named "red" "green" and "blue".
...
...
@@ -81,6 +82,16 @@ namespace dlib
- min() == 0
- max() == 255
- is_unsigned == true
- else if (lab == true) then
- The type T will be a struct with 3 public members of type
signed char named "l" "a" and "b".
- This type of pixel represents the Lab color space.
- num == 3
- has_alpha == false
- basic_pixel_type == signed char
- min() == -128
- max() == 127
- is_unsigned == false
- else
- grayscale == true
- This type of pixel represents a grayscale color space. T
...
...
@@ -190,6 +201,28 @@ namespace dlib
unsigned
char
s
;
unsigned
char
i
;
};
// ----------------------------------------------------------------------------------------
struct
lab_pixel
{
/*!
WHAT THIS OBJECT REPRESENTS
This is a simple struct that represents an Lab colored graphical pixel.
!*/
lab_pixel
(
)
{}
lab_pixel
(
signed
char
l_
,
signed
char
a_
,
signed
char
b_
)
:
l
(
l_
),
a
(
a_
),
b
(
b_
)
{}
signed
char
l
;
signed
char
a
;
signed
char
b
;
};
// ----------------------------------------------------------------------------------------
...
...
@@ -338,6 +371,17 @@ namespace dlib
provides serialization support for the hsi_pixel struct
!*/
// ----------------------------------------------------------------------------------------
inline
void
serialize
(
const
lab_pixel
&
item
,
std
::
ostream
&
out
);
/*!
provides serialization support for the lab_pixel struct
!*/
// ----------------------------------------------------------------------------------------
inline
void
deserialize
(
...
...
@@ -347,6 +391,15 @@ namespace dlib
/*!
provides deserialization support for the hsi_pixel struct
!*/
// ----------------------------------------------------------------------------------------
inline
void
deserialize
(
lab_pixel
&
item
,
std
::
istream
&
in
);
/*!
provides deserialization support for the lab_pixel struct
!*/
// ----------------------------------------------------------------------------------------
...
...
@@ -357,6 +410,7 @@ namespace dlib
const
static
bool
rgb_alpha
=
false
;
const
static
bool
grayscale
=
false
;
const
static
bool
hsi
=
false
;
const
static
bool
lab
=
false
;
enum
{
num
=
3
};
typedef
unsigned
char
basic_pixel_type
;
static
basic_pixel_type
min
()
{
return
0
;}
...
...
@@ -374,6 +428,7 @@ namespace dlib
const
static
bool
rgb_alpha
=
false
;
const
static
bool
grayscale
=
false
;
const
static
bool
hsi
=
false
;
const
static
bool
lab
=
false
;
enum
{
num
=
3
};
typedef
unsigned
char
basic_pixel_type
;
static
basic_pixel_type
min
()
{
return
0
;}
...
...
@@ -391,6 +446,7 @@ namespace dlib
const
static
bool
rgb_alpha
=
true
;
const
static
bool
grayscale
=
false
;
const
static
bool
hsi
=
false
;
const
static
bool
lab
=
false
;
enum
{
num
=
4
};
typedef
unsigned
char
basic_pixel_type
;
static
basic_pixel_type
min
()
{
return
0
;}
...
...
@@ -409,6 +465,7 @@ namespace dlib
const
static
bool
rgb_alpha
=
false
;
const
static
bool
grayscale
=
false
;
const
static
bool
hsi
=
true
;
const
static
bool
lab
=
false
;
enum
{
num
=
3
};
typedef
unsigned
char
basic_pixel_type
;
static
basic_pixel_type
min
()
{
return
0
;}
...
...
@@ -417,6 +474,25 @@ namespace dlib
const
static
bool
has_alpha
=
false
;
};
// ----------------------------------------------------------------------------------------
template
<
>
struct
pixel_traits
<
lab_pixel
>
{
const
static
bool
rgb
=
false
;
const
static
bool
rgb_alpha
=
false
;
const
static
bool
grayscale
=
false
;
const
static
bool
hsi
=
false
;
const
static
bool
lab
=
true
;
const
static
long
num
=
3
;
typedef
signed
char
basic_pixel_type
;
static
basic_pixel_type
min
()
{
return
-
128
;}
static
basic_pixel_type
max
()
{
return
127
;}
const
static
bool
is_unsigned
=
false
;
const
static
bool
has_alpha
=
false
;
};
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
...
...
@@ -426,6 +502,7 @@ namespace dlib
const
static
bool
rgb_alpha
=
false
;
const
static
bool
grayscale
=
true
;
const
static
bool
hsi
=
false
;
const
static
bool
lab
=
false
;
enum
{
num
=
1
};
const
static
bool
has_alpha
=
false
;
typedef
T
basic_pixel_type
;
...
...
@@ -457,6 +534,7 @@ namespace dlib
const
static
bool
rgb_alpha
=
false
;
const
static
bool
grayscale
=
true
;
const
static
bool
hsi
=
false
;
const
static
bool
lab
=
false
;
enum
{
num
=
1
};
const
static
bool
has_alpha
=
false
;
typedef
T
basic_pixel_type
;
...
...
@@ -615,6 +693,15 @@ namespace dlib
dest
.
i
=
src
.
i
;
}
template
<
typename
P1
,
typename
P2
>
typename
enable_if_c
<
pixel_traits
<
P1
>::
lab
&&
pixel_traits
<
P2
>::
lab
>::
type
assign
(
P1
&
dest
,
const
P2
&
src
)
{
dest
.
l
=
src
.
l
;
dest
.
a
=
src
.
a
;
dest
.
b
=
src
.
b
;
}
// -----------------------------
// dest is a grayscale
...
...
@@ -673,6 +760,13 @@ namespace dlib
assign_pixel
(
dest
,
src
.
i
);
}
template
<
typename
P1
,
typename
P2
>
typename
enable_if_c
<
pixel_traits
<
P1
>::
grayscale
&&
pixel_traits
<
P2
>::
lab
>::
type
assign
(
P1
&
dest
,
const
P2
&
src
)
{
assign_pixel
(
dest
,
src
.
l
);
}
// -----------------------------
...
...
@@ -771,6 +865,158 @@ namespace dlib
return
(
c2
);
}
// -----------------------------
struct
Lab
{
double
l
;
double
a
;
double
b
;
};
/*
Calculate Lab from RGB
L is between 0 and 100
a is between -128 and 127
b is between -128 and 127
*/
inline
Lab
RGB2Lab
(
COLOUR
c1
)
{
Lab
c2
;
using
namespace
std
;
double
var_R
=
c1
.
r
;
double
var_G
=
c1
.
g
;
double
var_B
=
c1
.
b
;
if
(
var_R
>
0.04045
)
{
var_R
=
pow
(((
var_R
+
0.055
)
/
1.055
),
2.4
);
}
else
{
var_R
=
var_R
/
12.92
;
}
if
(
var_G
>
0.04045
)
{
var_G
=
pow
(((
var_G
+
0.055
)
/
1.055
),
2.4
);
}
else
{
var_G
=
var_G
/
12.92
;
}
if
(
var_B
>
0.04045
)
{
var_B
=
pow
(((
var_B
+
0.055
)
/
1.055
),
2.4
);
}
else
{
var_B
=
var_B
/
12.92
;
}
var_R
=
var_R
*
100
;
var_G
=
var_G
*
100
;
var_B
=
var_B
*
100
;
//Observer. = 2°, Illuminant = D65
double
X
=
var_R
*
0.4124
+
var_G
*
0.3576
+
var_B
*
0.1805
;
double
Y
=
var_R
*
0.2126
+
var_G
*
0.7152
+
var_B
*
0.0722
;
double
Z
=
var_R
*
0.0193
+
var_G
*
0.1192
+
var_B
*
0.9505
;
double
var_X
=
X
/
95.047
;
double
var_Y
=
Y
/
100.000
;
double
var_Z
=
Z
/
108.883
;
if
(
var_X
>
0.008856
)
{
var_X
=
pow
(
var_X
,
(
1.0
/
3
));
}
else
{
var_X
=
(
7.787
*
var_X
)
+
(
16.0
/
116
);
}
if
(
var_Y
>
0.008856
)
{
var_Y
=
pow
(
var_Y
,
(
1.0
/
3
));
}
else
{
var_Y
=
(
7.787
*
var_Y
)
+
(
16.0
/
116
);
}
if
(
var_Z
>
0.008856
)
{
var_Z
=
pow
(
var_Z
,
(
1.0
/
3
));
}
else
{
var_Z
=
(
7.787
*
var_Z
)
+
(
16.0
/
116
);
}
c2
.
l
=
(
116
*
var_Y
)
-
16
;
c2
.
a
=
500
*
(
var_X
-
var_Y
);
c2
.
b
=
200
*
(
var_Y
-
var_Z
);
return
c2
;
}
/*
Calculate RGB from HSL, reverse of RGB2HSL()
Hue is in degrees
Lightness is between 0 and 1
Saturation is between 0 and 1
*/
inline
COLOUR
Lab2RGB
(
Lab
c1
)
{
COLOUR
c2
;
using
namespace
std
;
double
var_Y
=
(
c1
.
l
+
16
)
/
116.0
;
double
var_X
=
(
c1
.
a
/
500.0
)
+
var_Y
;
double
var_Z
=
var_Y
-
(
c1
.
b
/
200
);
if
(
pow
(
var_Y
,
3
)
>
0.008856
)
{
var_Y
=
pow
(
var_Y
,
3
);
}
else
{
var_Y
=
(
var_Y
-
16.0
/
116
)
/
7.787
;
}
if
(
pow
(
var_X
,
3
)
>
0.008856
)
{
var_X
=
pow
(
var_X
,
3
);
}
else
{
var_X
=
(
var_X
-
16.0
/
116
)
/
7.787
;
}
if
(
pow
(
var_Z
,
3
)
>
0.008856
)
{
var_Z
=
pow
(
var_Z
,
3
);
}
else
{
var_Z
=
(
var_Z
-
16.0
/
116
)
/
7.787
;
}
double
X
=
var_X
*
95.047
;
double
Y
=
var_Y
*
100.000
;
double
Z
=
var_Z
*
108.883
;
var_X
=
X
/
100.0
;
var_Y
=
Y
/
100.0
;
var_Z
=
Z
/
100.0
;
double
var_R
=
var_X
*
3.2406
+
var_Y
*
-
1.5372
+
var_Z
*
-
0.4986
;
double
var_G
=
var_X
*
-
0.9689
+
var_Y
*
1.8758
+
var_Z
*
0.0415
;
double
var_B
=
var_X
*
0.0557
+
var_Y
*
-
0.2040
+
var_Z
*
1.0570
;
if
(
var_R
>
0.0031308
)
{
var_R
=
1.055
*
pow
(
var_R
,
(
1
/
2.4
))
-
0.055
;
}
else
{
var_R
=
12.92
*
var_R
;
}
if
(
var_G
>
0.0031308
)
{
var_G
=
1.055
*
pow
(
var_G
,
(
1
/
2.4
))
-
0.055
;
}
else
{
var_G
=
12.92
*
var_G
;
}
if
(
var_B
>
0.0031308
)
{
var_B
=
1.055
*
pow
(
var_B
,
(
1
/
2.4
))
-
0.055
;
}
else
{
var_B
=
12.92
*
var_B
;
}
c2
.
r
=
var_R
;
c2
.
g
=
var_G
;
c2
.
b
=
var_B
;
return
(
c2
);
}
// -----------------------------
// dest is a color rgb_pixel
...
...
@@ -853,6 +1099,23 @@ namespace dlib
dest
.
blue
=
static_cast
<
unsigned
char
>
(
c
.
b
*
255.0
+
0.5
);
}
template
<
typename
P1
,
typename
P2
>
typename
enable_if_c
<
pixel_traits
<
P1
>::
rgb
&&
pixel_traits
<
P2
>::
lab
>::
type
assign
(
P1
&
dest
,
const
P2
&
src
)
{
COLOUR
c
;
Lab
l
;
l
.
l
=
src
.
l
;
l
.
a
=
src
.
a
;
l
.
b
=
src
.
b
;
c
=
Lab2RGB
(
l
);
dest
.
red
=
static_cast
<
unsigned
char
>
(
c
.
r
*
255.0
+
0.5
);
dest
.
green
=
static_cast
<
unsigned
char
>
(
c
.
g
*
255.0
+
0.5
);
dest
.
blue
=
static_cast
<
unsigned
char
>
(
c
.
b
*
255.0
+
0.5
);
}
// -----------------------------
// dest is a color rgb_alpha_pixel
...
...
@@ -908,6 +1171,22 @@ namespace dlib
dest
.
alpha
=
255
;
}
template
<
typename
P1
,
typename
P2
>
typename
enable_if_c
<
pixel_traits
<
P1
>::
rgb_alpha
&&
pixel_traits
<
P2
>::
lab
>::
type
assign
(
P1
&
dest
,
const
P2
&
src
)
{
COLOUR
c
;
Lab
l
;
l
.
l
=
src
.
l
;
l
.
a
=
src
.
a
;
l
.
b
=
src
.
b
;
c
=
Lab2RGB
(
l
);
dest
.
red
=
static_cast
<
unsigned
char
>
(
c
.
r
);
dest
.
green
=
static_cast
<
unsigned
char
>
(
c
.
g
);
dest
.
blue
=
static_cast
<
unsigned
char
>
(
c
.
b
);
dest
.
alpha
=
255
;
}
// -----------------------------
// dest is an hsi pixel
...
...
@@ -962,6 +1241,58 @@ namespace dlib
assign_pixel_helpers
::
assign
(
dest
,
temp
);
}
// -----------------------------
// dest is an lab pixel
template
<
typename
P1
>
typename
enable_if_c
<
pixel_traits
<
P1
>::
lab
>::
type
assign
(
P1
&
dest
,
const
unsigned
char
&
src
)
{
dest
.
a
=
0
;
dest
.
b
=
0
;
dest
.
l
=
src
;
}
template
<
typename
P1
,
typename
P2
>
typename
enable_if_c
<
pixel_traits
<
P1
>::
lab
&&
pixel_traits
<
P2
>::
grayscale
>::
type
assign
(
P1
&
dest
,
const
P2
&
src
)
{
dest
.
a
=
0
;
dest
.
b
=
0
;
assign_pixel
(
dest
.
l
,
src
);
}
template
<
typename
P1
,
typename
P2
>
typename
enable_if_c
<
pixel_traits
<
P1
>::
lab
&&
pixel_traits
<
P2
>::
rgb
>::
type
assign
(
P1
&
dest
,
const
P2
&
src
)
{
COLOUR
c1
;
Lab
c2
;
c1
.
r
=
src
.
red
/
255.0
;
c1
.
g
=
src
.
green
/
255.0
;
c1
.
b
=
src
.
blue
/
255.0
;
c2
=
RGB2Lab
(
c1
);
dest
.
l
=
static_cast
<
signed
char
>
(
c2
.
l
+
0.5
);
dest
.
a
=
static_cast
<
signed
char
>
(
c2
.
a
+
0.5
);
dest
.
b
=
static_cast
<
signed
char
>
(
c2
.
b
+
0.5
);
}
template
<
typename
P1
,
typename
P2
>
typename
enable_if_c
<
pixel_traits
<
P1
>::
lab
&&
pixel_traits
<
P2
>::
rgb_alpha
>::
type
assign
(
P1
&
dest
,
const
P2
&
src
)
{
rgb_pixel
temp
;
// convert target lab pixel to rgb
assign_pixel_helpers
::
assign
(
temp
,
dest
);
// now assign the rgb_alpha value to our temp rgb pixel
assign_pixel_helpers
::
assign
(
temp
,
src
);
// now we can just go assign the new rgb value to the
// hsi pixel
assign_pixel_helpers
::
assign
(
dest
,
temp
);
}
}
// -----------------------------
...
...
@@ -990,7 +1321,7 @@ namespace dlib
typename
P
,
typename
T
>
inline
typename
enable_if_c
<
pixel_traits
<
P
>::
grayscale
==
false
&&
inline
typename
enable_if_c
<
pixel_traits
<
P
>::
grayscale
==
false
&&
pixel_traits
<
P
>::
has_alpha
>::
type
assign_pixel_intensity_helper
(
P
&
dest
,
const
T
&
new_intensity
...
...
@@ -1011,7 +1342,7 @@ namespace dlib
typename
P
,
typename
T
>
inline
typename
enable_if_c
<
pixel_traits
<
P
>::
grayscale
==
false
&&
inline
typename
enable_if_c
<
pixel_traits
<
P
>::
grayscale
==
false
&&
pixel_traits
<
P
>::
has_alpha
==
false
>::
type
assign_pixel_intensity_helper
(
P
&
dest
,
const
T
&
new_intensity
...
...
@@ -1243,6 +1574,44 @@ namespace dlib
}
}
// ----------------------------------------------------------------------------------------
inline
void
serialize
(
const
lab_pixel
&
item
,
std
::
ostream
&
out
)
{
try
{
serialize
(
item
.
l
,
out
);
serialize
(
item
.
a
,
out
);
serialize
(
item
.
b
,
out
);
}
catch
(
serialization_error
&
e
)
{
throw
serialization_error
(
e
.
info
+
"
\n
while serializing object of type lab_pixel"
);
}
}
// ----------------------------------------------------------------------------------------
inline
void
deserialize
(
lab_pixel
&
item
,
std
::
istream
&
in
)
{
try
{
deserialize
(
item
.
l
,
in
);
deserialize
(
item
.
a
,
in
);
deserialize
(
item
.
b
,
in
);
}
catch
(
serialization_error
&
e
)
{
throw
serialization_error
(
e
.
info
+
"
\n
while deserializing object of type lab_pixel"
);
}
}
// ----------------------------------------------------------------------------------------
}
...
...
dlib/test/pixel.cpp
View file @
385bcb76
...
...
@@ -39,6 +39,7 @@ namespace
rgb_pixel
p_rgb
;
hsi_pixel
p_hsi
,
p_hsi2
;
rgb_alpha_pixel
p_rgba
;
lab_pixel
p_lab
,
p_lab2
;
assign_pixel
(
p_int
,
0.0
f
);
assign_pixel
(
p_float
,
0.0
f
);
...
...
@@ -49,6 +50,7 @@ namespace
assign_pixel
(
p_hsi
,
-
4
);
assign_pixel
(
p_rgba
,
p_int
);
assign_pixel
(
p_gray16
,
0
);
assign_pixel
(
p_lab
,
-
400
);
DLIB_TEST
(
p_int
==
0
);
DLIB_TEST
(
p_float
==
0
);
...
...
@@ -70,11 +72,16 @@ namespace
DLIB_TEST
(
p_hsi
.
s
==
0
);
DLIB_TEST
(
p_hsi
.
i
==
0
);
DLIB_TEST
(
p_lab
.
l
==
-
128
);
DLIB_TEST
(
p_lab
.
a
==
0
);
DLIB_TEST
(
p_lab
.
b
==
0
);
assign_pixel
(
p_gray
,
10
);
assign_pixel
(
p_gray16
,
10
);
assign_pixel
(
p_rgb
,
10
);
assign_pixel
(
p_hsi
,
10
);
assign_pixel
(
p_rgba
,
10
);
assign_pixel
(
p_lab
,
10
);
assign_pixel
(
p_int
,
-
10
);
assign_pixel
(
p_float
,
-
10
);
...
...
@@ -100,6 +107,10 @@ namespace
DLIB_TEST
(
p_hsi
.
s
==
0
);
DLIB_TEST
(
p_hsi
.
i
==
10
);
DLIB_TEST
(
p_lab
.
l
==
10
);
DLIB_TEST
(
p_lab
.
a
==
0
);
DLIB_TEST
(
p_lab
.
b
==
0
);
assign_pixel
(
p_gray16
,
12345
);
DLIB_TEST
(
p_gray16
==
12345
);
...
...
@@ -115,6 +126,7 @@ namespace
assign_pixel
(
p_rgb
,
p_rgb
);
assign_pixel
(
p_rgba
,
p_rgb
);
assign_pixel
(
p_hsi
,
p_rgb
);
assign_pixel
(
p_lab
,
p_rgb
);
assign_pixel
(
p_float
,
p_rgb
);
assign_pixel
(
p_int
,
p_rgb
);
...
...
@@ -139,6 +151,10 @@ namespace
DLIB_TEST
(
p_hsi
.
s
>
0
);
DLIB_TEST
(
p_hsi
.
h
>
0
);
DLIB_TEST
(
p_lab
.
l
>
0
);
DLIB_TEST
(
p_lab
.
a
>
0
);
DLIB_TEST
(
p_lab
.
b
>
0
);
assign_pixel
(
p_rgb
,
0
);
DLIB_TEST
(
p_rgb
.
red
==
0
);
DLIB_TEST
(
p_rgb
.
green
==
0
);
...
...
@@ -149,6 +165,16 @@ namespace
DLIB_TEST_MSG
(
p_rgb
.
green
>
96
&&
p_rgb
.
green
<
104
,(
int
)
p_rgb
.
green
);
DLIB_TEST_MSG
(
p_rgb
.
blue
>
47
&&
p_rgb
.
blue
<
53
,(
int
)
p_rgb
.
green
);
assign_pixel
(
p_rgb
,
0
);
DLIB_TEST
(
p_rgb
.
red
==
0
);
DLIB_TEST
(
p_rgb
.
green
==
0
);
DLIB_TEST
(
p_rgb
.
blue
==
0
);
assign_pixel
(
p_rgb
,
p_lab
);
DLIB_TEST_MSG
(
p_rgb
.
red
>
251
,(
int
)
p_rgb
.
green
);
DLIB_TEST_MSG
(
p_rgb
.
green
>
96
&&
p_rgb
.
green
<
104
,(
int
)
p_rgb
.
green
);
DLIB_TEST_MSG
(
p_rgb
.
blue
>
47
&&
p_rgb
.
blue
<
53
,(
int
)
p_rgb
.
green
);
assign_pixel
(
p_hsi2
,
p_hsi
);
DLIB_TEST
(
p_hsi
.
h
==
p_hsi2
.
h
);
DLIB_TEST
(
p_hsi
.
s
==
p_hsi2
.
s
);
...
...
@@ -163,6 +189,20 @@ namespace
DLIB_TEST
(
p_hsi
.
s
==
p_hsi2
.
s
);
DLIB_TEST
(
p_hsi
.
i
==
p_hsi2
.
i
);
assign_pixel
(
p_lab2
,
p_lab
);
DLIB_TEST
(
p_lab
.
l
==
p_lab2
.
l
);
DLIB_TEST
(
p_lab
.
a
==
p_lab2
.
a
);
DLIB_TEST
(
p_lab
.
b
==
p_lab2
.
b
);
assign_pixel
(
p_lab
,
0
);
DLIB_TEST
(
p_lab
.
l
==
0
);
DLIB_TEST
(
p_lab
.
a
==
0
);
DLIB_TEST
(
p_lab
.
b
==
0
);
assign_pixel
(
p_lab
,
p_rgba
);
DLIB_TEST
(
p_lab
.
l
==
p_lab2
.
l
);
DLIB_TEST
(
p_lab
.
a
==
p_lab2
.
a
);
DLIB_TEST
(
p_lab
.
b
==
p_lab2
.
b
);
assign_pixel
(
p_rgba
,
100
);
assign_pixel
(
p_gray
,
10
);
assign_pixel
(
p_rgb
,
10
);
...
...
@@ -192,6 +232,13 @@ namespace
DLIB_TEST
(
p_hsi
.
s
==
0
);
DLIB_TEST_MSG
(
p_hsi
.
i
<
p_hsi2
.
i
+
2
&&
p_hsi
.
i
>
p_hsi2
.
i
-
2
,(
int
)
p_hsi
.
i
<<
" "
<<
(
int
)
p_hsi2
.
i
);
assign_pixel
(
p_lab
,
3
);
assign_pixel
(
p_lab
,
p_rgba
);
assign_pixel
(
p_lab2
,
p_rgb
);
DLIB_TEST
(
p_lab
.
a
==
0
);
DLIB_TEST
(
p_lab
.
b
==
0
);
DLIB_TEST_MSG
(
p_lab
.
l
<
p_lab2
.
l
+
2
&&
p_lab
.
l
>
p_lab2
.
l
-
2
,(
int
)
p_lab
.
l
<<
" "
<<
(
int
)
p_lab2
.
l
);
assign_pixel
(
p_rgba
,
100
);
assign_pixel
(
p_gray
,
10
);
assign_pixel
(
p_schar
,
10
);
...
...
@@ -252,6 +299,10 @@ namespace
p_hsi
.
s
=
10
;
p_hsi
.
i
=
11
;
p_lab
.
l
=
10
;
p_lab
.
a
=
-
9
;
p_lab
.
b
=
8
;
ostringstream
sout
;
serialize
(
p_rgb
,
sout
);
serialize
(
p_rgba
,
sout
);
...
...
@@ -260,6 +311,7 @@ namespace
serialize
(
p_int
,
sout
);
serialize
(
p_float
,
sout
);
serialize
(
p_hsi
,
sout
);
serialize
(
p_lab
,
sout
);
assign_pixel
(
p_rgb
,
0
);
assign_pixel
(
p_rgba
,
0
);
...
...
@@ -268,6 +320,7 @@ namespace
assign_pixel
(
p_int
,
0
);
assign_pixel
(
p_float
,
0
);
assign_pixel
(
p_hsi
,
0
);
assign_pixel
(
p_lab
,
0
);
istringstream
sin
(
sout
.
str
());
...
...
@@ -278,6 +331,7 @@ namespace
deserialize
(
p_int
,
sin
);
deserialize
(
p_float
,
sin
);
deserialize
(
p_hsi
,
sin
);
deserialize
(
p_lab
,
sin
);
DLIB_TEST
(
p_rgb
.
red
==
1
);
DLIB_TEST
(
p_rgb
.
green
==
2
);
...
...
@@ -297,9 +351,13 @@ namespace
DLIB_TEST
(
p_hsi
.
s
==
10
);
DLIB_TEST
(
p_hsi
.
i
==
11
);
DLIB_TEST
(
p_lab
.
l
==
10
);
DLIB_TEST
(
p_lab
.
a
==
-
9
);
DLIB_TEST
(
p_lab
.
b
==
8
);
{
matrix
<
double
,
1
,
1
>
m_gray
,
m_schar
,
m_int
,
m_float
;
matrix
<
double
,
3
,
1
>
m_rgb
,
m_hsi
;
matrix
<
double
,
3
,
1
>
m_rgb
,
m_hsi
,
m_lab
;
m_gray
=
pixel_to_vector
<
double
>
(
p_gray
);
m_schar
=
pixel_to_vector
<
double
>
(
p_schar
);
...
...
@@ -308,6 +366,7 @@ namespace
m_hsi
=
pixel_to_vector
<
double
>
(
p_hsi
);
m_rgb
=
pixel_to_vector
<
double
>
(
p_rgb
);
m_lab
=
pixel_to_vector
<
double
>
(
p_lab
);
DLIB_TEST
(
m_gray
(
0
)
==
p_gray
);
DLIB_TEST
(
m_float
(
0
)
==
p_float
);
...
...
@@ -320,6 +379,9 @@ namespace
DLIB_TEST
(
m_hsi
(
0
)
==
p_hsi
.
h
);
DLIB_TEST
(
m_hsi
(
1
)
==
p_hsi
.
s
);
DLIB_TEST
(
m_hsi
(
2
)
==
p_hsi
.
i
);
DLIB_TEST
(
m_lab
(
0
)
==
p_lab
.
l
);
DLIB_TEST
(
m_lab
(
1
)
==
p_lab
.
a
);
DLIB_TEST
(
m_lab
(
2
)
==
p_lab
.
b
);
DLIB_TEST
(
p_rgb
.
red
==
1
);
DLIB_TEST
(
p_rgb
.
green
==
2
);
...
...
@@ -339,13 +401,19 @@ namespace
DLIB_TEST
(
p_hsi
.
s
==
10
);
DLIB_TEST
(
p_hsi
.
i
==
11
);
DLIB_TEST
(
p_lab
.
l
==
10
);
DLIB_TEST
(
p_lab
.
a
==
-
9
);
DLIB_TEST
(
p_lab
.
b
==
8
);
assign_pixel
(
p_gray
,
0
);
assign_pixel
(
p_hsi
,
0
);
assign_pixel
(
p_rgb
,
0
);
assign_pixel
(
p_lab
,
0
);
vector_to_pixel
(
p_gray
,
m_gray
);
vector_to_pixel
(
p_hsi
,
m_hsi
);
vector_to_pixel
(
p_rgb
,
m_rgb
);
vector_to_pixel
(
p_lab
,
m_lab
);
DLIB_TEST
(
p_rgb
.
red
==
1
);
DLIB_TEST
(
p_rgb
.
green
==
2
);
...
...
@@ -361,6 +429,10 @@ namespace
DLIB_TEST
(
p_hsi
.
h
==
9
);
DLIB_TEST
(
p_hsi
.
s
==
10
);
DLIB_TEST
(
p_hsi
.
i
==
11
);
DLIB_TEST
(
p_lab
.
l
==
10
);
DLIB_TEST
(
p_lab
.
a
==
-
9
);
DLIB_TEST
(
p_lab
.
b
==
8
);
}
...
...
@@ -375,6 +447,7 @@ namespace
rgb_pixel
p_rgb
;
hsi_pixel
p_hsi
,
p_hsi2
;
rgb_alpha_pixel
p_rgba
;
lab_pixel
p_lab
,
p_lab2
;
assign_pixel
(
p_gray
,
0
);
...
...
@@ -384,6 +457,7 @@ namespace
assign_pixel
(
p_schar
,
0
);
assign_pixel
(
p_rgb
,
0
);
assign_pixel
(
p_hsi
,
0
);
assign_pixel
(
p_lab
,
0
);
assign_pixel
(
p_gray
,
100
);
...
...
@@ -457,6 +531,11 @@ namespace
p_hsi
.
i
=
84
;
DLIB_TEST
(
get_pixel_intensity
(
p_hsi
)
==
84
);
p_lab
.
l
=
123
;
p_lab
.
a
=
100
;
p_lab
.
b
=
84
;
DLIB_TEST
(
get_pixel_intensity
(
p_lab
)
==
123
);
p_float
=
54.25
;
DLIB_TEST
(
get_pixel_intensity
(
p_float
)
==
54.25
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment