mirror of https://github.com/davisking/dlib.git
Made the jet and heat colormaps more accessible to other routines.
This commit is contained in:
parent
ac4666cbbc
commit
a969e1f984
|
@ -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); }
|
||||
|
@ -137,6 +148,54 @@ namespace dlib
|
|||
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>
|
||||
|
@ -163,44 +222,7 @@ namespace dlib
|
|||
|
||||
const_ret_type apply (long r, long c ) const
|
||||
{
|
||||
// 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));
|
||||
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;
|
||||
return colormap_jet(get_pixel_intensity(mat(img)(r,c)), min_val, max_val);
|
||||
}
|
||||
|
||||
long nr () const { return num_rows(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.
|
||||
!*/
|
||||
|
||||
|
|
Loading…
Reference in New Issue