OpenCV | 4.1.0 |
IDE | Visual Studio 2017 Enterprise (15.9.13) |
操作系统 | Windows 10 x64 中文专业版 (1903) |
在OpenCV库中,常见的伪色彩模式可以通过 applyColorMap(InputArray src, OutputArray dst, int colormap)
直接调用。
1、函数说明:
(1)void applyColorMap(InputArray src, OutputArray dst, int colormap)
src: 源图像(灰度图或彩色图(CV_8UC1 or CV_8UC3))。
dst: 在源图像上进行色彩映射后的结果图像。
colormap:提供的色彩图代码值。(参见:ColormapTypes 枚举数据类型)
(2)void applyColorMap(InputArray src, OutputArray dst, InputArray userColor)
src: 源图像(灰度图或彩色图(CV_8UC1 or CV_8UC3))。
dst: 在源图像上进行色彩映射后的结果图像。
userColor:自定义的色彩(CV_8UC1 or CV_8UC3 and size 256)。
2、OpenCV 4.1.0 中定义了色彩图枚举数据类型:ColormapTypes(包含 20 种)。
说明:(1)在 imgproc.hpp 文件中定义。(D:\opencv-4.1.0\build\include\opencv2\imgproc.hpp)
(2)与 Octave、MATLAB中定义的值完全相同。
//! GNU Octave/MATLAB equivalent colormaps
enum ColormapTypes
{
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, //!< 
COLORMAP_PARULA = 12, //!< 
COLORMAP_MAGMA = 13, //!< 
COLORMAP_INFERNO = 14, //!< 
COLORMAP_PLASMA = 15, //!< 
COLORMAP_VIRIDIS = 16, //!< 
COLORMAP_CIVIDIS = 17, //!< 
COLORMAP_TWILIGHT = 18, //!< 
COLORMAP_TWILIGHT_SHIFTED = 19 //!< 
};
3、色度图:
枚举值 | 枚举常量 | 色度图 |
---|---|---|
0 | COLORMAP_AUTUMN | ![]() |
1 | COLORMAP_BONE |
|
2 | COLORMAP_JET | ![]() |
3 | COLORMAP_WINTER | ![]() |
4 | COLORMAP_RAINBOW | ![]() |
5 | COLORMAP_OCEAN | ![]() |
6 | COLORMAP_SUMMER | ![]() |
7 | COLORMAP_SPRING | ![]() |
8 | COLORMAP_COOL | ![]() |
9 | COLORMAP_HSV | ![]() |
10 | COLORMAP_PINK | ![]() |
11 | COLORMAP_HOT | ![]() |
12 | COLORMAP_PARULA | ![]() |
13 | COLORMAP_MAGMA | ![]() |
14 | COLORMAP_INFERNO | ![]() |
15 | COLORMAP_PLASMA | ![]() |
16 | COLORMAP_VIRIDIS | ![]() |
17 | COLORMAP_CIVIDIS | ![]() |
18 | COLORMAP_TWILIGHT | ![]() |
19 | COLORMAP_TWILIGHT_SHIFTED | ![]() |
#include
#include
using namespace cv;
using namespace std;
void customColorMap(Mat &image);
int main(int argc, const char *argv[])
{
Mat src = imread("../images/fp_my01.png");
if (src.empty()){
printf("不能加载图像!\n");
return -1;
}
imshow("1-原图", src);
Mat dst;
//applyColorMap(src, dst, COLORMAP_SUMMER);
//applyColorMap(src, dst, COLORMAP_AUTUMN);
//applyColorMap(src, dst, COLORMAP_BONE);
applyColorMap(src, dst, COLORMAP_JET);
//applyColorMap(src, dst, COLORMAP_WINTER);
//applyColorMap(src, dst, COLORMAP_RAINBOW);
//applyColorMap(src, dst, COLORMAP_OCEAN);
//applyColorMap(src, dst, COLORMAP_SPRING);
//applyColorMap(src, dst, COLORMAP_COOL);
//applyColorMap(src, dst, COLORMAP_HSV);
//applyColorMap(src, dst, COLORMAP_PINK);
//applyColorMap(src, dst, COLORMAP_HOT);
//applyColorMap(src, dst, COLORMAP_PARULA);
//applyColorMap(src, dst, COLORMAP_MAGMA);
//applyColorMap(src, dst, COLORMAP_INFERNO);
//applyColorMap(src, dst, COLORMAP_PLASMA);
//applyColorMap(src, dst, COLORMAP_VIRIDIS);
//applyColorMap(src, dst, COLORMAP_CIVIDIS);
//applyColorMap(src, dst, COLORMAP_TWILIGHT);
//applyColorMap(src, dst, COLORMAP_TWILIGHT_SHIFTED);
// 显示结果
imshow("2-ColorMap", dst);
waitKey(0);
return 0;
}