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
a969e1f9
Commit
a969e1f9
authored
Mar 22, 2015
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made the jet and heat colormaps more accessible to other routines.
parent
ac4666cb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
105 additions
and
63 deletions
+105
-63
colormaps.h
dlib/image_transforms/colormaps.h
+76
-54
colormaps_abstract.h
dlib/image_transforms/colormaps_abstract.h
+29
-9
No files found.
dlib/image_transforms/colormaps.h
View file @
a969e1f9
...
@@ -63,6 +63,32 @@ namespace dlib
...
@@ -63,6 +63,32 @@ namespace dlib
return
matrix_op
<
op
>
(
op
(
img
));
return
matrix_op
<
op
>
(
op
(
img
));
}
}
// ----------------------------------------------------------------------------------------
inline
rgb_pixel
colormap_heat
(
double
value
,
double
min_val
,
double
max_val
)
{
// scale the gray value into the range [0, 1]
const
double
gray
=
put_in_range
(
0
,
1
,
(
value
-
min_val
)
/
(
max_val
-
min_val
));
rgb_pixel
pix
(
0
,
0
,
0
);
pix
.
red
=
static_cast
<
unsigned
char
>
(
std
::
min
(
gray
/
0
.
4
,
1
.
0
)
*
255
+
0
.
5
);
if
(
gray
>
0
.
4
)
{
pix
.
green
=
static_cast
<
unsigned
char
>
(
std
::
min
((
gray
-
0
.
4
)
/
0
.
4
,
1
.
0
)
*
255
+
0
.
5
);
}
if
(
gray
>
0
.
8
)
{
pix
.
blue
=
static_cast
<
unsigned
char
>
(
std
::
min
((
gray
-
0
.
8
)
/
0
.
2
,
1
.
0
)
*
255
+
0
.
5
);
}
return
pix
;
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
template
<
typename
T
>
...
@@ -89,22 +115,7 @@ namespace dlib
...
@@ -89,22 +115,7 @@ namespace dlib
const_ret_type
apply
(
long
r
,
long
c
)
const
const_ret_type
apply
(
long
r
,
long
c
)
const
{
{
// scale the gray value into the range [0, 1]
return
colormap_heat
(
get_pixel_intensity
(
mat
(
img
)(
r
,
c
)),
min_val
,
max_val
);
const
double
gray
=
put_in_range
(
0
,
1
,
(
get_pixel_intensity
(
mat
(
img
)(
r
,
c
))
-
min_val
)
/
(
max_val
-
min_val
));
rgb_pixel
pix
(
0
,
0
,
0
);
pix
.
red
=
static_cast
<
unsigned
char
>
(
std
::
min
(
gray
/
0
.
4
,
1
.
0
)
*
255
+
0
.
5
);
if
(
gray
>
0
.
4
)
{
pix
.
green
=
static_cast
<
unsigned
char
>
(
std
::
min
((
gray
-
0
.
4
)
/
0
.
4
,
1
.
0
)
*
255
+
0
.
5
);
}
if
(
gray
>
0
.
8
)
{
pix
.
blue
=
static_cast
<
unsigned
char
>
(
std
::
min
((
gray
-
0
.
8
)
/
0
.
2
,
1
.
0
)
*
255
+
0
.
5
);
}
return
pix
;
}
}
long
nr
()
const
{
return
num_rows
(
img
);
}
long
nr
()
const
{
return
num_rows
(
img
);
}
...
@@ -137,6 +148,54 @@ namespace dlib
...
@@ -137,6 +148,54 @@ namespace dlib
return
matrix_op
<
op
>
(
op
(
img
,
max
(
mat
(
img
)),
min
(
mat
(
img
))));
return
matrix_op
<
op
>
(
op
(
img
,
max
(
mat
(
img
)),
min
(
mat
(
img
))));
}
}
// ----------------------------------------------------------------------------------------
inline
rgb_pixel
colormap_jet
(
double
value
,
double
min_val
,
double
max_val
)
{
// scale the gray value into the range [0, 8]
const
double
gray
=
8
*
put_in_range
(
0
,
1
,
(
value
-
min_val
)
/
(
max_val
-
min_val
));
rgb_pixel
pix
;
// s is the slope of color change
const
double
s
=
1
.
0
/
2
.
0
;
if
(
gray
<=
1
)
{
pix
.
red
=
0
;
pix
.
green
=
0
;
pix
.
blue
=
static_cast
<
unsigned
char
>
((
gray
+
1
)
*
s
*
255
+
0
.
5
);
}
else
if
(
gray
<=
3
)
{
pix
.
red
=
0
;
pix
.
green
=
static_cast
<
unsigned
char
>
((
gray
-
1
)
*
s
*
255
+
0
.
5
);
pix
.
blue
=
255
;
}
else
if
(
gray
<=
5
)
{
pix
.
red
=
static_cast
<
unsigned
char
>
((
gray
-
3
)
*
s
*
255
+
0
.
5
);
pix
.
green
=
255
;
pix
.
blue
=
static_cast
<
unsigned
char
>
((
5
-
gray
)
*
s
*
255
+
0
.
5
);
}
else
if
(
gray
<=
7
)
{
pix
.
red
=
255
;
pix
.
green
=
static_cast
<
unsigned
char
>
((
7
-
gray
)
*
s
*
255
+
0
.
5
);
pix
.
blue
=
0
;
}
else
{
pix
.
red
=
static_cast
<
unsigned
char
>
((
9
-
gray
)
*
s
*
255
+
0
.
5
);
pix
.
green
=
0
;
pix
.
blue
=
0
;
}
return
pix
;
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
template
<
typename
T
>
...
@@ -163,44 +222,7 @@ namespace dlib
...
@@ -163,44 +222,7 @@ namespace dlib
const_ret_type
apply
(
long
r
,
long
c
)
const
const_ret_type
apply
(
long
r
,
long
c
)
const
{
{
// scale the gray value into the range [0, 8]
return
colormap_jet
(
get_pixel_intensity
(
mat
(
img
)(
r
,
c
)),
min_val
,
max_val
);
const
double
gray
=
8
*
put_in_range
(
0
,
1
,
(
get_pixel_intensity
(
mat
(
img
)(
r
,
c
))
-
min_val
)
/
(
max_val
-
min_val
));
rgb_pixel
pix
;
// s is the slope of color change
const
double
s
=
1
.
0
/
2
.
0
;
if
(
gray
<=
1
)
{
pix
.
red
=
0
;
pix
.
green
=
0
;
pix
.
blue
=
static_cast
<
unsigned
char
>
((
gray
+
1
)
*
s
*
255
+
0
.
5
);
}
else
if
(
gray
<=
3
)
{
pix
.
red
=
0
;
pix
.
green
=
static_cast
<
unsigned
char
>
((
gray
-
1
)
*
s
*
255
+
0
.
5
);
pix
.
blue
=
255
;
}
else
if
(
gray
<=
5
)
{
pix
.
red
=
static_cast
<
unsigned
char
>
((
gray
-
3
)
*
s
*
255
+
0
.
5
);
pix
.
green
=
255
;
pix
.
blue
=
static_cast
<
unsigned
char
>
((
5
-
gray
)
*
s
*
255
+
0
.
5
);
}
else
if
(
gray
<=
7
)
{
pix
.
red
=
255
;
pix
.
green
=
static_cast
<
unsigned
char
>
((
7
-
gray
)
*
s
*
255
+
0
.
5
);
pix
.
blue
=
0
;
}
else
{
pix
.
red
=
static_cast
<
unsigned
char
>
((
9
-
gray
)
*
s
*
255
+
0
.
5
);
pix
.
green
=
0
;
pix
.
blue
=
0
;
}
return
pix
;
}
}
long
nr
()
const
{
return
num_rows
(
img
);
}
long
nr
()
const
{
return
num_rows
(
img
);
}
...
...
dlib/image_transforms/colormaps_abstract.h
View file @
a969e1f9
...
@@ -37,6 +37,18 @@ namespace dlib
...
@@ -37,6 +37,18 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
rgb_pixel
colormap_heat
(
double
value
,
double
min_val
,
double
max_val
);
/*!
ensures
- Maps value to a color. In particular, we use a heatmap color scheme where
values <= min_val are black and larger values become more red, then yellow,
and then white as they approach max_val.
!*/
template
<
template
<
typename
image_type
typename
image_type
>
>
...
@@ -51,11 +63,9 @@ namespace dlib
...
@@ -51,11 +63,9 @@ namespace dlib
dlib/image_processing/generic_image.h, or something convertible to a matrix
dlib/image_processing/generic_image.h, or something convertible to a matrix
via mat().
via mat().
ensures
ensures
- Interprets img as a grayscale image and returns a new matrix
- Interprets img as a grayscale image and returns a new matrix which represents
which represents a colored version of img. In particular, the
a colored version of img. In particular, the colormap is defined by
colors will depict img using a heatmap where pixels with a
colormap_heat().
value <= min_val are black and larger pixel values become
more red, then yellow, and then white as they approach max_val.
- The returned matrix will have the same dimensions as img.
- The returned matrix will have the same dimensions as img.
!*/
!*/
...
@@ -79,6 +89,18 @@ namespace dlib
...
@@ -79,6 +89,18 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
rgb_pixel
colormap_jet
(
double
value
,
double
min_val
,
double
max_val
);
/*!
ensures
- Maps value to a color. In particular, we use a jet color scheme where
values <= min_val are dark blue and larger values become light blue, then
yellow, and then finally red as they approach max_val.
!*/
template
<
template
<
typename
image_type
typename
image_type
>
>
...
@@ -94,10 +116,8 @@ namespace dlib
...
@@ -94,10 +116,8 @@ namespace dlib
via mat().
via mat().
ensures
ensures
- Interprets img as a grayscale image and returns a new matrix which represents
- Interprets img as a grayscale image and returns a new matrix which represents
a colored version of img. In particular, the colors will depict img using a
a colored version of img. In particular, the colormap is defined by
jet color scheme where pixels with a value <= min_val are dark blue and
colormap_jet().
larger pixel values become light blue, then yellow, and then finally red as
they approach max_Val.
- The returned matrix will have the same dimensions as img.
- The returned matrix will have the same dimensions as img.
!*/
!*/
...
...
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