diff --git a/modules/mcc/include/opencv2/mcc/ccm.hpp b/modules/mcc/include/opencv2/mcc/ccm.hpp index ca2fb304642..37fbe962910 100644 --- a/modules/mcc/include/opencv2/mcc/ccm.hpp +++ b/modules/mcc/include/opencv2/mcc/ccm.hpp @@ -58,15 +58,15 @@ of the equipment, it is nessary to calibrate the captured color and the actual c */ enum CCM_TYPE { - CCM_3x3, ///0\\ C_{sl}=0, \qquad C_s=0 \f] -Because \f$exp(ln(0))\to\infin\f$, the channel whose component is 0 is directly mapped to 0 in the formula above. +Because \f$exp(ln(0))\to\infty \f$, the channel whose component is 0 is directly mapped to 0 in the formula above. For fitting channels respectively, we have: \f[ @@ -328,12 +328,13 @@ C_sl=0, \qquad C_s=0 */ enum LINEAR_TYPE { - IDENTITY_, - GAMMA, - COLORPOLYFIT, - COLORLOGPOLYFIT, - GRAYPOLYFIT, - GRAYLOGPOLYFIT + + LINEARIZATION_IDENTITY, ///ccm.data) { - throw "No CCM values!"; + CV_Error(Error::StsBadArg, "No CCM values!" ); } Mat img_lin = (p->linear)->linearize(img); Mat img_ccm(img_lin.size(), img_lin.type()); @@ -395,20 +393,20 @@ void ColorCorrectionModel::run() // distance function may affect the loss function and the fitting function switch (p->distance) { - case cv::ccm::RGBL: + case cv::ccm::DISTANCE_RGBL: p->initialLeastSquare(true); break; default: switch (p->initial_method_type) { - case cv::ccm::WHITE_BALANCE: + case cv::ccm::INITIAL_METHOD_WHITE_BALANCE: p->initialWhiteBalance(); break; - case cv::ccm::LEAST_SQUARE: + case cv::ccm::INITIAL_METHOD_LEAST_SQUARE: p->initialLeastSquare(); break; default: - throw std::invalid_argument { "Wrong initial_methoddistance_type!" }; + CV_Error(Error::StsBadArg, "Wrong initial_methoddistance_type!" ); break; } break; diff --git a/modules/mcc/src/color.cpp b/modules/mcc/src/color.cpp index 6c2bf536080..08da07f2a24 100644 --- a/modules/mcc/src/color.cpp +++ b/modules/mcc/src/color.cpp @@ -31,7 +31,7 @@ namespace cv { namespace ccm { Color::Color() : colors(Mat()) - , cs(*new ColorSpace()) + , cs(*std::make_shared()) {} Color::Color(Mat colors_, enum COLOR_SPACE cs_) : colors(colors_) @@ -111,19 +111,19 @@ Mat Color::diff(Color& other, IO io, DISTANCE_TYPE method) Lab lab = *Lab::get(io); switch (method) { - case cv::ccm::CIE76: - case cv::ccm::CIE94_GRAPHIC_ARTS: - case cv::ccm::CIE94_TEXTILES: - case cv::ccm::CIE2000: - case cv::ccm::CMC_1TO1: - case cv::ccm::CMC_2TO1: + case cv::ccm::DISTANCE_CIE76: + case cv::ccm::DISTANCE_CIE94_GRAPHIC_ARTS: + case cv::ccm::DISTANCE_CIE94_TEXTILES: + case cv::ccm::DISTANCE_CIE2000: + case cv::ccm::DISTANCE_CMC_1TO1: + case cv::ccm::DISTANCE_CMC_2TO1: return distance(to(lab).colors, other.to(lab).colors, method); - case cv::ccm::RGB: + case cv::ccm::DISTANCE_RGB: return distance(to(*cs.nl).colors, other.to(*cs.nl).colors, method); - case cv::ccm::RGBL: + case cv::ccm::DISTANCE_RGBL: return distance(to(*cs.l).colors, other.to(*cs.l).colors, method); default: - throw std::invalid_argument { "Wrong method!" }; + CV_Error(Error::StsBadArg, "Wrong method!" ); break; } } @@ -134,11 +134,11 @@ void Color::getGray(double JDN) { return; } - Mat lab = to(Lab_D65_2).colors; + Mat lab = to(COLOR_SPACE_Lab_D65_2).colors; Mat gray(colors.size(), colors.type()); int fromto[] = { 0, 0, -1, 1, -1, 2 }; mixChannels(&lab, 1, &gray, 1, fromto, 3); - Mat d = distance(lab, gray, CIE2000); + Mat d = distance(lab, gray, DISTANCE_CIE2000); this->grays = d < JDN; this->colored = ~grays; } @@ -368,26 +368,26 @@ std::shared_ptr GetColor::get_color(CONST_COLOR const_color) switch (const_color) { - case cv::ccm::Macbeth: + case cv::ccm::COLORCHECKER_Macbeth: { Mat ColorChecker2005_LAB_D50_2_ = GetColor::get_ColorChecker(*ColorChecker2005_LAB_D50_2, 24); Mat ColorChecker2005_COLORED_MASK_ = GetColor::get_ColorChecker_MASK(ColorChecker2005_COLORED_MASK, 24); - std::shared_ptr Macbeth_D50_2 = std::make_shared(ColorChecker2005_LAB_D50_2_, Lab_D50_2, ColorChecker2005_COLORED_MASK_); + std::shared_ptr Macbeth_D50_2 = std::make_shared(ColorChecker2005_LAB_D50_2_, COLOR_SPACE_Lab_D50_2, ColorChecker2005_COLORED_MASK_); return Macbeth_D50_2; } - case cv::ccm::Vinyl: + case cv::ccm::COLORCHECKER_Vinyl: { Mat Vinyl_LAB_D50_2__ = GetColor::get_ColorChecker(*Vinyl_LAB_D50_2, 18); Mat Vinyl_COLORED_MASK__ = GetColor::get_ColorChecker_MASK(Vinyl_COLORED_MASK, 18); - std::shared_ptr Vinyl_D50_2 = std::make_shared(Vinyl_LAB_D50_2__, Lab_D50_2, Vinyl_COLORED_MASK__); + std::shared_ptr Vinyl_D50_2 = std::make_shared(Vinyl_LAB_D50_2__, COLOR_SPACE_Lab_D50_2, Vinyl_COLORED_MASK__); return Vinyl_D50_2; } - case cv::ccm::DigitalSG: + case cv::ccm::COLORCHECKER_DigitalSG: { Mat DigitalSG_LAB_D50_2__ = GetColor::get_ColorChecker(*DigitalSG_LAB_D50_2, 140); - std::shared_ptr DigitalSG_D50_2 = std::make_shared(DigitalSG_LAB_D50_2__, Lab_D50_2); + std::shared_ptr DigitalSG_D50_2 = std::make_shared(DigitalSG_LAB_D50_2__, COLOR_SPACE_Lab_D50_2); return DigitalSG_D50_2; } } diff --git a/modules/mcc/src/color.hpp b/modules/mcc/src/color.hpp index 710bc5bfac4..8be475ba065 100644 --- a/modules/mcc/src/color.hpp +++ b/modules/mcc/src/color.hpp @@ -85,7 +85,7 @@ class Color @param method type of distance. @return distance between self and other */ - Mat diff(Color& other, DISTANCE_TYPE method = CIE2000); + Mat diff(Color& other, DISTANCE_TYPE method = DISTANCE_CIE2000); /** @brief Diff with IO. @param other type of Color. @@ -93,7 +93,7 @@ class Color @param method type of distance. @return distance between self and other */ - Mat diff(Color& other, IO io, DISTANCE_TYPE method = CIE2000); + Mat diff(Color& other, IO io, DISTANCE_TYPE method = DISTANCE_CIE2000); /** @brief Calculate gray mask. */ diff --git a/modules/mcc/src/colorspace.cpp b/modules/mcc/src/colorspace.cpp index 9d613f333dd..499676c7974 100644 --- a/modules/mcc/src/colorspace.cpp +++ b/modules/mcc/src/colorspace.cpp @@ -112,7 +112,6 @@ void RGBBase_::bind(RGBBase_& rgbl) } /* @brief Calculation of M_RGBL2XYZ_base. - * see ColorSpace.pdf for details. */ void RGBBase_::calM() { @@ -197,7 +196,6 @@ double sRGBBase_::toLFuncEW(double& x) } /* @brief Linearization. - * see ColorSpace.pdf for details. * @param rgb the input array, type of cv::Mat. * @return the output array, type of cv::Mat. */ @@ -226,7 +224,6 @@ double sRGBBase_::fromLFuncEW(double& x) } /* @brief Delinearization. - * see ColorSpace.pdf for details. * @param rgbl the input array, type of cv::Mat. * @return the output array, type of cv::Mat. */ @@ -353,9 +350,14 @@ void REC_2020_RGB_::setParameter() gamma = 1 / 0.45; } -/* @brief Enum of the possible types of CAMs. - */ - +static std::map, Mat> cams; +static const Mat Von_Kries = (Mat_(3, 3) << 0.40024, 0.7076, -0.08081, -0.2263, 1.16532, 0.0457, 0., 0., 0.91822); +static const Mat Bradford = (Mat_(3, 3) << 0.8951, 0.2664, -0.1614, -0.7502, 1.7135, 0.0367, 0.0389, -0.0685, 1.0296); +static const std::map> MAs = { + { IDENTITY, { Mat::eye(Size(3, 3), CV_64FC1), Mat::eye(Size(3, 3), CV_64FC1) } }, + { VON_KRIES, { Von_Kries, Von_Kries.inv() } }, + { BRADFORD, { Bradford, Bradford.inv() } } +}; /* @brief XYZ color space. * Chromatic adaption matrices. */ @@ -470,111 +472,111 @@ std::shared_ptr GetCS::get_rgb(enum COLOR_SPACE cs_name) { switch (cs_name) { - case cv::ccm::sRGB: + case cv::ccm::COLOR_SPACE_sRGB: { if (map_cs.count(cs_name) < 1) { std::shared_ptr sRGB_CS(new sRGB_(false)); std::shared_ptr sRGBL_CS(new sRGB_(true)); (*sRGB_CS).bind(*sRGBL_CS); - map_cs[sRGB] = sRGB_CS; - map_cs[sRGBL] = sRGBL_CS; + map_cs[COLOR_SPACE_sRGB] = sRGB_CS; + map_cs[COLOR_SPACE_sRGBL] = sRGBL_CS; } break; } - case cv::ccm::AdobeRGB: + case cv::ccm::COLOR_SPACE_AdobeRGB: { if (map_cs.count(cs_name) < 1) { std::shared_ptr AdobeRGB_CS(new AdobeRGB_(false)); std::shared_ptr AdobeRGBL_CS(new AdobeRGB_(true)); (*AdobeRGB_CS).bind(*AdobeRGBL_CS); - map_cs[AdobeRGB] = AdobeRGB_CS; - map_cs[AdobeRGBL] = AdobeRGBL_CS; + map_cs[COLOR_SPACE_AdobeRGB] = AdobeRGB_CS; + map_cs[COLOR_SPACE_AdobeRGBL] = AdobeRGBL_CS; } break; } - case cv::ccm::WideGamutRGB: + case cv::ccm::COLOR_SPACE_WideGamutRGB: { if (map_cs.count(cs_name) < 1) { std::shared_ptr WideGamutRGB_CS(new WideGamutRGB_(false)); std::shared_ptr WideGamutRGBL_CS(new WideGamutRGB_(true)); (*WideGamutRGB_CS).bind(*WideGamutRGBL_CS); - map_cs[WideGamutRGB] = WideGamutRGB_CS; - map_cs[WideGamutRGBL] = WideGamutRGBL_CS; + map_cs[COLOR_SPACE_WideGamutRGB] = WideGamutRGB_CS; + map_cs[COLOR_SPACE_WideGamutRGBL] = WideGamutRGBL_CS; } break; } - case cv::ccm::ProPhotoRGB: + case cv::ccm::COLOR_SPACE_ProPhotoRGB: { if (map_cs.count(cs_name) < 1) { std::shared_ptr ProPhotoRGB_CS(new ProPhotoRGB_(false)); std::shared_ptr ProPhotoRGBL_CS(new ProPhotoRGB_(true)); (*ProPhotoRGB_CS).bind(*ProPhotoRGBL_CS); - map_cs[ProPhotoRGB] = ProPhotoRGB_CS; - map_cs[ProPhotoRGBL] = ProPhotoRGBL_CS; + map_cs[COLOR_SPACE_ProPhotoRGB] = ProPhotoRGB_CS; + map_cs[COLOR_SPACE_ProPhotoRGBL] = ProPhotoRGBL_CS; } break; } - case cv::ccm::DCI_P3_RGB: + case cv::ccm::COLOR_SPACE_DCI_P3_RGB: { if (map_cs.count(cs_name) < 1) { std::shared_ptr DCI_P3_RGB_CS(new DCI_P3_RGB_(false)); std::shared_ptr DCI_P3_RGBL_CS(new DCI_P3_RGB_(true)); (*DCI_P3_RGB_CS).bind(*DCI_P3_RGBL_CS); - map_cs[DCI_P3_RGB] = DCI_P3_RGB_CS; - map_cs[DCI_P3_RGBL] = DCI_P3_RGBL_CS; + map_cs[COLOR_SPACE_DCI_P3_RGB] = DCI_P3_RGB_CS; + map_cs[COLOR_SPACE_DCI_P3_RGBL] = DCI_P3_RGBL_CS; } break; } - case cv::ccm::AppleRGB: + case cv::ccm::COLOR_SPACE_AppleRGB: { if (map_cs.count(cs_name) < 1) { std::shared_ptr AppleRGB_CS(new AppleRGB_(false)); std::shared_ptr AppleRGBL_CS(new AppleRGB_(true)); (*AppleRGB_CS).bind(*AppleRGBL_CS); - map_cs[AppleRGB] = AppleRGB_CS; - map_cs[AppleRGBL] = AppleRGBL_CS; + map_cs[COLOR_SPACE_AppleRGB] = AppleRGB_CS; + map_cs[COLOR_SPACE_AppleRGBL] = AppleRGBL_CS; } break; } - case cv::ccm::REC_709_RGB: + case cv::ccm::COLOR_SPACE_REC_709_RGB: { if (map_cs.count(cs_name) < 1) { std::shared_ptr REC_709_RGB_CS(new REC_709_RGB_(false)); std::shared_ptr REC_709_RGBL_CS(new REC_709_RGB_(true)); (*REC_709_RGB_CS).bind(*REC_709_RGBL_CS); - map_cs[REC_709_RGB] = REC_709_RGB_CS; - map_cs[REC_709_RGBL] = REC_709_RGBL_CS; + map_cs[COLOR_SPACE_REC_709_RGB] = REC_709_RGB_CS; + map_cs[COLOR_SPACE_REC_709_RGBL] = REC_709_RGBL_CS; } break; } - case cv::ccm::REC_2020_RGB: + case cv::ccm::COLOR_SPACE_REC_2020_RGB: { if (map_cs.count(cs_name) < 1) { std::shared_ptr REC_2020_RGB_CS(new REC_2020_RGB_(false)); std::shared_ptr REC_2020_RGBL_CS(new REC_2020_RGB_(true)); (*REC_2020_RGB_CS).bind(*REC_2020_RGBL_CS); - map_cs[REC_2020_RGB] = REC_2020_RGB_CS; - map_cs[REC_2020_RGBL] = REC_2020_RGBL_CS; + map_cs[COLOR_SPACE_REC_2020_RGB] = REC_2020_RGB_CS; + map_cs[COLOR_SPACE_REC_2020_RGBL] = REC_2020_RGBL_CS; } break; } - case cv::ccm::sRGBL: - case cv::ccm::AdobeRGBL: - case cv::ccm::WideGamutRGBL: - case cv::ccm::ProPhotoRGBL: - case cv::ccm::DCI_P3_RGBL: - case cv::ccm::AppleRGBL: - case cv::ccm::REC_709_RGBL: - case cv::ccm::REC_2020_RGBL: - CV_Error(Error::StsBadArg, "linear RGB colorspaces are not supported, you should assigned as normal rgb color space"); + case cv::ccm::COLOR_SPACE_sRGBL: + case cv::ccm::COLOR_SPACE_AdobeRGBL: + case cv::ccm::COLOR_SPACE_WideGamutRGBL: + case cv::ccm::COLOR_SPACE_ProPhotoRGBL: + case cv::ccm::COLOR_SPACE_DCI_P3_RGBL: + case cv::ccm::COLOR_SPACE_AppleRGBL: + case cv::ccm::COLOR_SPACE_REC_709_RGBL: + case cv::ccm::COLOR_SPACE_REC_2020_RGBL: + CV_Error(Error::StsBadArg, "linear RGB colorspaces are not supported, you should assigned as normal RGB color space"); break; default: @@ -587,180 +589,180 @@ std::shared_ptr GetCS::get_cs(enum COLOR_SPACE cs_name) { switch (cs_name) { - case cv::ccm::sRGB: - case cv::ccm::sRGBL: + case cv::ccm::COLOR_SPACE_sRGB: + case cv::ccm::COLOR_SPACE_sRGBL: { if (map_cs.count(cs_name) < 1) { std::shared_ptr sRGB_CS(new sRGB_(false)); std::shared_ptr sRGBL_CS(new sRGB_(true)); (*sRGB_CS).bind(*sRGBL_CS); - map_cs[sRGB] = sRGB_CS; - map_cs[sRGBL] = sRGBL_CS; + map_cs[COLOR_SPACE_sRGB] = sRGB_CS; + map_cs[COLOR_SPACE_sRGBL] = sRGBL_CS; } break; } - case cv::ccm::AdobeRGB: - case cv::ccm::AdobeRGBL: + case cv::ccm::COLOR_SPACE_AdobeRGB: + case cv::ccm::COLOR_SPACE_AdobeRGBL: { if (map_cs.count(cs_name) < 1) { std::shared_ptr AdobeRGB_CS(new AdobeRGB_(false)); std::shared_ptr AdobeRGBL_CS(new AdobeRGB_(true)); (*AdobeRGB_CS).bind(*AdobeRGBL_CS); - map_cs[AdobeRGB] = AdobeRGB_CS; - map_cs[AdobeRGBL] = AdobeRGBL_CS; + map_cs[COLOR_SPACE_AdobeRGB] = AdobeRGB_CS; + map_cs[COLOR_SPACE_AdobeRGBL] = AdobeRGBL_CS; } break; } - case cv::ccm::WideGamutRGB: - case cv::ccm::WideGamutRGBL: + case cv::ccm::COLOR_SPACE_WideGamutRGB: + case cv::ccm::COLOR_SPACE_WideGamutRGBL: { if (map_cs.count(cs_name) < 1) { std::shared_ptr WideGamutRGB_CS(new WideGamutRGB_(false)); std::shared_ptr WideGamutRGBL_CS(new WideGamutRGB_(true)); (*WideGamutRGB_CS).bind(*WideGamutRGBL_CS); - map_cs[WideGamutRGB] = WideGamutRGB_CS; - map_cs[WideGamutRGBL] = WideGamutRGBL_CS; + map_cs[COLOR_SPACE_WideGamutRGB] = WideGamutRGB_CS; + map_cs[COLOR_SPACE_WideGamutRGBL] = WideGamutRGBL_CS; } break; } - case cv::ccm::ProPhotoRGB: - case cv::ccm::ProPhotoRGBL: + case cv::ccm::COLOR_SPACE_ProPhotoRGB: + case cv::ccm::COLOR_SPACE_ProPhotoRGBL: { if (map_cs.count(cs_name) < 1) { std::shared_ptr ProPhotoRGB_CS(new ProPhotoRGB_(false)); std::shared_ptr ProPhotoRGBL_CS(new ProPhotoRGB_(true)); (*ProPhotoRGB_CS).bind(*ProPhotoRGBL_CS); - map_cs[ProPhotoRGB] = ProPhotoRGB_CS; - map_cs[ProPhotoRGBL] = ProPhotoRGBL_CS; + map_cs[COLOR_SPACE_ProPhotoRGB] = ProPhotoRGB_CS; + map_cs[COLOR_SPACE_ProPhotoRGBL] = ProPhotoRGBL_CS; } break; } - case cv::ccm::DCI_P3_RGB: - case cv::ccm::DCI_P3_RGBL: + case cv::ccm::COLOR_SPACE_DCI_P3_RGB: + case cv::ccm::COLOR_SPACE_DCI_P3_RGBL: { if (map_cs.count(cs_name) < 1) { std::shared_ptr DCI_P3_RGB_CS(new DCI_P3_RGB_(false)); std::shared_ptr DCI_P3_RGBL_CS(new DCI_P3_RGB_(true)); (*DCI_P3_RGB_CS).bind(*DCI_P3_RGBL_CS); - map_cs[DCI_P3_RGB] = DCI_P3_RGB_CS; - map_cs[DCI_P3_RGBL] = DCI_P3_RGBL_CS; + map_cs[COLOR_SPACE_DCI_P3_RGB] = DCI_P3_RGB_CS; + map_cs[COLOR_SPACE_DCI_P3_RGBL] = DCI_P3_RGBL_CS; } break; } - case cv::ccm::AppleRGB: - case cv::ccm::AppleRGBL: + case cv::ccm::COLOR_SPACE_AppleRGB: + case cv::ccm::COLOR_SPACE_AppleRGBL: { if (map_cs.count(cs_name) < 1) { std::shared_ptr AppleRGB_CS(new AppleRGB_(false)); std::shared_ptr AppleRGBL_CS(new AppleRGB_(true)); (*AppleRGB_CS).bind(*AppleRGBL_CS); - map_cs[AppleRGB] = AppleRGB_CS; - map_cs[AppleRGBL] = AppleRGBL_CS; + map_cs[COLOR_SPACE_AppleRGB] = AppleRGB_CS; + map_cs[COLOR_SPACE_AppleRGBL] = AppleRGBL_CS; } break; } - case cv::ccm::REC_709_RGB: - case cv::ccm::REC_709_RGBL: + case cv::ccm::COLOR_SPACE_REC_709_RGB: + case cv::ccm::COLOR_SPACE_REC_709_RGBL: { if (map_cs.count(cs_name) < 1) { std::shared_ptr REC_709_RGB_CS(new REC_709_RGB_(false)); std::shared_ptr REC_709_RGBL_CS(new REC_709_RGB_(true)); (*REC_709_RGB_CS).bind(*REC_709_RGBL_CS); - map_cs[REC_709_RGB] = REC_709_RGB_CS; - map_cs[REC_709_RGBL] = REC_709_RGBL_CS; + map_cs[COLOR_SPACE_REC_709_RGB] = REC_709_RGB_CS; + map_cs[COLOR_SPACE_REC_709_RGBL] = REC_709_RGBL_CS; } break; } - case cv::ccm::REC_2020_RGB: - case cv::ccm::REC_2020_RGBL: + case cv::ccm::COLOR_SPACE_REC_2020_RGB: + case cv::ccm::COLOR_SPACE_REC_2020_RGBL: { if (map_cs.count(cs_name) < 1) { std::shared_ptr REC_2020_RGB_CS(new REC_2020_RGB_(false)); std::shared_ptr REC_2020_RGBL_CS(new REC_2020_RGB_(true)); (*REC_2020_RGB_CS).bind(*REC_2020_RGBL_CS); - map_cs[REC_2020_RGB] = REC_2020_RGB_CS; - map_cs[REC_2020_RGBL] = REC_2020_RGBL_CS; + map_cs[COLOR_SPACE_REC_2020_RGB] = REC_2020_RGB_CS; + map_cs[COLOR_SPACE_REC_2020_RGBL] = REC_2020_RGBL_CS; } break; } - case cv::ccm::XYZ_D65_2: + case cv::ccm::COLOR_SPACE_XYZ_D65_2: return XYZ::get(IO::getIOs(D65_2)); break; - case cv::ccm::XYZ_D50_2: + case cv::ccm::COLOR_SPACE_XYZ_D50_2: return XYZ::get(IO::getIOs(D50_2)); break; - case cv::ccm::XYZ_D65_10: + case cv::ccm::COLOR_SPACE_XYZ_D65_10: return XYZ::get(IO::getIOs(D65_10)); break; - case cv::ccm::XYZ_D50_10: + case cv::ccm::COLOR_SPACE_XYZ_D50_10: return XYZ::get(IO::getIOs(D50_10)); break; - case cv::ccm::XYZ_A_2: + case cv::ccm::COLOR_SPACE_XYZ_A_2: return XYZ::get(IO::getIOs(A_2)); break; - case cv::ccm::XYZ_A_10: + case cv::ccm::COLOR_SPACE_XYZ_A_10: return XYZ::get(IO::getIOs(A_10)); break; - case cv::ccm::XYZ_D55_2: + case cv::ccm::COLOR_SPACE_XYZ_D55_2: return XYZ::get(IO::getIOs(D55_2)); break; - case cv::ccm::XYZ_D55_10: + case cv::ccm::COLOR_SPACE_XYZ_D55_10: return XYZ::get(IO::getIOs(D55_10)); break; - case cv::ccm::XYZ_D75_2: + case cv::ccm::COLOR_SPACE_XYZ_D75_2: return XYZ::get(IO::getIOs(D75_2)); break; - case cv::ccm::XYZ_D75_10: + case cv::ccm::COLOR_SPACE_XYZ_D75_10: return XYZ::get(IO::getIOs(D75_10)); break; - case cv::ccm::XYZ_E_2: + case cv::ccm::COLOR_SPACE_XYZ_E_2: return XYZ::get(IO::getIOs(E_2)); break; - case cv::ccm::XYZ_E_10: + case cv::ccm::COLOR_SPACE_XYZ_E_10: return XYZ::get(IO::getIOs(E_10)); break; - case cv::ccm::Lab_D65_2: + case cv::ccm::COLOR_SPACE_Lab_D65_2: return Lab::get(IO::getIOs(D65_2)); break; - case cv::ccm::Lab_D50_2: + case cv::ccm::COLOR_SPACE_Lab_D50_2: return Lab::get(IO::getIOs(D50_2)); break; - case cv::ccm::Lab_D65_10: + case cv::ccm::COLOR_SPACE_Lab_D65_10: return Lab::get(IO::getIOs(D65_10)); break; - case cv::ccm::Lab_D50_10: + case cv::ccm::COLOR_SPACE_Lab_D50_10: return Lab::get(IO::getIOs(D50_10)); break; - case cv::ccm::Lab_A_2: + case cv::ccm::COLOR_SPACE_Lab_A_2: return Lab::get(IO::getIOs(A_2)); break; - case cv::ccm::Lab_A_10: + case cv::ccm::COLOR_SPACE_Lab_A_10: return Lab::get(IO::getIOs(A_10)); break; - case cv::ccm::Lab_D55_2: + case cv::ccm::COLOR_SPACE_Lab_D55_2: return Lab::get(IO::getIOs(D55_2)); break; - case cv::ccm::Lab_D55_10: + case cv::ccm::COLOR_SPACE_Lab_D55_10: return Lab::get(IO::getIOs(D55_10)); break; - case cv::ccm::Lab_D75_2: + case cv::ccm::COLOR_SPACE_Lab_D75_2: return Lab::get(IO::getIOs(D75_2)); break; - case cv::ccm::Lab_D75_10: + case cv::ccm::COLOR_SPACE_Lab_D75_10: return Lab::get(IO::getIOs(D75_10)); break; - case cv::ccm::Lab_E_2: + case cv::ccm::COLOR_SPACE_Lab_E_2: return Lab::get(IO::getIOs(E_2)); break; - case cv::ccm::Lab_E_10: + case cv::ccm::COLOR_SPACE_Lab_E_10: return Lab::get(IO::getIOs(E_10)); break; default: diff --git a/modules/mcc/src/colorspace.hpp b/modules/mcc/src/colorspace.hpp index c4859d97bed..38c2e255b6f 100644 --- a/modules/mcc/src/colorspace.hpp +++ b/modules/mcc/src/colorspace.hpp @@ -112,7 +112,6 @@ class RGBBase_ : public ColorSpace virtual void setParameter() {}; /** @brief Calculation of M_RGBL2XYZ_base. - see ColorSpace.pdf for details. */ virtual void calM(); @@ -157,7 +156,6 @@ class sRGBBase_ : public RGBBase_ private: /** @brief linearization parameters - see ColorSpace.pdf for details; */ virtual void calLinear() CV_OVERRIDE; /** @brief Used by toLFunc. @@ -165,7 +163,6 @@ class sRGBBase_ : public RGBBase_ double toLFuncEW(double& x); /** @brief Linearization. - see ColorSpace.pdf for details. @param rgb the input array, type of cv::Mat. @return the output array, type of cv::Mat. */ @@ -176,7 +173,6 @@ class sRGBBase_ : public RGBBase_ double fromLFuncEW(double& x); /** @brief Delinearization. - see ColorSpace.pdf for details. @param rgbl the input array, type of cv::Mat. @return the output array, type of cv::Mat. */ @@ -297,14 +293,14 @@ enum CAM BRADFORD }; -static std::map, Mat> cams; -static const Mat Von_Kries = (Mat_(3, 3) << 0.40024, 0.7076, -0.08081, -0.2263, 1.16532, 0.0457, 0., 0., 0.91822); -static const Mat Bradford = (Mat_(3, 3) << 0.8951, 0.2664, -0.1614, -0.7502, 1.7135, 0.0367, 0.0389, -0.0685, 1.0296); -static const std::map> MAs = { - { IDENTITY, { Mat::eye(Size(3, 3), CV_64FC1), Mat::eye(Size(3, 3), CV_64FC1) } }, - { VON_KRIES, { Von_Kries, Von_Kries.inv() } }, - { BRADFORD, { Bradford, Bradford.inv() } } -}; +// static std::map, Mat> cams; +// static const Mat Von_Kries = (Mat_(3, 3) << 0.40024, 0.7076, -0.08081, -0.2263, 1.16532, 0.0457, 0., 0., 0.91822); +// static const Mat Bradford = (Mat_(3, 3) << 0.8951, 0.2664, -0.1614, -0.7502, 1.7135, 0.0367, 0.0389, -0.0685, 1.0296); +// static const std::map> MAs = { +// { IDENTITY, { Mat::eye(Size(3, 3), CV_64FC1), Mat::eye(Size(3, 3), CV_64FC1) } }, +// { VON_KRIES, { Von_Kries, Von_Kries.inv() } }, +// { BRADFORD, { Bradford, Bradford.inv() } } +// }; /** @brief XYZ color space. Chromatic adaption matrices. @@ -328,11 +324,6 @@ class XYZ : public ColorSpace Mat cam_(IO sio, IO dio, CAM method = BRADFORD) const; }; -/** @brief Define XYZ_D65_2 and XYZ_D50_2. -*/ -const XYZ XYZ_D65_2_CS(IO::getIOs(D65_2)); -const XYZ XYZ_D50_2_CS(IO::getIOs(D50_2)); - /** @brief Lab color space. */ class Lab : public ColorSpace @@ -365,11 +356,6 @@ class Lab : public ColorSpace Mat tosrc(Mat& src); }; -/** @brief Define Lab_D65_2 and Lab_D50_2. -*/ -const Lab Lab_D65_2_CS(IO::getIOs(D65_2)); -const Lab Lab_D50_2_CS(IO::getIOs(D50_2)); - class GetCS { public: diff --git a/modules/mcc/src/distance.cpp b/modules/mcc/src/distance.cpp index cd6738259b5..fa535b88477 100644 --- a/modules/mcc/src/distance.cpp +++ b/modules/mcc/src/distance.cpp @@ -196,24 +196,24 @@ Mat distance(Mat src, Mat ref, DISTANCE_TYPE distance_type) { switch (distance_type) { - case cv::ccm::CIE76: + case cv::ccm::DISTANCE_CIE76: return distanceWise(src, ref, deltaCIE76); - case cv::ccm::CIE94_GRAPHIC_ARTS: + case cv::ccm::DISTANCE_CIE94_GRAPHIC_ARTS: return distanceWise(src, ref, deltaCIE94GraphicArts); - case cv::ccm::CIE94_TEXTILES: + case cv::ccm::DISTANCE_CIE94_TEXTILES: return distanceWise(src, ref, deltaCIE94Textiles); - case cv::ccm::CIE2000: + case cv::ccm::DISTANCE_CIE2000: return distanceWise(src, ref, deltaCIEDE2000); - case cv::ccm::CMC_1TO1: + case cv::ccm::DISTANCE_CMC_1TO1: return distanceWise(src, ref, deltaCMC1To1); - case cv::ccm::CMC_2TO1: + case cv::ccm::DISTANCE_CMC_2TO1: return distanceWise(src, ref, deltaCMC2To1); - case cv::ccm::RGB: + case cv::ccm::DISTANCE_RGB: return distanceWise(src, ref, deltaCIE76); - case cv::ccm::RGBL: + case cv::ccm::DISTANCE_RGBL: return distanceWise(src, ref, deltaCIE76); default: - throw std::invalid_argument { "Wrong distance_type!" }; + CV_Error(Error::StsBadArg, "Wrong distance_type!" ); break; } }; diff --git a/modules/mcc/src/linearize.cpp b/modules/mcc/src/linearize.cpp index 02f221ef394..3a48a560eb8 100644 --- a/modules/mcc/src/linearize.cpp +++ b/modules/mcc/src/linearize.cpp @@ -101,26 +101,26 @@ std::shared_ptr getLinear(double gamma, int deg, Mat src, Color dst, Mat std::shared_ptr p = std::make_shared(); switch (linear_type) { - case cv::ccm::IDENTITY_: + case cv::ccm::LINEARIZATION_IDENTITY: p.reset(new LinearIdentity()); break; - case cv::ccm::GAMMA: + case cv::ccm::LINEARIZATION_GAMMA: p.reset(new LinearGamma(gamma)); break; - case cv::ccm::COLORPOLYFIT: + case cv::ccm::LINEARIZATION_COLORPOLYFIT: p.reset(new LinearColor(deg, src, dst, mask, cs)); break; - case cv::ccm::COLORLOGPOLYFIT: + case cv::ccm::LINEARIZATION_COLORLOGPOLYFIT: p.reset(new LinearColor(deg, src, dst, mask, cs)); break; - case cv::ccm::GRAYPOLYFIT: + case cv::ccm::LINEARIZATION_GRAYPOLYFIT: p.reset(new LinearGray(deg, src, dst, mask, cs)); break; - case cv::ccm::GRAYLOGPOLYFIT: + case cv::ccm::LINEARIZATION_GRAYLOGPOLYFIT: p.reset(new LinearGray(deg, src, dst, mask, cs)); break; default: - throw std::invalid_argument { "Wrong linear_type!" }; + CV_Error(Error::StsBadArg, "Wrong linear_type!" ); break; } return p; diff --git a/modules/mcc/src/linearize.hpp b/modules/mcc/src/linearize.hpp index e762ee4b702..a703b5c5293 100644 --- a/modules/mcc/src/linearize.hpp +++ b/modules/mcc/src/linearize.hpp @@ -48,7 +48,6 @@ class Polyfit https://en.wikipedia.org/wiki/Polynomial_regression polynomial: yi = a0 + a1*xi + a2*xi^2 + ... + an*xi^deg (i = 1,2,...,n) and deduct: Ax = y - See linear.pdf for details */ Polyfit(Mat x, Mat y, int deg); virtual ~Polyfit() {}; diff --git a/modules/mcc/src/operations.hpp b/modules/mcc/src/operations.hpp index db7bd7441de..475ffcc9eeb 100644 --- a/modules/mcc/src/operations.hpp +++ b/modules/mcc/src/operations.hpp @@ -76,7 +76,6 @@ class Operations { public: std::vector ops; - Operations() : ops {} {}; Operations(std::initializer_list op) @@ -92,7 +91,8 @@ class Operations Mat run(Mat abc); static Operations get_IDENTITY_OPS() { - return Operations { Operation::get_IDENTITY_OP() }; + Operation Operation_op = Operation::get_IDENTITY_OP(); + return Operations { Operation_op }; } }; diff --git a/modules/mcc/src/utils.cpp b/modules/mcc/src/utils.cpp index 1bfc4204598..3a0128b6ef6 100644 --- a/modules/mcc/src/utils.cpp +++ b/modules/mcc/src/utils.cpp @@ -76,7 +76,7 @@ Mat maskCopyTo(const Mat& src, const Mat& mask) break; } default: - throw std::invalid_argument { "Wrong channel!" }; + CV_Error(Error::StsBadArg, "Wrong channel!" ); break; } return dst; diff --git a/modules/mcc/src/utils.hpp b/modules/mcc/src/utils.hpp index a9810a017df..02570ca0184 100644 --- a/modules/mcc/src/utils.hpp +++ b/modules/mcc/src/utils.hpp @@ -35,7 +35,7 @@ namespace ccm { double gammaCorrection_(const double& element, const double& gamma); -/** @brief gamma correction ,see ColorSpace.pdf for details. +/** @brief gamma correction. \f[ C_l=C_n^{\gamma},\qquad C_n\ge0\\ C_l=-(-C_n)^{\gamma},\qquad C_n<0\\\\ @@ -67,7 +67,7 @@ Mat multiple(const Mat& xyz, const Mat& ccm); Mat saturate(Mat& src, const double& low, const double& up); /** @brief rgb2gray it is an approximation grayscale function for relative RGB - color space, see Miscellaneous.pdf for details; + color space @param rgb the input array,type of Mat. */ Mat rgb2gray(const Mat& rgb); @@ -106,7 +106,7 @@ Mat elementWise(const Mat& src, F&& lambda) break; } default: - throw std::invalid_argument { "Wrong channel!" }; + CV_Error(Error::StsBadArg, "Wrong channel!" ); break; } return dst; diff --git a/modules/mcc/tutorials/basic_ccm/color_correction_model.markdown b/modules/mcc/tutorials/basic_ccm/color_correction_model.markdown index 3b8ed663241..ac510cf36ea 100644 --- a/modules/mcc/tutorials/basic_ccm/color_correction_model.markdown +++ b/modules/mcc/tutorials/basic_ccm/color_correction_model.markdown @@ -51,48 +51,48 @@ Here are the parameters for ColorCorrectionModel If the color type is some RGB, the format is RGB not BGR; Supported Color Space: Supported list of RGB color spaces: - sRGB; - AdobeRGB; - WideGamutRGB; - ProPhotoRGB; - DCI_P3_RGB; - AppleRGB; - REC_709_RGB; - REC_2020_RGB; + COLOR_SPACE_sRGB; + COLOR_SPACE_AdobeRGB; + COLOR_SPACE_WideGamutRGB; + COLOR_SPACE_ProPhotoRGB; + COLOR_SPACE_DCI_P3_RGB; + COLOR_SPACE_AppleRGB; + COLOR_SPACE_REC_709_RGB; + COLOR_SPACE_REC_2020_RGB; Supported list of linear RGB color spaces: - sRGBL; - AdobeRGBL; - WideGamutRGBL; - ProPhotoRGBL; - DCI_P3_RGBL; - AppleRGBL; - REC_709_RGBL; - REC_2020_RGBL; + COLOR_SPACE_sRGBL; + COLOR_SPACE_AdobeRGBL; + COLOR_SPACE_WideGamutRGBL; + COLOR_SPACE_ProPhotoRGBL; + COLOR_SPACE_DCI_P3_RGBL; + COLOR_SPACE_AppleRGBL; + COLOR_SPACE_REC_709_RGBL; + COLOR_SPACE_REC_2020_RGBL; Supported list of non-RGB color spaces: - Lab_D50_2; - Lab_D65_2; - XYZ_D50_2; - XYZ_D65_2; - XYZ_D65_10; - XYZ_D50_10; - XYZ_A_2; - XYZ_A_10; - XYZ_D55_2; - XYZ_D55_10; - XYZ_D75_2; - XYZ_D75_10; - XYZ_E_2; - XYZ_E_10; - Lab_D65_10; - Lab_D50_10; - Lab_A_2; - Lab_A_10; - Lab_D55_2; - Lab_D55_10; - Lab_D75_2; - Lab_D75_10; - Lab_E_2; - Lab_E_10; + COLOR_SPACE_Lab_D50_2; + COLOR_SPACE_Lab_D65_2; + COLOR_SPACE_XYZ_D50_2; + COLOR_SPACE_XYZ_D65_2; + COLOR_SPACE_XYZ_D65_10; + COLOR_SPACE_XYZ_D50_10; + COLOR_SPACE_XYZ_A_2; + COLOR_SPACE_XYZ_A_10; + COLOR_SPACE_XYZ_D55_2; + COLOR_SPACE_XYZ_D55_10; + COLOR_SPACE_XYZ_D75_2; + COLOR_SPACE_XYZ_D75_10; + COLOR_SPACE_XYZ_E_2; + COLOR_SPACE_XYZ_E_10; + COLOR_SPACE_Lab_D65_10; + COLOR_SPACE_Lab_D50_10; + COLOR_SPACE_Lab_A_2; + COLOR_SPACE_Lab_A_10; + COLOR_SPACE_Lab_D55_2; + COLOR_SPACE_Lab_D55_10; + COLOR_SPACE_Lab_D75_2; + COLOR_SPACE_Lab_D75_10; + COLOR_SPACE_Lab_E_2; + COLOR_SPACE_Lab_E_10; ```