VS2017+OpenCV3.4.0 折腾(6)

今天使用的是调节对比度和亮度

p.s. 似乎发现之前bilibili那个链接的教程顺序大概是来源于最开始自己编译出来的那份html教程。所以可以自己看了 0 0

原理:

[g(i,j) = alpha cdot f(i,j) + eta (alpha > 0) ]

应用:

    Mat image = imread( imageName );
    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 );
            }
        }
    }

还有一种方法是Gamma correction
原理:

[O = left( frac{I}{255} ight)^{gamma} imes 255 ]

应用:

    Mat lookUpTable(1, 256, CV_8U);
    uchar* p = lookUpTable.ptr();
    for( int i = 0; i < 256; ++i)
        p[i] = saturate_cast<uchar>(pow(i / 255.0, gamma_) * 255.0);
    // 事先要有 gamma_ 的值
    Mat res = img.clone();
    LUT(img, lookUpTable, res);
原文地址:https://www.cnblogs.com/aphas1a/p/8475515.html