#include <opencv/cv.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace std;
using namespace cv;
double alpha;
int beta;
int main()
{
Mat image=imread("image.jpg");
Mat new_image=Mat::zeros(image.size(), image.type());
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<image.rows;y++)
{
for(int x=0;x<image.cols;x++)
{
for(int c=0;c<3;c++)
{
new_image.at<Vec3b>(y,x)[c]=saturate_cast<uchar>(alpha*(image.at<Vec3b>(y,x)[c])+beta);
}
}
}
namedWindow("Original Image",1);
namedWindow("New Image",1);
imshow("Original Image",image);
imshow("New Image",new_image);
waitKey(0);
return 0;
}
其中alpha用来控制对比度contrast,beta用来控制亮度brightness
实验结果:
本文介绍了一个使用OpenCV库实现的C++程序,该程序能够读取一张图像,并允许用户通过输入alpha值来调整图像的对比度,通过输入beta值来调整图像的亮度。程序演示了如何使用OpenCV函数来逐像素地应用这些调整。
2万+

被折叠的 条评论
为什么被折叠?



