-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Color Calibration Algorithm Implementation Revised #2671
Conversation
Fix the error whitespace and 'EOF' on the docs.
Implement color distance.
Co-authored-by: Chenqi Shan <[email protected]>
Co-authored-by: Chenqi Shan <[email protected]>
df58817
to
75f100c
Compare
Refer ccm.hpp in entrypoint header and update realted refs in sampe & tutorial
75f100c
to
7d133a0
Compare
move <iostream> and add getloss() method for class ColorCorrection Model
update sample/color_correction_model.cpp
add getIOs() function for minimize initialization of IO variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enum LINEAR_TYPE | ||
{ | ||
IDENTITY_, | ||
GAMMA, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enum values are propagated into namespaces.
So it is better to add prefixes to its values, like LINEARIZATION_IDENTITY
P.S. There is enum class
in C++ 11, but it is still not supported by OpenCV bindings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I have added prefixes for Enum values.
CMC_1TO1, ///< In 1984, the Colour Measurement Committee of the Society of Dyers and Colourists defined a difference measure, also based on the L*C*h color model. | ||
CMC_2TO1, | ||
RGB, | ||
RGBL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use prefixes too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Supported list of color cards: | ||
- @ref Macbeth (Macbeth ColorChecker) | ||
- @ref Vinyl (DKK ColorChecker) | ||
- @ref DigitalSG (DigitalSG ColorChecker with 140 squares) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move "Supported list" out of params or just add reference to enum (use @ref CONST_COLOR
for that).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I got it.
the color type is RGB not BGR, and the color values are in [0, 1]; | ||
@param colors the reference color values,the color values are in [0, 1].\n | ||
@param ref_cs the corresponding color space | ||
NOTICE: For the list of color spaces supported, see the notes above;\n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see the notes above
It is unclear from documentation page which notes are mentioned here
Supported list: | ||
- @ref CIE2000 | ||
- @ref CIE94_GRAPHIC_ARTS | ||
- @ref CIE94_TEXTILES | ||
- @ref CIE76 | ||
- @ref CMC_1TO1 | ||
- @ref CMC_2TO1 | ||
- @ref RGB (Euclidean distance of rgb color space) | ||
- @ref RGBL (Euclidean distance of rgbl color space) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure that it is a good idea to duplicate enum values.
Just reference on enum type is enough.
Additionally it make sense to notice about some exclusions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I think you are right, and I removed enum values from the supported list only if it is necessary.
modules/mcc/src/colorspace.hpp
Outdated
static std::map<std::tuple<IO, IO, CAM>, Mat> cams; | ||
static const Mat Von_Kries = (Mat_<double>(3, 3) << 0.40024, 0.7076, -0.08081, -0.2263, 1.16532, 0.0457, 0., 0., 0.91822); | ||
static const Mat Bradford = (Mat_<double>(3, 3) << 0.8951, 0.2664, -0.1614, -0.7502, 1.7135, 0.0367, 0.0389, -0.0685, 1.0296); | ||
static const std::map<CAM, std::vector<Mat>> 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() } } | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reduce initialization of global variables.
Wrap them into functions with "static" variables (functions should return const references).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, I moved it into the function which uses these variables.
modules/mcc/src/operations.hpp
Outdated
/** @brief run operations to make color conversion | ||
*/ | ||
Mat run(Mat abc); | ||
static Operations get_IDENTITY_OPS() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return reference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
modules/mcc/src/color.cpp
Outdated
namespace ccm { | ||
Color::Color() | ||
: colors(Mat()) | ||
, cs(*new ColorSpace()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add tests which covers added functionality.
Looks like we have memory leak here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I have added test files and used share_ptr for Color( ).
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation is broken in this place (blames on undefined control sequence \infin
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I fixed this issue using \infty.
update sample --help
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Please apply left cosmetic changes and we ready for merge.
CV_WRAP Mat get_src_rgbl() const; | ||
CV_WRAP Mat get_dst_rgbl() const; | ||
CV_WRAP Mat get_mask() const; | ||
CV_WRAP Mat get_weights() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow OpenCV naming convention rules: https://github.com/opencv/opencv/wiki/Coding_Style_Guide#naming-conventions
get_weights() => getWeights()
Also it probably make sense to change return value Mat => const Mat&
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reviewing the codes. We are encouraged. We renamed functions under OpenCV rules such as getColor() and getMask().
Note that the parameter of $ln$ cannot be 0. | ||
Therefore, we need to delete the channels whose values are 0 from $R_s$ and $R_{dl}$, $G_s$ and $G_{dl}$, $B_s$ and $B_{dl}$. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look on this part.
It looks broken in documentation.
And several other places, look for $
symbol on documentation page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, we fixed the issue and removed $
.
@ref LINEARIZATION_COLORPOLYFIT | ||
@ref LINEARIZATION_GRAYPOLYFIT | ||
@ref LINEARIZATION_COLORLOGPOLYFIT | ||
@ref LINEARIZATION_GRAYLOGPOLYFIT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please extract "valid" list out of @param
section (see setColorSpace
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK!
@param upper the upper threshold to determine saturation; | ||
NOTICE: it is a tuple of [lower, upper]; | ||
The colors in the closed interval [lower, upper] are reserved to participate | ||
in the calculation of the loss function and initialization parameters\n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like notice is related for both parameters. It make sense to put this description as method body.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done! Thank you for contribution 👍
Thanks for your recognition, we will make more contributions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why removing exposition to colorspace conversions and distances ?
Would be great to have those functions in this module.
OpenCV's cvtcolor can't convert from sRGB to CIELAB D50 2°.
Revise a new PR with branch named 'color-calibration', based on the discussion at: #2653
Color calibration algorithm of OE.30. https://github.com/opencv/opencv/wiki/OE-30.-Color-Calibration
Algorithm struct and other details: https://github.com/riskiest/color_calibration/tree/v4/doc/pdf/English/Algorithm
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.