#include <opencv2/opencv.hpp>
#include "gamma.h"
#include "drawImage.h"
using namespace cv;
int main()
{
Mat image = imread("arial.jpg");
if (!image.data)
{
return -1;
}
imageProcess oper;
drawImage draw;
oper.nlen = image.cols*image.rows;
vector<Mat> planes;
int chn = image.channels();
if (chn==3)
{
split(image,planes);
}
char filename[256];
while (chn)
{
chn--;
unsigned char* imageData = new unsigned char[sizeof(unsigned char)*(image.cols*image.rows)];
Mat hist1(256,256,CV_8UC3,Scalar(0,0,0));
Mat hist2(256,256,CV_8UC3,Scalar(0,0,0));
memcpy(imageData,planes[chn].data,planes[chn].cols*planes[chn].rows);
oper.getHis(imageData);
oper.getPdf();
draw.drawHistogram(oper.pdf,hist1);
sprintf(filename,"original_his%d.jpg",chn);
imwrite(filename,hist1);
oper.gamma = 0.7;
oper.gamaCorrection(imageData,oper.gamma);
oper.getHis(imageData);
oper.getPdf();
draw.drawHistogram(oper.pdf,hist2);
sprintf(filename,"his%fCorrection%d.jpg",oper.gamma,chn);
imwrite(filename,hist2);
memcpy(planes[chn].data,imageData,planes[chn].cols*planes[chn].rows);
imageData = NULL;
delete[] imageData;
}
merge(planes,image);
sprintf(filename,"gamma%f.jpg",oper.gamma);
imwrite(filename,image);
}
评论1
最新资源