Commit a969e1f9 authored by Davis King's avatar Davis King

Made the jet and heat colormaps more accessible to other routines.

parent ac4666cb
......@@ -63,6 +63,32 @@ namespace dlib
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>
......@@ -89,22 +115,7 @@ namespace dlib
const_ret_type apply (long r, long c ) const
{
// scale the gray value into the range [0, 1]
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;
return colormap_heat(get_pixel_intensity(mat(img)(r,c)), min_val, max_val);
}
long nr () const { return num_rows(img); }
......@@ -139,32 +150,14 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template <typename T>
struct op_jet : does_not_alias
{
op_jet(
const T& img_,
const double max_val_,
const double min_val_
) : img(img_), max_val(max_val_), min_val(min_val_){}
const T& img;
const double max_val;
const double min_val;
const static long cost = 7;
const static long NR = 0;
const static long NC = 0;
typedef rgb_pixel type;
typedef const rgb_pixel const_ret_type;
typedef default_memory_manager mem_manager_type;
typedef row_major_layout layout_type;
const_ret_type apply (long r, long c ) const
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, (get_pixel_intensity(mat(img)(r,c)) - min_val)/(max_val-min_val));
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;
......@@ -203,6 +196,35 @@ namespace dlib
return pix;
}
// ----------------------------------------------------------------------------------------
template <typename T>
struct op_jet : does_not_alias
{
op_jet(
const T& img_,
const double max_val_,
const double min_val_
) : img(img_), max_val(max_val_), min_val(min_val_){}
const T& img;
const double max_val;
const double min_val;
const static long cost = 7;
const static long NR = 0;
const static long NC = 0;
typedef rgb_pixel type;
typedef const rgb_pixel const_ret_type;
typedef default_memory_manager mem_manager_type;
typedef row_major_layout layout_type;
const_ret_type apply (long r, long c ) const
{
return colormap_jet(get_pixel_intensity(mat(img)(r,c)), min_val, max_val);
}
long nr () const { return num_rows(img); }
long nc () const { return num_columns(img); }
};
......
......@@ -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 <
typename image_type
>
......@@ -51,11 +63,9 @@ namespace dlib
dlib/image_processing/generic_image.h, or something convertible to a matrix
via mat().
ensures
- 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 heatmap where pixels with a
value <= min_val are black and larger pixel values become
more red, then yellow, and then white as they approach max_val.
- Interprets img as a grayscale image and returns a new matrix which represents
a colored version of img. In particular, the colormap is defined by
colormap_heat().
- The returned matrix will have the same dimensions as img.
!*/
......@@ -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 <
typename image_type
>
......@@ -94,10 +116,8 @@ namespace dlib
via mat().
ensures
- 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
jet color scheme where pixels with a value <= min_val are dark blue and
larger pixel values become light blue, then yellow, and then finally red as
they approach max_Val.
a colored version of img. In particular, the colormap is defined by
colormap_jet().
- The returned matrix will have the same dimensions as img.
!*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment