ColorMaps in opencv

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;
}
以下是每个可用色彩的颜色标尺:
Class
Scale
COLORMAP_AUTUMN ../../../../_images/colorscale_autumn.jpg
COLORMAP_BONE ../../../../_images/colorscale_bone.jpg
COLORMAP_COOL ../../../../_images/colorscale_cool.jpg
COLORMAP_HOT ../../../../_images/colorscale_hot.jpg
COLORMAP_HSV ../../../../_images/colorscale_hsv.jpg
COLORMAP_JET ../../../../_images/colorscale_jet.jpg
COLORMAP_OCEAN ../../../../_images/colorscale_ocean.jpg
COLORMAP_PINK ../../../../_images/colorscale_pink.jpg
COLORMAP_RAINBOW ../../../../_images/colorscale_rainbow.jpg
COLORMAP_SPRING ../../../../_images/colorscale_spring.jpg
COLORMAP_SUMMER ../../../../_images/colorscale_summer.jpg
COLORMAP_WINTER ../../../../_images/colorscale_winter.jpg


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值