Skip to content
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

Merged
merged 92 commits into from
Nov 23, 2020

Conversation

riskiest
Copy link
Contributor

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

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake
force_builders=linux,Docs,Win64,Mac,Win32,android,ios

Chenqi Shan and others added 25 commits August 31, 2020 04:04
Fix the error whitespace and 'EOF' on the docs.
Implement color distance.
Refer ccm.hpp in entrypoint header and update realted refs in sampe & tutorial
riskiest and others added 5 commits November 17, 2020 19:32
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
@riskiest riskiest requested a review from alalek November 19, 2020 03:04
Copy link
Member

@alalek alalek left a 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 generated documentation pages:

I added commits with changes in public documentation and clang-format for added sources.

enum LINEAR_TYPE
{
IDENTITY_,
GAMMA,
Copy link
Member

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.

Copy link
Contributor

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use prefixes too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 364 to 367
Supported list of color cards:
- @ref Macbeth (Macbeth ColorChecker)
- @ref Vinyl (DKK ColorChecker)
- @ref DigitalSG (DigitalSG ColorChecker with 140 squares)
Copy link
Member

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).

Copy link
Contributor

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
Copy link
Member

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

Comment on lines 414 to 422
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)
Copy link
Member

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.

Copy link
Contributor

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.

Comment on lines 300 to 308
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() } }
};

Copy link
Member

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).

Copy link
Contributor

@shanchenqi shanchenqi Nov 20, 2020

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.

/** @brief run operations to make color conversion
*/
Mat run(Mat abc);
static Operations get_IDENTITY_OPS()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return reference

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

namespace ccm {
Color::Color()
: colors(Mat())
, cs(*new ColorSpace())
Copy link
Member

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.

Copy link
Contributor

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.
Copy link
Member

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)

Copy link
Contributor

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.

@riskiest riskiest requested a review from alalek November 22, 2020 04:31
Copy link
Member

@alalek alalek left a 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.

Comment on lines 501 to 504
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;
Copy link
Member

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&

Copy link
Contributor

@shanchenqi shanchenqi Nov 23, 2020

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().

Comment on lines 305 to 306
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}$.
Copy link
Member

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.

Copy link
Contributor

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
Copy link
Member

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).

Copy link
Contributor

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
Copy link
Member

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Member

@alalek alalek left a 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 👍

@alalek alalek merged commit 478cc12 into opencv:master Nov 23, 2020
@shanchenqi
Copy link
Contributor

Thanks for your recognition, we will make more contributions.

@alalek alalek mentioned this pull request Nov 27, 2020
Copy link
Contributor

@kevineor kevineor left a 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°.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: mcc color calibration module feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants