OpenCV增加图像的亮度及对比度
opencv
OpenCV: 开源计算机视觉库
项目地址:https://gitcode.com/gh_mirrors/opencv31/opencv
免费下载资源
·
1、概述
案例:输出一张原图,增加该图片的亮度及对比度
基本概念:
亮度:RGB的像素值范围是0~255,我们称从0——>255随着像素值的增加图像会越来月亮,反之会越来越暗。所以我们可以通过对图像像素加减来改变图像的亮度。
对比度:其反应的是图像中各像素的差异(层次感、落差感),差异越大对比度越大,图像越清晰。差异越小对比度越小,图像越模糊。
2、示例代码
Mat src = imread(filePath);
imshow("src",src);
int height = src.rows;
int width = src.cols;
int channels = src.channels();
double alpha = 1.2;//像素增加权重,即:每个像素都扩大1.2倍,用于增加图像的对比度
double beta = 50;//用于增加亮度
Mat dst;//输出图像
dst = Mat::zeros(src.size(),src.type());//创建一个都是0的Mat,即纯黑色的mat
//下面是增加亮度及对比度的关键代码
for(int y = 0;y<height;y++){
for(int x = 0;x<width;x++){
dst.at<Vec3b>(y,x)[0] = saturate_cast<uchar>(alpha*src.at<Vec3b>(y,x)[0]+beta);
dst.at<Vec3b>(y,x)[1] = saturate_cast<uchar>(alpha*src.at<Vec3b>(y,x)[1]+beta);
dst.at<Vec3b>(y,x)[2] = saturate_cast<uchar>(alpha*src.at<Vec3b>(y,x)[2]+beta);
}
}
QImage qImage = QImage(dst.data,dst.cols,dst.rows,dst.step,QImage::Format_BGR888);
label->setFixedSize(QSize(qImage.width(),qImage.height()));
label->setScaledContents(true);
label->setPixmap(QPixmap::fromImage(qImage));
3、示例图片
本文福利,莬费领取Qt开发学习资料包、技术视频,内容包括(C++语言基础,Qt编程入门,QT信号与槽机制,QT界面开发-图像绘制,QT网络,QT数据库编程,QT项目实战,QSS,OpenCV,Quick模块,面试题等等)↓↓↓↓↓↓见下面↓↓文章底部点击莬费领取↓↓
GitHub 加速计划 / opencv31 / opencv
156
15
下载
OpenCV: 开源计算机视觉库
最近提交(Master分支:4 个月前 )
4d26e16a
Speed up and reduce memory consumption for findContours 2 天前
1db98278
Add jxl (JPEG XL) codec support #26379
### Pull Request Readiness Checklist
Related CI and Docker changes:
- https://github.com/opencv/ci-gha-workflow/pull/190
- https://github.com/opencv-infrastructure/opencv-gha-dockerfile/pull/44
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work https://github.com/opencv/opencv/issues/20178
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2 天前
更多推荐
已为社区贡献16条内容
所有评论(0)