ColorMaps in opencv

来源:互联网 发布:免费费用报销软件 编辑:程序博客网 时间:2024/06/03 22:39

http://docs.opencv.org/2.4/modules/contrib/doc/facerec/colormaps.html#applycolormap

http://www.learnopencv.com/applycolormap-for-pseudocoloring-in-opencv-c-python/

在给定的图像上应用GNU Octave / MATLAB等效的色彩映射。

C++: void applyColorMap(InputArray src, OutputArray dst, int colormap)
Parameters:
  • src – The source image, grayscale or colored does not matter.
  • dst – The result is the colormapped source image. Note: Mat::create() is called on dst.
  • colormap – The colormap to apply, see the list of available colormaps below.

目前实现了以下GNU Octave / MATLAB等效的色彩映射:

enum{    COLORMAP_AUTUMN = 0,    COLORMAP_BONE = 1,    COLORMAP_JET = 2,    COLORMAP_WINTER = 3,    COLORMAP_RAINBOW = 4,    COLORMAP_OCEAN = 5,    COLORMAP_SUMMER = 6,    COLORMAP_SPRING = 7,    COLORMAP_COOL = 8,    COLORMAP_HSV = 9,    COLORMAP_PINK = 10,    COLORMAP_HOT = 11}
人类的感知不是用来观察灰度图像的细微变化的。 人眼对于观察颜色之间的变化更为敏感,因此您经常需要重新着色灰度图像,以获得关于它们的线索。 OpenCV现在配有各种色彩映射,以增强计算机视觉应用程序中的可视化。

在OpenCV 2.4中,您只需要applyColorMap()来在给定的图像上应用色彩映射。 以下示例代码从命令行读取图像的路径,在其上应用Jet色彩映射并显示结果:

#include <opencv2/contrib/contrib.hpp>#include <opencv2/core/core.hpp>#include <opencv2/highgui/highgui.hpp>using namespace cv;int main(int argc, const char *argv[]) {    // Get the path to the image, if it was given    // if no arguments were given.    string filename;    if (argc > 1) {        filename = string(argv[1]);    }    // The following lines show how to apply a colormap on a given image    // and show it with cv::imshow example with an image. An exception is    // thrown if the path to the image is invalid.    if(!filename.empty()) {        Mat img0 = imread(filename);        // Throw an exception, if the image can't be read:        if(img0.empty()) {            CV_Error(CV_StsBadArg, "Sample image is empty. Please adjust your path, so it points to a valid input image!");        }        // Holds the colormap version of the image:        Mat cm_img0;        // Apply the colormap:        applyColorMap(img0, cm_img0, COLORMAP_JET);        // Show the result:        imshow("cm_img0", cm_img0);        waitKey(0);    }    return 0;}
以下是每个可用色彩的颜色标尺:
ClassScaleCOLORMAP_AUTUMN../../../../_images/colorscale_autumn.jpgCOLORMAP_BONE../../../../_images/colorscale_bone.jpgCOLORMAP_COOL../../../../_images/colorscale_cool.jpgCOLORMAP_HOT../../../../_images/colorscale_hot.jpgCOLORMAP_HSV../../../../_images/colorscale_hsv.jpgCOLORMAP_JET../../../../_images/colorscale_jet.jpgCOLORMAP_OCEAN../../../../_images/colorscale_ocean.jpgCOLORMAP_PINK../../../../_images/colorscale_pink.jpgCOLORMAP_RAINBOW../../../../_images/colorscale_rainbow.jpgCOLORMAP_SPRING../../../../_images/colorscale_spring.jpgCOLORMAP_SUMMER../../../../_images/colorscale_summer.jpgCOLORMAP_WINTER../../../../_images/colorscale_winter.jpg

原创粉丝点击