Visual Servoing Platform  version 3.6.1 under development (2024-04-19)
tutorial-image-colormap.cpp
#include <map>
#include <visp3/core/vpColormap.h>
#include <visp3/core/vpFont.h>
#include <visp3/core/vpImageTools.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/io/vpImageIo.h>
int main()
{
#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
try {
std::map<vpColormap::vpColormapType, std::string> colormaps_str = {
{vpColormap::COLORMAP_AUTUMN, "Colormap Autumn"},
{vpColormap::COLORMAP_CIVIDIS, "Colormap Cividis"},
{vpColormap::COLORMAP_COOL, "Colormap Cool"},
{vpColormap::COLORMAP_GIST_EARTH, "Colormap Gist Earth"},
{vpColormap::COLORMAP_GNUPLOT, "Colormap Gnuplot"},
{vpColormap::COLORMAP_GNUPLOT2, "Colormap Gnuplot2"},
{vpColormap::COLORMAP_HOT, "Colormap Hot"},
{vpColormap::COLORMAP_HSV, "Colormap HSV"},
{vpColormap::COLORMAP_INFERNO, "Colormap Inferno"},
{vpColormap::COLORMAP_JET, "Colormap Jet"},
{vpColormap::COLORMAP_MAGMA, "Colormap Magma"},
{vpColormap::COLORMAP_OCEAN, "Colormap Ocean"},
{vpColormap::COLORMAP_PLASMA, "Colormap Plasma"},
{vpColormap::COLORMAP_RAINBOW, "Colormap Rainbow"},
{vpColormap::COLORMAP_SPRING, "Colormap Spring"},
{vpColormap::COLORMAP_SUMMER, "Colormap Summer"},
{vpColormap::COLORMAP_TERRAIN, "Colormap Terrain"},
{vpColormap::COLORMAP_TURBO, "Colormap Turbo"},
{vpColormap::COLORMAP_TWILIGHT, "Colormap Twilight"},
{vpColormap::COLORMAP_TWILIGHT_SHIFTED, "Colormap Twilight Shifted"},
{vpColormap::COLORMAP_VIRIDIS, "Colormap Viridis"},
{vpColormap::COLORMAP_WINTER, "Colormap Winter"}
};
std::vector<vpColormap::vpColormapType> colormaps = {
};
// Apply a colormap on a 3-channel floating-point image
{
vpImageIo::readPFM_HDR(Irgbf, "memorial.pfm");
vpImage<vpRGBa> Icolor(Irgbf.getHeight(), Irgbf.getWidth());
vpImage<vpRGBa> Icolor2(Irgbf.getHeight() * 2, Irgbf.getWidth() * 2);
#if defined(VISP_HAVE_X11)
vpDisplayX d(Icolor2, 10, 10, "Memorial");
#elif defined(VISP_HAVE_GDI)
vpDisplayGDI d(Icolor2, 10, 10, "Memorial");
#elif defined(HAVE_OPENCV_HIGHGUI)
vpDisplayOpenCV d(Icolor2, 10, 10, "Memorial");
#else
std::cout << "No image viewer is available..." << std::endl;
return EXIT_SUCCESS;
#endif
vpFont font(20);
for (size_t i = 0; i < colormaps.size(); i++) {
vpColormap colormap(colormaps[i]);
colormap.convert(Irgbf, Icolor);
font.drawText(Icolor2, colormaps_str[colormaps[i]], vpImagePoint(20, 20), vpColor::black, vpColor::white);
vpDisplay::flush(Icolor2);
}
}
// Apply a colormap on a 8-bit RGB image
{
vpImageIo::read(I, "monkey.png");
vpImage<vpRGBa> Icolor2(I.getHeight() * 2, I.getWidth() * 2);
#if defined(VISP_HAVE_X11)
vpDisplayX d(Icolor2, 10, 10, "Monkey");
#elif defined(VISP_HAVE_GDI)
vpDisplayGDI d(Icolor2, 10, 10, "Monkey");
#elif defined(HAVE_OPENCV_HIGHGUI)
vpDisplayOpenCV d(Icolor2, 10, 10, "Monkey");
#else
std::cout << "No image viewer is available..." << std::endl;
return EXIT_SUCCESS;
#endif
vpFont font(20);
for (size_t i = 0; i < colormaps.size(); i++) {
vpColormap colormap(colormaps[i]);
colormap.convert(I, Icolor);
font.drawText(Icolor2, colormaps_str[colormaps[i]], vpImagePoint(20, 20), vpColor::black, vpColor::white);
vpDisplay::flush(Icolor2);
}
}
// Apply a colormap on a 8-bit RGB image, with normalization to the [0 - 255] range
{
vpImageIo::read(I, "monkey.png");
vpImage<vpRGBa> Icolor2(I.getHeight() * 2, I.getWidth() * 2);
#if defined(VISP_HAVE_X11)
vpDisplayX d(Icolor2, 10, 10, "Monkey");
#elif defined(VISP_HAVE_GDI)
vpDisplayGDI d(Icolor2, 10, 10, "Monkey");
#elif defined(HAVE_OPENCV_HIGHGUI)
vpDisplayOpenCV d(Icolor2, 10, 10, "Monkey");
#else
std::cout << "No image viewer is available..." << std::endl;
return EXIT_SUCCESS;
#endif
vpFont font(20);
for (size_t i = 0; i < colormaps.size(); i++) {
vpColormap colormap(colormaps[i]);
const bool normalise = true;
colormap.convert(I, Icolor, normalise);
font.drawText(Icolor2, colormaps_str[colormaps[i]], vpImagePoint(20, 20), vpColor::black, vpColor::white);
vpDisplay::flush(Icolor2);
}
}
}
catch (const vpException &e) {
std::cerr << "Catch an exception: " << e << std::endl;
}
#else
std::cout << "This tutorial should be built with c++11 support" << std::endl;
#endif
return EXIT_SUCCESS;
}
static const vpColor white
Definition: vpColor.h:206
static const vpColor black
Definition: vpColor.h:205
Creates a colormap class to be able to recolor an image with different grayscale values into some cor...
Definition: vpColormap.h:58
@ COLORMAP_OCEAN
Definition: vpColormap.h:73
@ COLORMAP_MAGMA
Definition: vpColormap.h:72
@ COLORMAP_TWILIGHT
Definition: vpColormap.h:80
@ COLORMAP_VIRIDIS
Definition: vpColormap.h:82
@ COLORMAP_COOL
Definition: vpColormap.h:64
@ COLORMAP_RAINBOW
Definition: vpColormap.h:75
@ COLORMAP_GNUPLOT
Definition: vpColormap.h:66
@ COLORMAP_INFERNO
Definition: vpColormap.h:70
@ COLORMAP_GIST_EARTH
Definition: vpColormap.h:65
@ COLORMAP_TWILIGHT_SHIFTED
Definition: vpColormap.h:81
@ COLORMAP_AUTUMN
Definition: vpColormap.h:62
@ COLORMAP_CIVIDIS
Definition: vpColormap.h:63
@ COLORMAP_SPRING
Definition: vpColormap.h:76
@ COLORMAP_JET
Definition: vpColormap.h:71
@ COLORMAP_HOT
Definition: vpColormap.h:68
@ COLORMAP_TURBO
Definition: vpColormap.h:79
@ COLORMAP_PLASMA
Definition: vpColormap.h:74
@ COLORMAP_TERRAIN
Definition: vpColormap.h:78
@ COLORMAP_HSV
Definition: vpColormap.h:69
@ COLORMAP_GNUPLOT2
Definition: vpColormap.h:67
@ COLORMAP_WINTER
Definition: vpColormap.h:83
@ COLORMAP_SUMMER
Definition: vpColormap.h:77
void convert(const vpImage< unsigned char > &I, vpImage< vpRGBa > &Icolor, bool normalize=false)
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:128
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
error that can be emitted by ViSP classes.
Definition: vpException.h:59
Font drawing functions for image.
Definition: vpFont.h:54
bool drawText(vpImage< unsigned char > &I, const std::string &text, const vpImagePoint &position, unsigned char color) const
Definition: vpFont.cpp:2617
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:143
static void readPFM_HDR(vpImage< float > &I, const std::string &filename)
Definition: vpImageIo.cpp:1347
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
static void resize(const vpImage< Type > &I, vpImage< Type > &Ires, unsigned int width, unsigned int height, const vpImageInterpolationType &method=INTERPOLATION_NEAREST, unsigned int nThreads=0)
@ INTERPOLATION_LINEAR
Definition: vpImageTools.h:80
Definition of the vpImage class member functions.
Definition: vpImage.h:69
unsigned int getWidth() const
Definition: vpImage.h:245
unsigned int getHeight() const
Definition: vpImage.h:184