zoukankan      html  css  js  c++  java
  • OpenCV学习:改变图像的对比度和亮度

      本实例演示简单地改变图像的对比度和亮度,使用了如下线性变换来实现像素值的遍历操作:

      

      The parameters α > 0 and β often called the gain and bias parameters;

      sometimes these parameters are said to control contrast and brightness respectively.

      代码如下:

    // 改变图像的对比度和亮度  
    #include <opencv2/opencv.hpp>  
    using namespace cv;
    using namespace std;
    
    double alpha; /** < Simple contrast control */
    int beta;     /** < Simple brightness control */
    
    int main( int argc, char** argv )
    {
        /// 加载图像
        Mat image = imread( "./Res/James Harden.jpg" );

      /// 目标图像空间预分配 Mat new_image
    = Mat::zeros( image.size(), image.type() ); /// 输入初始化值 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; /// 执行变换 new_image(i,j) = alpha * image(i,j) + 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(); cin.get(); return 0; }

    运行结果:

  • 相关阅读:
    《社会动物》笔记
    对长城汽车品牌多样化的一点思考
    LightGBM简单例子
    mysql拆分字符串为多行(逗号等分割)
    vue中$refs、$emit、$on的使用场景
    js中的call()和apply()和bind()方法
    Vue.js中this.$nextTick()的使用
    Vue中ref和$refs的介绍及使用
    ES6(异步操作和Async函数&await)
    vue项目在git commit时,使用eslint检测
  • 原文地址:https://www.cnblogs.com/MakeView660/p/6513589.html
Copyright © 2011-2022 走看看