文章目录
- 1、applyColorMap()函数的使用:
- (1)函数原型:
- void applyColorMap(InputArray src, OutputArray dst, int colormap)
- void applyColorMap(InputArray src, OutputArray dst, InputArray userColor)
- (2)示例:
- 成果展示:
1、applyColorMap()函数的使用:
使用applyColorMap()函数,可以将灰度图或彩色图转换成自定义的彩色图,或opencv提供的20多种色彩值
(1)函数原型:
void applyColorMap(InputArray src, OutputArray dst, int colormap)
- src:源图像,灰度图或彩色图( CV_8UC1 or CV_8UC3 );
- dst:在源图像上进行色彩映射后的结果图像;
- colormap:opencv提供的色彩值;
// opencv提供的色彩值 int colorMap[] = { COLORMAP_AUTUMN, COLORMAP_BONE, COLORMAP_JET, COLORMAP_WINTER, COLORMAP_RAINBOW, COLORMAP_OCEAN, COLORMAP_SUMMER, COLORMAP_SPRING, COLORMAP_COOL, COLORMAP_HSV, COLORMAP_PINK, COLORMAP_HOT, COLORMAP_PARULA, COLORMAP_MAGMA, COLORMAP_INFERNO, COLORMAP_PLASMA, COLORMAP_VIRIDIS, COLORMAP_CIVIDIS, COLORMAP_TWILIGHT, COLORMAP_TWILIGHT_SHIFTED };
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提供的20多种色彩值
void QuickDemo::colorStyle(Mat &image) {
// opencv提供的色彩值
int colorMap[] = {
COLORMAP_AUTUMN,
COLORMAP_BONE,
COLORMAP_JET,
COLORMAP_WINTER,
COLORMAP_RAINBOW,
COLORMAP_OCEAN,
COLORMAP_SUMMER,
COLORMAP_SPRING,
COLORMAP_COOL,
COLORMAP_HSV,
COLORMAP_PINK,
COLORMAP_HOT,
COLORMAP_PARULA,
COLORMAP_MAGMA,
COLORMAP_INFERNO,
COLORMAP_PLASMA,
COLORMAP_VIRIDIS,
COLORMAP_CIVIDIS,
COLORMAP_TWILIGHT,
COLORMAP_TWILIGHT_SHIFTED
};
Mat dst;
int index = 0;
while (true) {
int c = waitKey(200);
if (c == 27) { // 退出
break;
}
// index%19,index取模之后下标值在 0 - 19 之间循环,下标不会超过19
applyColorMap(image, dst, colorMap[index%19]);
index++;
namedWindow("colorStyle", WINDOW_NORMAL);
imshow("colorStyle", dst);
}
}