#include "stdafx.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include "iostream"
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
int alpha;
int beta;
char* name1 = "sourec";
char* name2 = "result";
Mat src = imread( argv[1] );
Mat new_map = Mat::zeros( src.size(), src.type() ); //构建一个新的零矩阵用来存储转换以后的图像 第一个参数是矩阵,第二个是矩阵类型参数3个通道的RGB
/// 初始化
cout << " Basic Linear Transforms " << endl;
cout << "-------------------------" << endl;
cout << "* Enter the alpha value [1.0-3.0]: ";
cin >> alpha;
cout << "* Enter the beta value [0-100]: ";
cin >> beta;
/*for (int y = 0; y < src.rows; y++)
{
for ( int x = 0; x < src.cols; x++ )
{
for ( int c = 0; c < 3; c++ )
{
new_map.at<Vec3b>(y,x)[c] = saturate_cast<uchar>( alpha * ( src.at<Vec3b>(y,x)[c] ) + beta );//<span style="font-family: Arial, Helvetica, sans-serif;">saturate_cast防止像素超出</span>
}
}
}*/
src.convertTo(new_map, -1, alpha, beta); //等价于前面的循环处理结果 执行运算 new_map(i,j) = alpha*image(i,j) + beta
namedWindow(name1,1);
namedWindow(name2,1);
imshow(name1,src);
imshow(name2,new_map);
waitKey();
return 0;
}