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: |
|
---|
目前实现了以下GNU Octave / MATLAB等效的色彩映射:
人类的感知不是用来观察灰度图像的细微变化的。 人眼对于观察颜色之间的变化更为敏感,因此您经常需要重新着色灰度图像,以获得关于它们的线索。 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 | ![]() |
COLORMAP_BONE | ![]() |
COLORMAP_COOL | ![]() |
COLORMAP_HOT | ![]() |
COLORMAP_HSV | ![]() |
COLORMAP_JET | ![]() |
COLORMAP_OCEAN | ![]() |
COLORMAP_PINK | ![]() |
COLORMAP_RAINBOW | ![]() |
COLORMAP_SPRING | ![]() |
COLORMAP_SUMMER | ![]() |
COLORMAP_WINTER | ![]() |