#include <iostream>
#include <sstream>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
using namespace std;
int main()
{
const int width = 640, height = 480, type = CV_8UC3;
double gamma[] = { 0.04, 0.1, 0.2, 0.3, 0.4, 0.6, 1.0, 1.5, 2.5, 3.5, 5.0, 10.0, 25.0 };
cv::Mat mat = cv::Mat::zeros(cv::Size(width, height), type);
cv::Point pts[1][256];
cv::Scalar color[] = { cv::Scalar(255, 0, 0), cv::Scalar( 0, 255, 0), cv::Scalar( 0, 0, 255),
cv::Scalar(255, 255, 0), cv::Scalar(255, 0, 255), cv::Scalar( 0, 128, 255),
cv::Scalar(128, 0, 0), cv::Scalar( 0, 128, 0), cv::Scalar( 0, 0, 128),
cv::Scalar(128, 128, 0), cv::Scalar(128, 0, 128), cv::Scalar( 0, 128, 128),
cv::Scalar( 0, 0, 0)
};
int indices[] = { 20, 40, 60, 80, 100, 120, 130, 140, 160, 180, 200, 220, 240 };
cv::rectangle(mat, cv::Rect(0, 0, width, height), cv::Scalar::all(255), -1);
for (int i = 0; i < 13; ++i)
{
for (int j = 0; j < 256; ++j)
{
int x = j * width / 256;
int y = height - (int)(cv::pow(j / 255.0, gamma[i]) * 255.0) * height / 256;
pts[0][j] = cv::Point(x, y);
}
const cv::Point* pPts[1] = { pts[0] };
int npts[1] = { 256 };
cv::polylines(mat, pPts, npts, 1, false, color[i], 1, cv::LINE_AA);
ostringstream oss;
oss << gamma[i];
cv::putText(mat, oss.str(), pts[0][indices[i]], 1, 1, color[i]);
}
cv::imshow("gamma", mat);
cv::waitKey(0);
return 0;
}
