转自https://blog.csdn.net/billbliss/article/details/43452173
#include<iostream>
#include<opencv2/opencv.hpp>
#include<sstream>
using namespace std;
using namespace cv;
void main()
{
Mat dst;
double vmin, vmax, alpha;
Mat ImgGray = imread("outImg4.jpg",0);
imshow("the original", ImgGray);
minMaxLoc(ImgGray, &vmin, &vmax);
alpha = (255.0 / (vmax - vmin))*0.85;
cout << alpha << endl;
ImgGray.convertTo(ImgGray, CV_8U, alpha, -vmin * alpha);
Mat im_color;
applyColorMap(ImgGray, im_color, COLORMAP_JET);
imshow("result", im_color);
imwrite("result4.jpg", im_color);
waitKey(0);
system("pause");
}