对比度和亮度设置

2018-05-11  本文已影响0人  暗夜晴空
//对比度和亮度设置 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);
}
效果图 原图
上一篇 下一篇

猜你喜欢

热点阅读