对比度和亮度设置

//对比度和亮度设置 dConstrast[1-3]
int base::setContrastAndBright( string strFileName, double dConstrast, int nBright, QLabel* labelImage )
{
    Mat matSource = imread(strFileName);
    if (!matSource.data)
    {
        return(-1);
    }

    Mat matTemp = Mat::zeros(matSource.size(), matSource.type());

    for(int nRow=0; nRow<matSource.rows; nRow++)
    {
        for(int nCol=0; nCol<matSource.cols; nCol++)
        {
            for (int nChannel=0; nChannel<matSource.channels(); nChannel++)
            {
                //像素点操作 saturate_cast<uchar> 控制值范围[0,255]
                matTemp.at<Vec3b>(nRow, nCol)[nChannel] = 
                    saturate_cast<uchar>(dConstrast * matSource.at<Vec3b>(nRow, nCol)[nChannel] + nBright);
            }
        }
    }

    return loadImg(matTemp, labelImage);
}
效果图
原图
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容