saturate_cast 图像对比度与亮度
2017-10-30 15:28
169 查看
#include<iostream>
#include<opencv2\opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc,char** argv){
Mat src,dst;
src = imread("1.jpg");
if (src.empty())
{
cout << "could not load image.." << endl;
return -1;
}
char input_win[] = "input image";
namedWindow(input_win, CV_WINDOW_AUTOSIZE);
imshow(input_win, src);
int height = src.rows;
int weight = src.cols;
float alpha = 1.2;
float beta = 60;
dst = Mat::zeros(src.size(), src.type());
for (int i = 0; i < height; i++) {
for (int j = 0; j < weight; j++) {
if (src.channels() == 3) {
float b = src.at<Vec3b>(i,j)[0];
float g = src.at<Vec3b>(i,j)[1];
float r = src.at<Vec3b>(i,j)[2];
//对dst进行赋值操作
dst.at<Vec3b>(i, j)[0] = saturate_cast<uchar>(b*alpha+beta);
dst.at<Vec3b>(i, j)[1] = saturate_cast<uchar>(g*alpha + beta);
dst.at<Vec3b>(i, j)[2] = saturate_cast<uchar>(r*alpha + beta);
}
else if (src.channels() == 1)
{
float v = src.at<uchar>(i, j);
dst.at<uchar>(i,j)= saturate_cast<uchar>(v*alpha + beta);
}
}
}
char output_title[] = "调整图像亮度和对比度";
cvNamedWindow(output_title, CV_WINDOW_AUTOSIZE);
imshow(output_title, dst);
waitKey(0);
return 0;
}
#include<opencv2\opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc,char** argv){
Mat src,dst;
src = imread("1.jpg");
if (src.empty())
{
cout << "could not load image.." << endl;
return -1;
}
char input_win[] = "input image";
namedWindow(input_win, CV_WINDOW_AUTOSIZE);
imshow(input_win, src);
int height = src.rows;
int weight = src.cols;
float alpha = 1.2;
float beta = 60;
dst = Mat::zeros(src.size(), src.type());
for (int i = 0; i < height; i++) {
for (int j = 0; j < weight; j++) {
if (src.channels() == 3) {
float b = src.at<Vec3b>(i,j)[0];
float g = src.at<Vec3b>(i,j)[1];
float r = src.at<Vec3b>(i,j)[2];
//对dst进行赋值操作
dst.at<Vec3b>(i, j)[0] = saturate_cast<uchar>(b*alpha+beta);
dst.at<Vec3b>(i, j)[1] = saturate_cast<uchar>(g*alpha + beta);
dst.at<Vec3b>(i, j)[2] = saturate_cast<uchar>(r*alpha + beta);
}
else if (src.channels() == 1)
{
float v = src.at<uchar>(i, j);
dst.at<uchar>(i,j)= saturate_cast<uchar>(v*alpha + beta);
}
}
}
char output_title[] = "调整图像亮度和对比度";
cvNamedWindow(output_title, CV_WINDOW_AUTOSIZE);
imshow(output_title, dst);
waitKey(0);
return 0;
}
相关文章推荐
- OpenCV 图像对比度和亮度调节
- 示例程序020--改变图像对比度和亮度
- 图像对比度与亮度调整算法实现(Python&OpenCV)
- 【Opencv】saturate_cast防止数据溢出
- OpenCV学习--saturate_cast防止数据溢出
- Opencv图像对比度和亮度的调整
- Opencv图像对比度和亮度的调整-滚动条
- opencv之saturate_cast模板函数
- opencv 图像对比度及亮度调整
- opencv学习日常之“Saturation Casting“转换saturate_cast<>()
- saturate_cast
- OpenCV-saturate_cast
- OpenCV学习--saturate_cast防止数据溢出
- OpenCV学习--saturate_cast防止数据溢出
- opencv处理图像对比度和亮度
- python3-opencv库(4)--图片像素运算,利用加权叠加调节图像对比度和亮度
- Opencv之saturate_cast防止数据溢出
- 基础学习笔记之opencv(12):改变图像对比度和亮度
- OpenCV学习二:指针操作、saturate_cast
- Class03 改变图像对比度和亮度