Opencv— — Bias and Gain
// define head function
#ifndef PS_ALGORITHM_H_INCLUDED
#define PS_ALGORITHM_H_INCLUDED
#include
#include
#include "cv.h"
#include "highgui.h"
#include "cxmat.hpp"
#include "cxcore.hpp"
#include "math.h"
using namespace std;
using namespace cv;
void Show_Image(Mat&, const string &);
#endif // PS_ALGORITHM_H_INCLUDED
/*
Adjust bias and gain.
*/
#include "PS_Algorithm.h"
float Bias(float a, float b);
float Gain(float a, float b);
int main()
{
string Image_name("4.jpg");
Mat Img=imread(Image_name.c_str());
Mat Img_out(Img.size(), CV_32FC3);
float gain_val = 0.75; // 0-1
float bias_val = 0.25; // 0-1
int width=Img.cols;
int height=Img.rows;
float val;
for (int y=0; y(y, x)[k]/255;
val=Gain(val, gain_val);
Img_out.at(y, x)[k]=Bias(val, bias_val);
}
}
}
Show_Image(Img_out, "New_img");
cout<<"All is well."< .999)
return 1.0f;
if (a < 0.5)
return pow(2 * a, p) / 2;
else
return 1.0f - pow(2 * (1. - a), p) / 2;
*/
float c = (1.0f/b-2.0f) * (1.0f-2.0f*a);
if (a < 0.5)
return a/(c+1.0f);
else
return (c-a)/(c-1.0f);
}
// define the show image
#include "PS_Algorithm.h"
#include
#include
using namespace std;
using namespace cv;
void Show_Image(Mat& Image, const string& str)
{
namedWindow(str.c_str(),CV_WINDOW_AUTOSIZE);
imshow(str.c_str(), Image);
}