//自动对比度均衡(非色彩均衡)
Mat ACE2(Mat src, int C = 3, int n = 3, float MaxCG = 7.5){
int row = src.rows;
int col = src.cols;
Mat meanLocal; //图像局部均值
Mat varLocal; //图像局部方差
Mat meanGlobal; //全局均值
Mat varGlobal; //全局标准差
blur(src.clone(), meanLocal, Size(n, n));
Mat highFreq = src - meanLocal;
varLocal = highFreq.mul(highFreq);
varLocal.convertTo(varLocal, CV_32F);
for(int i = 0; i < row; i++){
for(int j = 0; j < col; j++){
varLocal.at<float>(i, j) = (float)sqrt(varLocal.at<float>(i, j));
}
}
meanStdDev(src, meanGlobal, varGlobal);
Mat gainArr = meanGlobal / varLocal; //增益系数矩阵
for(int i = 0; i < row; i++){
for(int j = 0; j < col; j++){
if(gainArr.at<float>(i, j) > MaxCG){
gainArr.at<float>(i, j) = MaxCG;
}
}
}
printf("%d %d\n", row, col);
gainArr.convertTo(gainArr, CV_8U);
gainArr = gainArr.mul(highFreq);
Mat dst1 = meanLocal + gainArr;
//Mat dst2 = meanLocal + C * highFreq;
return dst1;
}
int main(){
Mat src = imread("./test2.png");
vector <Mat> now;
split(src, now);
int C = 4;
int n = 15;
float MaxCG = 2;
Mat dst1 = ACE2(now[0], C, n, MaxCG);
Mat dst2 = ACE2(now[1], C, n, MaxCG);
Mat dst3 = ACE2(now[2], C, n, MaxCG);
now.clear();
Mat dst;
now.push_back(dst1);
now.push_back(dst2);
now.push_back(dst3);
cv::merge(now, dst);
imshow("origin", src);
imshow("result", dst);
imwrite("../result.jpg", dst);
waitKey(0);
return 0;}
ACE算法Real-time adaptive contrast enhancement for imaging sensors
最新推荐文章于 2023-12-25 17:19:08 发布