我认为在这种情况下,阴影、中间调和高光定义了拖动条值的范围。
- 阴影 - 精确定位(小范围);
- 中间调 - 中等调整(中等范围);
- 高光 - 大幅度调整(广泛范围)。
这使得快速精确地进行颜色校正成为可能。
代码片段:
#include <iostream>
#include <vector>
#include <stdio.h>
#include <functional>
#include <algorithm>
#include <numeric>
#include <cstddef>
#include "opencv2/opencv.hpp"
using namespace std;
using namespace cv;
int val_Cyan_Red=0;
int val_Magenta_Green=0;
int val_Yellow_Blue=0;
Mat result;
Mat Img;
void on_trackbar( int, void* )
{
float SH=0.1;
float cr_val=(float)val_Cyan_Red/255.0;
float mg_val=(float)val_Magenta_Green/255.0;
float yb_val=(float)val_Yellow_Blue/255.0;
float R1=0;
float G1=1;
float B1=1;
float R2=1;
float G2=0;
float B2=0;
float DR=(1-cr_val)*R1+(cr_val)*R2-0.5;
float DG=(1-cr_val)*G1+(cr_val)*G2-0.5;
float DB=(1-cr_val)*B1+(cr_val)*B2-0.5;
result=Img+(Scalar(DB,DG,DR)*SH);
R1=1;
G1=0;
B1=1;
R2=0;
G2=1;
B2=0;
DR=(1-mg_val)*R1+(mg_val)*R2-0.5;
DG=(1-mg_val)*G1+(mg_val)*G2-0.5;
DB=(1-mg_val)*B1+(mg_val)*B2-0.5;
result+=(Scalar(DB,DG,DR)*SH);
R1=1;
G1=1;
B1=0;
R2=0;
G2=0;
B2=1;
DR=(1-yb_val)*R1+(yb_val)*R2-0.5;
DG=(1-yb_val)*G1+(yb_val)*G2-0.5;
DB=(1-yb_val)*B1+(yb_val)*B2-0.5;
result+=(Scalar(DB,DG,DR)*SH);
imshow("Result",result);
waitKey(10);
}
int main( int argc, char** argv )
{
namedWindow("Image",cv::WINDOW_NORMAL);
namedWindow("Result");
Img=imread("D:\\ImagesForTest\\cat2.jpg",1);
Img.convertTo(Img,CV_32FC1,1.0/255.0);
createTrackbar("CyanRed", "Image", &val_Cyan_Red, 255, on_trackbar);
createTrackbar("MagentaGreen", "Image", &val_Magenta_Green, 255, on_trackbar);
createTrackbar("YellowBlue", "Image", &val_Yellow_Blue, 255, on_trackbar);
imshow("Image",Img);
waitKey(0);
}
对于上述近似的值(零偏移为128),结果如下图所示:
![enter image description here](https://istack.dev59.com/C0cwq.webp)