Open
Description
System information (version)
-
OpenCV => 4.10
-
Operating System / Platform => Windows 64 Bit
-
Compiler => Visual Studio 2022
-
OpenCV => 4.10
-
Operating System / Platform => Windows 64 Bit
-
Compiler => Visual Studio 2022
Detailed description
Following the tutorial I manage to make color correction over the image and the result is not totally weird but for away from others like DaVinci Resolve implementation.
bool getRGBChartsFromImage(const string& imagePath,const TYPECHART chartType, Mat &mat)
{
Mat imageWithCheck = imread(imagePath, IMREAD_COLOR);
if (!imageWithCheck.data) {
cout << "Invalid Image Check!" << endl;
return false;
}
Ptr<CCheckerDetector> detector = CCheckerDetector::create();
if (!detector->process(imageWithCheck, chartType, 1)) {
printf("ChartColor not detected \n");
return false;
}
vector<Ptr<mcc::CChecker>> checkers = detector->getListColorChecker();
if (checkers.size() != 1)
{
printf("Invalid amount of charts %i\n", (int)checkers.size());
}
Ptr<mcc::CChecker> checker = checkers[0];
Mat chartsRGB = checker->getChartsRGB();
mat = chartsRGB.col(1).clone().reshape(3, chartsRGB.rows / 3);
mat /= 255.0;
}
bool calibrateImage(const Mat& uncalibradedMat, const TYPECHART chartType, const Mat &chartMat, Mat& calibratedMat)
{
CONST_COLOR destColor;
switch (chartType) {
case cv::mcc::MCC24:
destColor = COLORCHECKER_Macbeth;
break;
case cv::mcc::SG140:
destColor = COLORCHECKER_DigitalSG;
break;
case cv::mcc::VINYL18:
destColor = COLORCHECKER_Vinyl;
break;
default:
printf("Invalid chart type. Exiting.\n");
return false;
}
ColorCorrectionModel model(chartMat, destColor);
//model.setInitialMethod(INITIAL_METHOD_WHITE_BALANCE);
model.setColorSpace(COLOR_SPACE_sRGB);
model.setDistance(DISTANCE_CIE2000);
model.setLinear(LINEARIZATION_GAMMA);
model.setLinearGamma(2.0);
model.setLinearDegree(3);
model.setCCM_TYPE(CCM_3x3);
model.setMaxCount(5000);
model.setEpsilon(1e-7);
model.setSaturatedThreshold(0, 0.98);
model.run();
Mat ccm = model.getCCM();
std::cout << "ccm:\n" << ccm << std::endl;
double loss = model.getLoss();
std::cout << "loss: " << loss << std::endl;
// Aplicar el modelo a imageMod
Mat img_;
cvtColor(uncalibradedMat, img_, COLOR_BGR2RGB);
img_.convertTo(img_, CV_64F, 1.0 / 255.0);
Mat calibratedImage = model.infer(img_);
Mat out_ = calibratedImage * 255.0;
out_.convertTo(out_, CV_8UC3);
Mat img_out = min(max(out_, 0), 255);
cvtColor(img_out, calibratedMat, COLOR_RGB2BGR);
return true;
}
You can notice that the result is too warm.
Thank you in advance