Matlab使用colormap Jet 可以将灰度图像生成彩色的热度图,灰度值越高,色彩偏向暖色调。相反亦然。
// ColorMap.h #ifndef COLORMAP_H #define COLORMAP_H class colormap { public: static void GroundColorMix(BYTE* color, double x, double min, double max); static void Convert2Colormap(BYTE* Image, int *imSize); }; #endif //ColorMap.cpp #include "ColorMap.h" #define BChannel 2 #define GChannel 1 #define RChannel 0 void colormap::GroundColorMix(BYTE* color, double x, double min, double max) { double posSlope = (max-min)/60; double negSlope = (min-max)/60; if( x < 60 ) { color[RChannel] = max; color[GChannel] = posSlope*x+min; color[BChannel] = min; return; } else if ( x < 120 ) { color[RChannel] = negSlope*x+2*max+min; color[GChannel] = max; color[BChannel] = min; return; } else if ( x < 180 ) { color[RChannel] = min; color[GChannel] = max; color[BChannel] = posSlope*x-2*max+min; return; } else if ( x < 240 ) { color[RChannel] = min; color[GChannel] = negSlope*x+4*max+min; color[BChannel] = max; return; } else if ( x < 300 ) { color[RChannel] = posSlope*x-4*max+min; color[GChannel] = min; color[BChannel] = max; return; } else { color[RChannel] = max; color[GChannel] = min; color[2] = negSlope*x+6*max; return; } } void colormap::Convert2Colormap(BYTE* Image, int *imSize) //Image为三通道的灰度图像,R=G=B { const int stride = imSize[1]*imSize[2]; const int height = imSize[0]; const int width = imSize[1]; for (int i=0; i<height; i++) { BYTE *rowIndex = &Image[i*stride]; for (int j=0; j<stride; j+=3) { GroundColorMix(&rowIndex[j],rowIndex[j],0.0,255.0); } } } #undef BChannel #undef GChannel #undef RChannel |