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
69d5aef2
Commit
69d5aef2
authored
Mar 18, 2016
by
Davis King
Browse files
Options
Browse Files
Download
Plain Diff
merged
parents
d748529a
09893704
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
1 deletion
+97
-1
random_color_transform.h
dlib/image_transforms/random_color_transform.h
+57
-0
random_color_transform_abstract.h
dlib/image_transforms/random_color_transform_abstract.h
+18
-1
rand_kernel_1.h
dlib/rand/rand_kernel_1.h
+9
-0
rand_kernel_abstract.h
dlib/rand/rand_kernel_abstract.h
+13
-0
No files found.
dlib/image_transforms/random_color_transform.h
View file @
69d5aef2
...
@@ -92,6 +92,63 @@ namespace dlib
...
@@ -92,6 +92,63 @@ namespace dlib
}
}
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
image_type
>
void
apply_random_color_offset
(
image_type
&
img_
,
dlib
::
rand
&
rnd
)
{
// Make a random color offset. This tform matrix came from looking at the
// covariance matrix of RGB values in a bunch of images. In particular, if you
// multiply Gaussian random vectors by tform it will result in vectors with the
// same covariance matrix as the original RGB data. Also, this color transform is
// what is suggested by the paper:
// Krizhevsky, Alex, Ilya Sutskever, and Geoffrey E. Hinton. "Imagenet
// classification with deep convolutional neural networks." Advances in neural
// information processing systems. 2012.
// Except that we used the square root of the eigenvalues (which I'm pretty sure is
// what the authors intended).
matrix
<
double
,
3
,
3
>
tform
;
tform
=
-
66
.
379
,
25
.
094
,
6
.
79698
,
-
68
.
04
92
,
-
0
.
302309
,
-
13
.
9539
,
-
68
.
4907
,
-
24
.
01
99
,
7
.
27653
;
matrix
<
double
,
3
,
1
>
v
;
v
=
rnd
.
get_random_gaussian
(),
rnd
.
get_random_gaussian
(),
rnd
.
get_random_gaussian
();
v
=
round
(
tform
*
0
.
1
*
v
);
const
int
roffset
=
v
(
0
);
const
int
goffset
=
v
(
1
);
const
int
boffset
=
v
(
2
);
// Make up lookup tables that apply the color mapping so we don't have to put a
// bunch of complicated conditional branches in the loop below.
unsigned
char
rtable
[
256
];
unsigned
char
gtable
[
256
];
unsigned
char
btable
[
256
];
for
(
int
i
=
0
;
i
<
256
;
++
i
)
{
rtable
[
i
]
=
put_in_range
(
0
,
255
,
i
+
roffset
);
gtable
[
i
]
=
put_in_range
(
0
,
255
,
i
+
goffset
);
btable
[
i
]
=
put_in_range
(
0
,
255
,
i
+
boffset
);
}
// now transform the image.
image_view
<
image_type
>
img
(
img_
);
for
(
long
r
=
0
;
r
<
img
.
nr
();
++
r
)
{
for
(
long
c
=
0
;
c
<
img
.
nc
();
++
c
)
{
rgb_pixel
temp
;
assign_pixel
(
temp
,
img
[
r
][
c
]);
temp
.
red
=
rtable
[
temp
.
red
];
temp
.
green
=
rtable
[
temp
.
green
];
temp
.
blue
=
rtable
[
temp
.
blue
];
assign_pixel
(
img
[
r
][
c
],
temp
);
}
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
}
}
...
...
dlib/image_transforms/random_color_transform_abstract.h
View file @
69d5aef2
...
@@ -71,7 +71,24 @@ namespace dlib
...
@@ -71,7 +71,24 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
}
template
<
typename
image_type
>
void
apply_random_color_offset
(
image_type
&
img
,
dlib
::
rand
&
rnd
);
/*!
ensures
- Picks a random color offset vector and adds it to the given image. The offset
vector is selected using the method described in the paper:
Krizhevsky, Alex, Ilya Sutskever, and Geoffrey E. Hinton. "Imagenet
classification with deep convolutional neural networks." Advances in neural
information processing systems. 2012.
In particular, we sample an RGB value from the typical distribution of RGB
values, assuming it has a Gaussian distribution, and then divide it by 10.
This sampled RGB vector is added to each pixel of img.
!*/
// ----------------------------------------------------------------------------------------
#endif // DLIB_RANDOM_cOLOR_TRANSFORM_ABSTRACT_Hh_
#endif // DLIB_RANDOM_cOLOR_TRANSFORM_ABSTRACT_Hh_
dlib/rand/rand_kernel_1.h
View file @
69d5aef2
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#include "../is_kind.h"
#include "../is_kind.h"
#include <iostream>
#include <iostream>
#include "../serialize.h"
#include "../serialize.h"
#include "../string.h"
namespace
dlib
namespace
dlib
{
{
...
@@ -39,6 +40,14 @@ namespace dlib
...
@@ -39,6 +40,14 @@ namespace dlib
init
();
init
();
}
}
rand
(
time_t
seed_value
)
{
init
();
set_seed
(
cast_to_string
(
seed_value
));
}
rand
(
rand
(
const
std
::
string
&
seed_value
const
std
::
string
&
seed_value
)
)
...
...
dlib/rand/rand_kernel_abstract.h
View file @
69d5aef2
...
@@ -34,6 +34,19 @@ namespace dlib
...
@@ -34,6 +34,19 @@ namespace dlib
- std::bad_alloc
- std::bad_alloc
!*/
!*/
rand
(
time_t
seed_value
);
/*!
ensures
- #*this is properly initialized
- #get_seed() == cast_to_string(seed_value)
- This version of the constructor is equivalent to using
the default constructor and then calling set_seed(cast_to_string(seed_value))
throws
- std::bad_alloc
!*/
rand
(
rand
(
const
std
::
string
&
seed_value
const
std
::
string
&
seed_value
);
);
...
...
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