Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
36a0776a
Commit
36a0776a
authored
Aug 05, 2016
by
Davis King
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'sutr90-lab_pixel'
parents
8c037c3c
83324898
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
674 additions
and
12 deletions
+674
-12
save_png.h
dlib/image_saver/save_png.h
+2
-2
matrix_utilities.h
dlib/matrix/matrix_utilities.h
+34
-2
pixel.h
dlib/pixel.h
+401
-3
pixel.cpp
dlib/test/pixel.cpp
+237
-5
No files found.
dlib/image_saver/save_png.h
View file @
36a0776a
...
@@ -80,9 +80,9 @@ namespace dlib
...
@@ -80,9 +80,9 @@ namespace dlib
impl
::
impl_save_png
(
file_name
,
row_pointers
,
img
.
nc
(),
impl
::
png_type_rgb_alpha
,
8
);
impl
::
impl_save_png
(
file_name
,
row_pointers
,
img
.
nc
(),
impl
::
png_type_rgb_alpha
,
8
);
}
}
else
if
(
pixel_traits
<
pixel_type
>::
hsi
||
pixel_traits
<
pixel_type
>::
rgb
)
else
if
(
pixel_traits
<
pixel_type
>::
lab
||
pixel_traits
<
pixel_type
>::
hsi
||
pixel_traits
<
pixel_type
>::
rgb
)
{
{
// convert from HSI to RGB (Or potentially RGB pixels that aren't laid out as R G B)
// convert from
Lab or
HSI to RGB (Or potentially RGB pixels that aren't laid out as R G B)
array2d
<
rgb_pixel
>
temp_img
;
array2d
<
rgb_pixel
>
temp_img
;
assign_image
(
temp_img
,
img_
);
assign_image
(
temp_img
,
img_
);
for
(
unsigned
long
i
=
0
;
i
<
row_pointers
.
size
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
row_pointers
.
size
();
++
i
)
...
...
dlib/matrix/matrix_utilities.h
View file @
36a0776a
...
@@ -2573,7 +2573,8 @@ namespace dlib
...
@@ -2573,7 +2573,8 @@ namespace dlib
pixel_traits
<
P
>::
grayscale
,
pixel_traits
<
P
>::
grayscale
,
pixel_traits
<
P
>::
rgb
,
pixel_traits
<
P
>::
rgb
,
pixel_traits
<
P
>::
hsi
,
pixel_traits
<
P
>::
hsi
,
pixel_traits
<
P
>::
rgb_alpha
pixel_traits
<
P
>::
rgb_alpha
,
pixel_traits
<
P
>::
lab
>::
value
>::
value
>
>
struct
pixel_to_vector_helper
;
struct
pixel_to_vector_helper
;
...
@@ -2637,6 +2638,21 @@ namespace dlib
...
@@ -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
<
template
<
typename
T
,
typename
T
,
...
@@ -2660,7 +2676,8 @@ namespace dlib
...
@@ -2660,7 +2676,8 @@ namespace dlib
pixel_traits
<
P
>::
grayscale
,
pixel_traits
<
P
>::
grayscale
,
pixel_traits
<
P
>::
rgb
,
pixel_traits
<
P
>::
rgb
,
pixel_traits
<
P
>::
hsi
,
pixel_traits
<
P
>::
hsi
,
pixel_traits
<
P
>::
rgb_alpha
pixel_traits
<
P
>::
rgb_alpha
,
pixel_traits
<
P
>::
lab
>::
value
>::
value
>
>
struct
vector_to_pixel_helper
;
struct
vector_to_pixel_helper
;
...
@@ -2724,6 +2741,21 @@ namespace dlib
...
@@ -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
<
unsigned
char
>
(
m
(
0
));
pixel
.
a
=
static_cast
<
unsigned
char
>
(
m
(
1
));
pixel
.
b
=
static_cast
<
unsigned
char
>
(
m
(
2
));
}
};
template
<
template
<
typename
P
,
typename
P
,
typename
EXP
typename
EXP
...
...
dlib/pixel.h
View file @
36a0776a
...
@@ -36,6 +36,7 @@ namespace dlib
...
@@ -36,6 +36,7 @@ namespace dlib
- bool rgb
- bool rgb
- bool rgb_alpha
- bool rgb_alpha
- bool hsi
- bool hsi
- bool lab
- bool has_alpha
- bool has_alpha
...
@@ -47,7 +48,7 @@ namespace dlib
...
@@ -47,7 +48,7 @@ namespace dlib
- is_unsigned
- is_unsigned
The above public constants are subject to the following constraints:
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
- if (rgb == true) then
- The type T will be a struct with 3 public members of type
- The type T will be a struct with 3 public members of type
unsigned char named "red" "green" and "blue".
unsigned char named "red" "green" and "blue".
...
@@ -81,6 +82,16 @@ namespace dlib
...
@@ -81,6 +82,16 @@ namespace dlib
- min() == 0
- min() == 0
- max() == 255
- max() == 255
- is_unsigned == true
- is_unsigned == true
- else if (lab == true) then
- The type T will be a struct with 3 public members of type
unsigned char named "l" "a" and "b".
- This type of pixel represents the Lab color space.
- num == 3
- has_alpha == false
- basic_pixel_type == unsigned char
- min() == 0
- max() == 255
- is_unsigned == true
- else
- else
- grayscale == true
- grayscale == true
- This type of pixel represents a grayscale color space. T
- This type of pixel represents a grayscale color space. T
...
@@ -190,6 +201,28 @@ namespace dlib
...
@@ -190,6 +201,28 @@ namespace dlib
unsigned
char
s
;
unsigned
char
s
;
unsigned
char
i
;
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
(
unsigned
char
l_
,
unsigned
char
a_
,
unsigned
char
b_
)
:
l
(
l_
),
a
(
a_
),
b
(
b_
)
{}
unsigned
char
l
;
unsigned
char
a
;
unsigned
char
b
;
};
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
@@ -338,6 +371,17 @@ namespace dlib
...
@@ -338,6 +371,17 @@ namespace dlib
provides serialization support for the hsi_pixel struct
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
(
inline
void
deserialize
(
...
@@ -347,6 +391,15 @@ namespace dlib
...
@@ -347,6 +391,15 @@ namespace dlib
/*!
/*!
provides deserialization support for the hsi_pixel struct
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
...
@@ -357,6 +410,7 @@ namespace dlib
const
static
bool
rgb_alpha
=
false
;
const
static
bool
rgb_alpha
=
false
;
const
static
bool
grayscale
=
false
;
const
static
bool
grayscale
=
false
;
const
static
bool
hsi
=
false
;
const
static
bool
hsi
=
false
;
const
static
bool
lab
=
false
;
enum
{
num
=
3
};
enum
{
num
=
3
};
typedef
unsigned
char
basic_pixel_type
;
typedef
unsigned
char
basic_pixel_type
;
static
basic_pixel_type
min
()
{
return
0
;}
static
basic_pixel_type
min
()
{
return
0
;}
...
@@ -374,6 +428,7 @@ namespace dlib
...
@@ -374,6 +428,7 @@ namespace dlib
const
static
bool
rgb_alpha
=
false
;
const
static
bool
rgb_alpha
=
false
;
const
static
bool
grayscale
=
false
;
const
static
bool
grayscale
=
false
;
const
static
bool
hsi
=
false
;
const
static
bool
hsi
=
false
;
const
static
bool
lab
=
false
;
enum
{
num
=
3
};
enum
{
num
=
3
};
typedef
unsigned
char
basic_pixel_type
;
typedef
unsigned
char
basic_pixel_type
;
static
basic_pixel_type
min
()
{
return
0
;}
static
basic_pixel_type
min
()
{
return
0
;}
...
@@ -391,6 +446,7 @@ namespace dlib
...
@@ -391,6 +446,7 @@ namespace dlib
const
static
bool
rgb_alpha
=
true
;
const
static
bool
rgb_alpha
=
true
;
const
static
bool
grayscale
=
false
;
const
static
bool
grayscale
=
false
;
const
static
bool
hsi
=
false
;
const
static
bool
hsi
=
false
;
const
static
bool
lab
=
false
;
enum
{
num
=
4
};
enum
{
num
=
4
};
typedef
unsigned
char
basic_pixel_type
;
typedef
unsigned
char
basic_pixel_type
;
static
basic_pixel_type
min
()
{
return
0
;}
static
basic_pixel_type
min
()
{
return
0
;}
...
@@ -409,6 +465,7 @@ namespace dlib
...
@@ -409,6 +465,7 @@ namespace dlib
const
static
bool
rgb_alpha
=
false
;
const
static
bool
rgb_alpha
=
false
;
const
static
bool
grayscale
=
false
;
const
static
bool
grayscale
=
false
;
const
static
bool
hsi
=
true
;
const
static
bool
hsi
=
true
;
const
static
bool
lab
=
false
;
enum
{
num
=
3
};
enum
{
num
=
3
};
typedef
unsigned
char
basic_pixel_type
;
typedef
unsigned
char
basic_pixel_type
;
static
basic_pixel_type
min
()
{
return
0
;}
static
basic_pixel_type
min
()
{
return
0
;}
...
@@ -417,6 +474,25 @@ namespace dlib
...
@@ -417,6 +474,25 @@ namespace dlib
const
static
bool
has_alpha
=
false
;
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
unsigned
char
basic_pixel_type
;
static
basic_pixel_type
min
()
{
return
0
;}
static
basic_pixel_type
max
()
{
return
255
;}
const
static
bool
is_unsigned
=
true
;
const
static
bool
has_alpha
=
false
;
};
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
template
<
typename
T
>
...
@@ -426,6 +502,7 @@ namespace dlib
...
@@ -426,6 +502,7 @@ namespace dlib
const
static
bool
rgb_alpha
=
false
;
const
static
bool
rgb_alpha
=
false
;
const
static
bool
grayscale
=
true
;
const
static
bool
grayscale
=
true
;
const
static
bool
hsi
=
false
;
const
static
bool
hsi
=
false
;
const
static
bool
lab
=
false
;
enum
{
num
=
1
};
enum
{
num
=
1
};
const
static
bool
has_alpha
=
false
;
const
static
bool
has_alpha
=
false
;
typedef
T
basic_pixel_type
;
typedef
T
basic_pixel_type
;
...
@@ -457,6 +534,7 @@ namespace dlib
...
@@ -457,6 +534,7 @@ namespace dlib
const
static
bool
rgb_alpha
=
false
;
const
static
bool
rgb_alpha
=
false
;
const
static
bool
grayscale
=
true
;
const
static
bool
grayscale
=
true
;
const
static
bool
hsi
=
false
;
const
static
bool
hsi
=
false
;
const
static
bool
lab
=
false
;
enum
{
num
=
1
};
enum
{
num
=
1
};
const
static
bool
has_alpha
=
false
;
const
static
bool
has_alpha
=
false
;
typedef
T
basic_pixel_type
;
typedef
T
basic_pixel_type
;
...
@@ -615,6 +693,15 @@ namespace dlib
...
@@ -615,6 +693,15 @@ namespace dlib
dest
.
i
=
src
.
i
;
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
// dest is a grayscale
...
@@ -673,6 +760,13 @@ namespace dlib
...
@@ -673,6 +760,13 @@ namespace dlib
assign_pixel
(
dest
,
src
.
i
);
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,161 @@ namespace dlib
...
@@ -771,6 +865,161 @@ namespace dlib
return
(
c2
);
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
RGB is between 0.0 and 1.0
*/
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
.
01
93
+
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
.
00
8856
)
{
var_X
=
pow
(
var_X
,
(
1
.
0
/
3
));
}
else
{
var_X
=
(
7
.
787
*
var_X
)
+
(
16
.
0
/
116
);
}
if
(
var_Y
>
0
.
00
8856
)
{
var_Y
=
pow
(
var_Y
,
(
1
.
0
/
3
));
}
else
{
var_Y
=
(
7
.
787
*
var_Y
)
+
(
16
.
0
/
116
);
}
if
(
var_Z
>
0
.
00
8856
)
{
var_Z
=
pow
(
var_Z
,
(
1
.
0
/
3
));
}
else
{
var_Z
=
(
7
.
787
*
var_Z
)
+
(
16
.
0
/
116
);
}
//clamping
c2
.
l
=
max
(
0
.
0
,
(
116
.
0
*
var_Y
)
-
16
);
c2
.
a
=
max
(
-
128
.
0
,
min
(
127
.
0
,
500
.
0
*
(
var_X
-
var_Y
)));
c2
.
b
=
max
(
-
128
.
0
,
min
(
127
.
0
,
200
.
0
*
(
var_Y
-
var_Z
)));
return
c2
;
}
/*
Calculate RGB from Lab, reverse of RGB2LAb()
L is between 0 and 100
a is between -128 and 127
b is between -128 and 127
RGB is between 0.0 and 1.0
*/
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
.
00
8856
)
{
var_Y
=
pow
(
var_Y
,
3
);
}
else
{
var_Y
=
(
var_Y
-
16
.
0
/
116
)
/
7
.
787
;
}
if
(
pow
(
var_X
,
3
)
>
0
.
00
8856
)
{
var_X
=
pow
(
var_X
,
3
);
}
else
{
var_X
=
(
var_X
-
16
.
0
/
116
)
/
7
.
787
;
}
if
(
pow
(
var_Z
,
3
)
>
0
.
00
8856
)
{
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
.
003130
8
)
{
var_R
=
1
.
055
*
pow
(
var_R
,
(
1
/
2
.
4
))
-
0
.
055
;
}
else
{
var_R
=
12
.
92
*
var_R
;
}
if
(
var_G
>
0
.
003130
8
)
{
var_G
=
1
.
055
*
pow
(
var_G
,
(
1
/
2
.
4
))
-
0
.
055
;
}
else
{
var_G
=
12
.
92
*
var_G
;
}
if
(
var_B
>
0
.
003130
8
)
{
var_B
=
1
.
055
*
pow
(
var_B
,
(
1
/
2
.
4
))
-
0
.
055
;
}
else
{
var_B
=
12
.
92
*
var_B
;
}
// clamping
c2
.
r
=
max
(
0
.
0
,
min
(
1
.
0
,
var_R
));
c2
.
g
=
max
(
0
.
0
,
min
(
1
.
0
,
var_G
));
c2
.
b
=
max
(
0
.
0
,
min
(
1
.
0
,
var_B
));
return
(
c2
);
}
// -----------------------------
// -----------------------------
// dest is a color rgb_pixel
// dest is a color rgb_pixel
...
@@ -853,6 +1102,23 @@ namespace dlib
...
@@ -853,6 +1102,23 @@ namespace dlib
dest
.
blue
=
static_cast
<
unsigned
char
>
(
c
.
b
*
255
.
0
+
0
.
5
);
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
/
255
.
0
)
*
100
;
l
.
a
=
(
src
.
a
-
128
.
0
);
l
.
b
=
(
src
.
b
-
128
.
0
);
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
// dest is a color rgb_alpha_pixel
...
@@ -908,6 +1174,22 @@ namespace dlib
...
@@ -908,6 +1174,22 @@ namespace dlib
dest
.
alpha
=
255
;
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
/
255
.
0
)
*
100
;
l
.
a
=
(
src
.
a
-
128
.
0
);
l
.
b
=
(
src
.
b
-
128
.
0
);
c
=
Lab2RGB
(
l
);
dest
.
red
=
static_cast
<
unsigned
char
>
(
c
.
r
*
255
+
0
.
5
);
dest
.
green
=
static_cast
<
unsigned
char
>
(
c
.
g
*
255
+
0
.
5
);
dest
.
blue
=
static_cast
<
unsigned
char
>
(
c
.
b
*
255
+
0
.
5
);
dest
.
alpha
=
255
;
}
// -----------------------------
// -----------------------------
// dest is an hsi pixel
// dest is an hsi pixel
...
@@ -962,6 +1244,84 @@ namespace dlib
...
@@ -962,6 +1244,84 @@ namespace dlib
assign_pixel_helpers
::
assign
(
dest
,
temp
);
assign_pixel_helpers
::
assign
(
dest
,
temp
);
}
}
template
<
typename
P1
,
typename
P2
>
typename
enable_if_c
<
pixel_traits
<
P1
>::
hsi
&&
pixel_traits
<
P2
>::
lab
>::
type
assign
(
P1
&
dest
,
const
P2
&
src
)
{
rgb_pixel
temp
;
// convert lab 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
);
}
// -----------------------------
// 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
=
128
;
dest
.
b
=
128
;
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
=
128
;
dest
.
b
=
128
;
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
<
unsigned
char
>
((
c2
.
l
/
100
)
*
255
+
0
.
5
);
dest
.
a
=
static_cast
<
unsigned
char
>
(
c2
.
a
+
128
+
0
.
5
);
dest
.
b
=
static_cast
<
unsigned
char
>
(
c2
.
b
+
128
+
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
// lab pixel
assign_pixel_helpers
::
assign
(
dest
,
temp
);
}
template
<
typename
P1
,
typename
P2
>
typename
enable_if_c
<
pixel_traits
<
P1
>::
lab
&&
pixel_traits
<
P2
>::
hsi
>::
type
assign
(
P1
&
dest
,
const
P2
&
src
)
{
rgb_pixel
temp
;
// convert hsi value to our temp rgb pixel
assign_pixel_helpers
::
assign
(
temp
,
src
);
// now we can just go assign the new rgb value to the
// lab pixel
assign_pixel_helpers
::
assign
(
dest
,
temp
);
}
}
}
// -----------------------------
// -----------------------------
...
@@ -990,7 +1350,7 @@ namespace dlib
...
@@ -990,7 +1350,7 @@ namespace dlib
typename
P
,
typename
P
,
typename
T
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
(
pixel_traits
<
P
>::
has_alpha
>::
type
assign_pixel_intensity_helper
(
P
&
dest
,
P
&
dest
,
const
T
&
new_intensity
const
T
&
new_intensity
...
@@ -1011,7 +1371,7 @@ namespace dlib
...
@@ -1011,7 +1371,7 @@ namespace dlib
typename
P
,
typename
P
,
typename
T
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
(
pixel_traits
<
P
>::
has_alpha
==
false
>::
type
assign_pixel_intensity_helper
(
P
&
dest
,
P
&
dest
,
const
T
&
new_intensity
const
T
&
new_intensity
...
@@ -1243,6 +1603,44 @@ namespace dlib
...
@@ -1243,6 +1603,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 @
36a0776a
...
@@ -36,9 +36,10 @@ namespace
...
@@ -36,9 +36,10 @@ namespace
long
p_int
;
long
p_int
;
float
p_float
;
float
p_float
;
signed
char
p_schar
;
signed
char
p_schar
;
rgb_pixel
p_rgb
;
rgb_pixel
p_rgb
,
p_rgb2
;
hsi_pixel
p_hsi
,
p_hsi2
;
hsi_pixel
p_hsi
,
p_hsi2
;
rgb_alpha_pixel
p_rgba
;
rgb_alpha_pixel
p_rgba
;
lab_pixel
p_lab
,
p_lab2
;
assign_pixel
(
p_int
,
0.0
f
);
assign_pixel
(
p_int
,
0.0
f
);
assign_pixel
(
p_float
,
0.0
f
);
assign_pixel
(
p_float
,
0.0
f
);
...
@@ -49,6 +50,7 @@ namespace
...
@@ -49,6 +50,7 @@ namespace
assign_pixel
(
p_hsi
,
-
4
);
assign_pixel
(
p_hsi
,
-
4
);
assign_pixel
(
p_rgba
,
p_int
);
assign_pixel
(
p_rgba
,
p_int
);
assign_pixel
(
p_gray16
,
0
);
assign_pixel
(
p_gray16
,
0
);
assign_pixel
(
p_lab
,
-
400
);
DLIB_TEST
(
p_int
==
0
);
DLIB_TEST
(
p_int
==
0
);
DLIB_TEST
(
p_float
==
0
);
DLIB_TEST
(
p_float
==
0
);
...
@@ -70,11 +72,16 @@ namespace
...
@@ -70,11 +72,16 @@ namespace
DLIB_TEST
(
p_hsi
.
s
==
0
);
DLIB_TEST
(
p_hsi
.
s
==
0
);
DLIB_TEST
(
p_hsi
.
i
==
0
);
DLIB_TEST
(
p_hsi
.
i
==
0
);
DLIB_TEST
(
p_lab
.
l
==
0
);
DLIB_TEST
(
p_lab
.
a
==
128
);
DLIB_TEST
(
p_lab
.
b
==
128
);
assign_pixel
(
p_gray
,
10
);
assign_pixel
(
p_gray
,
10
);
assign_pixel
(
p_gray16
,
10
);
assign_pixel
(
p_gray16
,
10
);
assign_pixel
(
p_rgb
,
10
);
assign_pixel
(
p_rgb
,
10
);
assign_pixel
(
p_hsi
,
10
);
assign_pixel
(
p_hsi
,
10
);
assign_pixel
(
p_rgba
,
10
);
assign_pixel
(
p_rgba
,
10
);
assign_pixel
(
p_lab
,
10
);
assign_pixel
(
p_int
,
-
10
);
assign_pixel
(
p_int
,
-
10
);
assign_pixel
(
p_float
,
-
10
);
assign_pixel
(
p_float
,
-
10
);
...
@@ -100,6 +107,10 @@ namespace
...
@@ -100,6 +107,10 @@ namespace
DLIB_TEST
(
p_hsi
.
s
==
0
);
DLIB_TEST
(
p_hsi
.
s
==
0
);
DLIB_TEST
(
p_hsi
.
i
==
10
);
DLIB_TEST
(
p_hsi
.
i
==
10
);
DLIB_TEST
(
p_lab
.
l
==
10
);
DLIB_TEST
(
p_lab
.
a
==
128
);
DLIB_TEST
(
p_lab
.
b
==
128
);
assign_pixel
(
p_gray16
,
12345
);
assign_pixel
(
p_gray16
,
12345
);
DLIB_TEST
(
p_gray16
==
12345
);
DLIB_TEST
(
p_gray16
==
12345
);
...
@@ -115,6 +126,7 @@ namespace
...
@@ -115,6 +126,7 @@ namespace
assign_pixel
(
p_rgb
,
p_rgb
);
assign_pixel
(
p_rgb
,
p_rgb
);
assign_pixel
(
p_rgba
,
p_rgb
);
assign_pixel
(
p_rgba
,
p_rgb
);
assign_pixel
(
p_hsi
,
p_rgb
);
assign_pixel
(
p_hsi
,
p_rgb
);
assign_pixel
(
p_lab
,
p_rgb
);
assign_pixel
(
p_float
,
p_rgb
);
assign_pixel
(
p_float
,
p_rgb
);
assign_pixel
(
p_int
,
p_rgb
);
assign_pixel
(
p_int
,
p_rgb
);
...
@@ -139,6 +151,10 @@ namespace
...
@@ -139,6 +151,10 @@ namespace
DLIB_TEST
(
p_hsi
.
s
>
0
);
DLIB_TEST
(
p_hsi
.
s
>
0
);
DLIB_TEST
(
p_hsi
.
h
>
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
);
assign_pixel
(
p_rgb
,
0
);
DLIB_TEST
(
p_rgb
.
red
==
0
);
DLIB_TEST
(
p_rgb
.
red
==
0
);
DLIB_TEST
(
p_rgb
.
green
==
0
);
DLIB_TEST
(
p_rgb
.
green
==
0
);
...
@@ -149,6 +165,16 @@ namespace
...
@@ -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
.
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
);
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
);
assign_pixel
(
p_hsi2
,
p_hsi
);
DLIB_TEST
(
p_hsi
.
h
==
p_hsi2
.
h
);
DLIB_TEST
(
p_hsi
.
h
==
p_hsi2
.
h
);
DLIB_TEST
(
p_hsi
.
s
==
p_hsi2
.
s
);
DLIB_TEST
(
p_hsi
.
s
==
p_hsi2
.
s
);
...
@@ -163,6 +189,20 @@ namespace
...
@@ -163,6 +189,20 @@ namespace
DLIB_TEST
(
p_hsi
.
s
==
p_hsi2
.
s
);
DLIB_TEST
(
p_hsi
.
s
==
p_hsi2
.
s
);
DLIB_TEST
(
p_hsi
.
i
==
p_hsi2
.
i
);
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
==
128
);
DLIB_TEST
(
p_lab
.
b
==
128
);
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_rgba
,
100
);
assign_pixel
(
p_gray
,
10
);
assign_pixel
(
p_gray
,
10
);
assign_pixel
(
p_rgb
,
10
);
assign_pixel
(
p_rgb
,
10
);
...
@@ -192,6 +232,169 @@ namespace
...
@@ -192,6 +232,169 @@ namespace
DLIB_TEST
(
p_hsi
.
s
==
0
);
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
);
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
);
// this value corresponds to RGB(10,10,10)
p_lab
.
l
=
7
;
p_lab
.
a
=
128
;
p_lab
.
b
=
128
;
assign_pixel
(
p_lab
,
p_rgba
);
assign_pixel
(
p_lab2
,
p_rgb
);
DLIB_TEST
(
p_lab
.
a
==
128
);
DLIB_TEST
(
p_lab
.
b
==
128
);
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_lab
,
128
);
DLIB_TEST
(
p_lab
.
l
==
128
);
DLIB_TEST
(
p_lab
.
a
==
128
);
DLIB_TEST
(
p_lab
.
b
==
128
);
assign_pixel
(
p_rgb
,
p_lab
);
//Lab midpoint (50,0,0) is not same as RGB midpoint (127,127,127)
DLIB_TEST
(
p_rgb
.
red
==
119
);
DLIB_TEST
(
p_rgb
.
green
==
119
);
DLIB_TEST
(
p_rgb
.
blue
==
119
);
//Lab limit values test
//red, green, blue, yellow, black, white
p_lab
.
l
=
84
;
p_lab
.
a
=
164
;
p_lab
.
b
=
56
;
assign_pixel
(
p_rgb
,
p_lab
);
DLIB_TEST
(
p_rgb
.
red
==
0
);
DLIB_TEST
(
p_rgb
.
green
==
64
);
DLIB_TEST
(
p_rgb
.
blue
==
194
);
p_lab
.
l
=
255
;
p_lab
.
a
=
0
;
p_lab
.
b
=
0
;
assign_pixel
(
p_rgb
,
p_lab
);
DLIB_TEST
(
p_rgb
.
red
==
0
);
DLIB_TEST
(
p_rgb
.
green
==
255
);
DLIB_TEST
(
p_rgb
.
blue
==
255
);
p_lab
.
l
=
0
;
p_lab
.
a
=
255
;
p_lab
.
b
=
0
;
assign_pixel
(
p_rgb
,
p_lab
);
DLIB_TEST
(
p_rgb
.
red
==
0
);
DLIB_TEST
(
p_rgb
.
green
==
0
);
DLIB_TEST
(
p_rgb
.
blue
==
195
);
p_lab
.
l
=
0
;
p_lab
.
a
=
0
;
p_lab
.
b
=
255
;
assign_pixel
(
p_rgb
,
p_lab
);
DLIB_TEST
(
p_rgb
.
red
==
0
);
DLIB_TEST
(
p_rgb
.
green
==
45
);
DLIB_TEST
(
p_rgb
.
blue
==
0
);
p_lab
.
l
=
255
;
p_lab
.
a
=
255
;
p_lab
.
b
=
0
;
assign_pixel
(
p_rgb
,
p_lab
);
DLIB_TEST
(
p_rgb
.
red
==
255
);
DLIB_TEST
(
p_rgb
.
green
==
139
);
DLIB_TEST
(
p_rgb
.
blue
==
255
);
p_lab
.
l
=
0
;
p_lab
.
a
=
255
;
p_lab
.
b
=
255
;
assign_pixel
(
p_rgb
,
p_lab
);
DLIB_TEST
(
p_rgb
.
red
==
132
);
DLIB_TEST
(
p_rgb
.
green
==
0
);
DLIB_TEST
(
p_rgb
.
blue
==
0
);
p_lab
.
l
=
255
;
p_lab
.
a
=
0
;
p_lab
.
b
=
255
;
assign_pixel
(
p_rgb
,
p_lab
);
DLIB_TEST
(
p_rgb
.
red
==
0
);
DLIB_TEST
(
p_rgb
.
green
==
255
);
DLIB_TEST
(
p_rgb
.
blue
==
0
);
p_lab
.
l
=
255
;
p_lab
.
a
=
255
;
p_lab
.
b
=
255
;
assign_pixel
(
p_rgb
,
p_lab
);
DLIB_TEST
(
p_rgb
.
red
==
255
);
DLIB_TEST
(
p_rgb
.
green
==
70
);
DLIB_TEST
(
p_rgb
.
blue
==
0
);
//RGB limit tests
p_rgb
.
red
=
0
;
p_rgb
.
green
=
0
;
p_rgb
.
blue
=
0
;
assign_pixel
(
p_lab
,
p_rgb
);
assign_pixel
(
p_rgb2
,
p_lab
);
DLIB_TEST
(
p_rgb2
.
red
<
3
);
DLIB_TEST
(
p_rgb2
.
green
<
3
);
DLIB_TEST
(
p_rgb2
.
blue
<
3
);
p_rgb
.
red
=
255
;
p_rgb
.
green
=
0
;
p_rgb
.
blue
=
0
;
assign_pixel
(
p_lab
,
p_rgb
);
assign_pixel
(
p_rgb2
,
p_lab
);
DLIB_TEST
(
p_rgb2
.
red
>
252
);
DLIB_TEST
(
p_rgb2
.
green
<
3
);
DLIB_TEST
(
p_rgb2
.
blue
<
3
);
p_rgb
.
red
=
0
;
p_rgb
.
green
=
255
;
p_rgb
.
blue
=
0
;
assign_pixel
(
p_lab
,
p_rgb
);
assign_pixel
(
p_rgb2
,
p_lab
);
DLIB_TEST
(
p_rgb2
.
red
<
8
);
DLIB_TEST
(
p_rgb2
.
green
>
252
);
DLIB_TEST
(
p_rgb2
.
blue
<
5
);
p_rgb
.
red
=
0
;
p_rgb
.
green
=
0
;
p_rgb
.
blue
=
255
;
assign_pixel
(
p_lab
,
p_rgb
);
assign_pixel
(
p_rgb2
,
p_lab
);
DLIB_TEST
(
p_rgb2
.
red
<
3
);
DLIB_TEST
(
p_rgb2
.
green
<
3
);
DLIB_TEST
(
p_rgb2
.
blue
>
252
);
p_rgb
.
red
=
255
;
p_rgb
.
green
=
255
;
p_rgb
.
blue
=
0
;
assign_pixel
(
p_lab
,
p_rgb
);
assign_pixel
(
p_rgb2
,
p_lab
);
DLIB_TEST
(
p_rgb2
.
red
>
252
);
DLIB_TEST
(
p_rgb2
.
green
>
252
);
DLIB_TEST
(
p_rgb2
.
blue
<
9
);
p_rgb
.
red
=
0
;
p_rgb
.
green
=
255
;
p_rgb
.
blue
=
255
;
assign_pixel
(
p_lab
,
p_rgb
);
assign_pixel
(
p_rgb2
,
p_lab
);
DLIB_TEST
(
p_rgb2
.
red
<
5
);
DLIB_TEST
(
p_rgb2
.
green
>
252
);
DLIB_TEST
(
p_rgb2
.
blue
>
252
);
p_rgb
.
red
=
255
;
p_rgb
.
green
=
0
;
p_rgb
.
blue
=
255
;
assign_pixel
(
p_lab
,
p_rgb
);
assign_pixel
(
p_rgb2
,
p_lab
);
DLIB_TEST
(
p_rgb2
.
red
>
252
);
DLIB_TEST
(
p_rgb2
.
green
<
6
);
DLIB_TEST
(
p_rgb2
.
blue
>
252
);
p_rgb
.
red
=
255
;
p_rgb
.
green
=
255
;
p_rgb
.
blue
=
255
;
assign_pixel
(
p_lab
,
p_rgb
);
assign_pixel
(
p_rgb2
,
p_lab
);
DLIB_TEST
(
p_rgb2
.
red
>
252
);
DLIB_TEST
(
p_rgb2
.
green
>
252
);
DLIB_TEST
(
p_rgb2
.
blue
>
252
);
assign_pixel
(
p_rgba
,
100
);
assign_pixel
(
p_rgba
,
100
);
assign_pixel
(
p_gray
,
10
);
assign_pixel
(
p_gray
,
10
);
assign_pixel
(
p_schar
,
10
);
assign_pixel
(
p_schar
,
10
);
...
@@ -252,6 +455,10 @@ namespace
...
@@ -252,6 +455,10 @@ namespace
p_hsi
.
s
=
10
;
p_hsi
.
s
=
10
;
p_hsi
.
i
=
11
;
p_hsi
.
i
=
11
;
p_lab
.
l
=
10
;
p_lab
.
a
=
9
;
p_lab
.
b
=
8
;
ostringstream
sout
;
ostringstream
sout
;
serialize
(
p_rgb
,
sout
);
serialize
(
p_rgb
,
sout
);
serialize
(
p_rgba
,
sout
);
serialize
(
p_rgba
,
sout
);
...
@@ -260,6 +467,7 @@ namespace
...
@@ -260,6 +467,7 @@ namespace
serialize
(
p_int
,
sout
);
serialize
(
p_int
,
sout
);
serialize
(
p_float
,
sout
);
serialize
(
p_float
,
sout
);
serialize
(
p_hsi
,
sout
);
serialize
(
p_hsi
,
sout
);
serialize
(
p_lab
,
sout
);
assign_pixel
(
p_rgb
,
0
);
assign_pixel
(
p_rgb
,
0
);
assign_pixel
(
p_rgba
,
0
);
assign_pixel
(
p_rgba
,
0
);
...
@@ -268,6 +476,7 @@ namespace
...
@@ -268,6 +476,7 @@ namespace
assign_pixel
(
p_int
,
0
);
assign_pixel
(
p_int
,
0
);
assign_pixel
(
p_float
,
0
);
assign_pixel
(
p_float
,
0
);
assign_pixel
(
p_hsi
,
0
);
assign_pixel
(
p_hsi
,
0
);
assign_pixel
(
p_lab
,
0
);
istringstream
sin
(
sout
.
str
());
istringstream
sin
(
sout
.
str
());
...
@@ -278,6 +487,7 @@ namespace
...
@@ -278,6 +487,7 @@ namespace
deserialize
(
p_int
,
sin
);
deserialize
(
p_int
,
sin
);
deserialize
(
p_float
,
sin
);
deserialize
(
p_float
,
sin
);
deserialize
(
p_hsi
,
sin
);
deserialize
(
p_hsi
,
sin
);
deserialize
(
p_lab
,
sin
);
DLIB_TEST
(
p_rgb
.
red
==
1
);
DLIB_TEST
(
p_rgb
.
red
==
1
);
DLIB_TEST
(
p_rgb
.
green
==
2
);
DLIB_TEST
(
p_rgb
.
green
==
2
);
...
@@ -297,9 +507,13 @@ namespace
...
@@ -297,9 +507,13 @@ namespace
DLIB_TEST
(
p_hsi
.
s
==
10
);
DLIB_TEST
(
p_hsi
.
s
==
10
);
DLIB_TEST
(
p_hsi
.
i
==
11
);
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
,
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_gray
=
pixel_to_vector
<
double
>
(
p_gray
);
m_schar
=
pixel_to_vector
<
double
>
(
p_schar
);
m_schar
=
pixel_to_vector
<
double
>
(
p_schar
);
...
@@ -308,6 +522,7 @@ namespace
...
@@ -308,6 +522,7 @@ namespace
m_hsi
=
pixel_to_vector
<
double
>
(
p_hsi
);
m_hsi
=
pixel_to_vector
<
double
>
(
p_hsi
);
m_rgb
=
pixel_to_vector
<
double
>
(
p_rgb
);
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_gray
(
0
)
==
p_gray
);
DLIB_TEST
(
m_float
(
0
)
==
p_float
);
DLIB_TEST
(
m_float
(
0
)
==
p_float
);
...
@@ -320,6 +535,9 @@ namespace
...
@@ -320,6 +535,9 @@ namespace
DLIB_TEST
(
m_hsi
(
0
)
==
p_hsi
.
h
);
DLIB_TEST
(
m_hsi
(
0
)
==
p_hsi
.
h
);
DLIB_TEST
(
m_hsi
(
1
)
==
p_hsi
.
s
);
DLIB_TEST
(
m_hsi
(
1
)
==
p_hsi
.
s
);
DLIB_TEST
(
m_hsi
(
2
)
==
p_hsi
.
i
);
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
.
red
==
1
);
DLIB_TEST
(
p_rgb
.
green
==
2
);
DLIB_TEST
(
p_rgb
.
green
==
2
);
...
@@ -339,13 +557,19 @@ namespace
...
@@ -339,13 +557,19 @@ namespace
DLIB_TEST
(
p_hsi
.
s
==
10
);
DLIB_TEST
(
p_hsi
.
s
==
10
);
DLIB_TEST
(
p_hsi
.
i
==
11
);
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_gray
,
0
);
assign_pixel
(
p_hsi
,
0
);
assign_pixel
(
p_hsi
,
0
);
assign_pixel
(
p_rgb
,
0
);
assign_pixel
(
p_rgb
,
0
);
assign_pixel
(
p_lab
,
0
);
vector_to_pixel
(
p_gray
,
m_gray
);
vector_to_pixel
(
p_gray
,
m_gray
);
vector_to_pixel
(
p_hsi
,
m_hsi
);
vector_to_pixel
(
p_hsi
,
m_hsi
);
vector_to_pixel
(
p_rgb
,
m_rgb
);
vector_to_pixel
(
p_rgb
,
m_rgb
);
vector_to_pixel
(
p_lab
,
m_lab
);
DLIB_TEST
(
p_rgb
.
red
==
1
);
DLIB_TEST
(
p_rgb
.
red
==
1
);
DLIB_TEST
(
p_rgb
.
green
==
2
);
DLIB_TEST
(
p_rgb
.
green
==
2
);
...
@@ -361,6 +585,10 @@ namespace
...
@@ -361,6 +585,10 @@ namespace
DLIB_TEST
(
p_hsi
.
h
==
9
);
DLIB_TEST
(
p_hsi
.
h
==
9
);
DLIB_TEST
(
p_hsi
.
s
==
10
);
DLIB_TEST
(
p_hsi
.
s
==
10
);
DLIB_TEST
(
p_hsi
.
i
==
11
);
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 +603,7 @@ namespace
...
@@ -375,6 +603,7 @@ namespace
rgb_pixel
p_rgb
;
rgb_pixel
p_rgb
;
hsi_pixel
p_hsi
,
p_hsi2
;
hsi_pixel
p_hsi
,
p_hsi2
;
rgb_alpha_pixel
p_rgba
;
rgb_alpha_pixel
p_rgba
;
lab_pixel
p_lab
;
assign_pixel
(
p_gray
,
0
);
assign_pixel
(
p_gray
,
0
);
...
@@ -384,6 +613,7 @@ namespace
...
@@ -384,6 +613,7 @@ namespace
assign_pixel
(
p_schar
,
0
);
assign_pixel
(
p_schar
,
0
);
assign_pixel
(
p_rgb
,
0
);
assign_pixel
(
p_rgb
,
0
);
assign_pixel
(
p_hsi
,
0
);
assign_pixel
(
p_hsi
,
0
);
assign_pixel
(
p_lab
,
0
);
assign_pixel
(
p_gray
,
100
);
assign_pixel
(
p_gray
,
100
);
...
@@ -457,6 +687,11 @@ namespace
...
@@ -457,6 +687,11 @@ namespace
p_hsi
.
i
=
84
;
p_hsi
.
i
=
84
;
DLIB_TEST
(
get_pixel_intensity
(
p_hsi
)
==
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
;
p_float
=
54.25
;
DLIB_TEST
(
get_pixel_intensity
(
p_float
)
==
54.25
);
DLIB_TEST
(
get_pixel_intensity
(
p_float
)
==
54.25
);
...
@@ -540,6 +775,3 @@ namespace
...
@@ -540,6 +775,3 @@ namespace
}
a
;
}
a
;
}
}
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