-
Notifications
You must be signed in to change notification settings - Fork 598
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
[feat]IBA:demosaic add white balancing #4499
base: main
Are you sure you want to change the base?
[feat]IBA:demosaic add white balancing #4499
Conversation
Signed-off-by: Anton Dukhovnikov <[email protected]>
Signed-off-by: Anton Dukhovnikov <[email protected]>
Signed-off-by: Anton Dukhovnikov <[email protected]>
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.
This LGTM. It's still marked as "draft". Is it ready to be reviewed and merged?
Hi Larry, if you're happy with the code, I just need to update the docs and add some tests. I've also just realised we could add an "auto" or "meta" value to the Bayer layout and white balance parameters, which would pull the values from the ImageBuf attributes. |
I'm happy with the code. Docs+tests should take it over the finish line. I'm not quite sure what you mean about the ImageBuf attributes? Do you mean that when the image is read in, you expect the raw reader would drop hints in the spec about the default white balancing method to use, so IBA::demosaic should honor that if it gets no other overriding instructions? Or did you mean something different? |
Yep, exactly that. The raw reader currently adds the "raw:FilterPattern" attribute to the output when asked not to debayer. We could do something similar for white balancing. We can leave this for later, as adding an auto white balancing mode should not change the default behaviour, I think. If we were to add the "auto" layout pattern, it should become the default, as the current default behaviour is to assume RGGB. This is beyond the scope of this change though. I'll update the docs, tests and the python bindings. |
Signed-off-by: Anton Dukhovnikov <[email protected]>
Signed-off-by: Anton Dukhovnikov <[email protected]>
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.
Also, I think before this is ready to merge, we will need the docs to be updated for all of C++ (imagebufalgo.h), Python (pythonbindings.rst), and oiiotool (oiiotool.rst), to explain the new parameters.
float wb[4] = {2.0, 0.8, 1.2, 1.5}; | ||
ParamValue options[] = { | ||
{ "layout", "GRBG" }, | ||
ParamValue("white-balance", TypeFloat, 4, wb) | ||
}; |
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 requesting this as part of this PR, but just noting that at some point, we should do the thing where we move these actual code snippets to the appropriate parts of testsuite/docs-examples-cpp and testsuite/docs-examples-python, and then just include them by reference in the docs, so that it is confirmed that they compile and work correct with every CI run.
src/oiiotool/oiiotool.cpp
Outdated
string_view str(wb); | ||
float white_balance[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; | ||
if (str.size() && Strutil::parse_float(str, white_balance[0]) | ||
&& Strutil::parse_char(str, ',') | ||
&& Strutil::parse_float(str, white_balance[1]) | ||
&& Strutil::parse_char(str, ',') | ||
&& Strutil::parse_float(str, white_balance[2]) | ||
&& Strutil::parse_char(str, ',') | ||
&& Strutil::parse_float(str, white_balance[3])) { |
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.
I think there is a more compact alternative, and also more correct, because it will fail if the string contains any extra non-whitespace after the 4th value.
string_view str(wb); | |
float white_balance[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; | |
if (str.size() && Strutil::parse_float(str, white_balance[0]) | |
&& Strutil::parse_char(str, ',') | |
&& Strutil::parse_float(str, white_balance[1]) | |
&& Strutil::parse_char(str, ',') | |
&& Strutil::parse_float(str, white_balance[2]) | |
&& Strutil::parse_char(str, ',') | |
&& Strutil::parse_float(str, white_balance[3])) { | |
string_view str(wb); | |
Strutil::remove_trailing_whitespace(str); | |
float white_balance[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; | |
if (Strutil::parse_values(str, "", white_balance, ",") && str.size()) { |
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've also decided to allow 3 values, for RGB, and extend them to RGGB automatically.
src/python/py_imagebufalgo.cpp
Outdated
"wb_r"_a = 1.0f, "wb_g1"_a = 1.0f, "wb_g2"_a = 1.0f, | ||
"wb_b"_a = 1.0f, "roi"_a = ROI::All(), "nthreads"_a = 0) |
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.
This part, I'm not so sure about. Would it be better to pass white_balance as one parameter that expects a tuple or array (checked to be 4 floats), versus 4 separate float parameters?
I don't have a strong feeling one way or the other. I'm just wondering if that would be more symmetric with the C++ API, and/or more idiomatic for a Python native speaker?
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.
I've changed that to use tuples, seems to be more inline with other python bindings
Signed-off-by: Anton Dukhovnikov <[email protected]>
Signed-off-by: Anton Dukhovnikov <[email protected]>
Signed-off-by: Anton Dukhovnikov <[email protected]>
/// - "white-balance" : float[3] or float[4] (default: {1.0, 1.0, 1.0, 1.0}) | ||
/// | ||
/// Optional white-balancing weights. Can contain either three (RGB), or four (RGGB) values. |
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.
Is there a use case for specifying two green values?
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.
Yes, I have seen some images recently with the greens in red and blue rows having distinctly different levels. Sony A99, I think.
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.
Is there a use case for specifying two green values?
RAW_PENTAX_K200D.PEF in the test suite has 2 different weights for the green sub-channels
I'm confused about the white balance values.
|
Co-authored-by: Larry Gritz <[email protected]> Signed-off-by: Anton Dukhovnikov <[email protected]>
Co-authored-by: Larry Gritz <[email protected]> Signed-off-by: Anton Dukhovnikov <[email protected]>
Hi Larry, I've been mostly following exiftool, which shows WB as either RGB or RGGB, regardless of the layout:
Libraw stores the weights as RGBG, regardless of the layout. I find the RGGB easier to understand, because the order also represents a valid Bayer layout, so it is clear where each G sits. |
Great, precedence from another widely used tool is a good reason for doing it a particular way. |
Description
Adds white balancing functionality to IBA:demosaic
Tests
Updated unittests
Checklist:
need to update the documentation, for example if this is a bug fix that
doesn't change the API.)
(adding new test cases if necessary).
corresponding Python bindings (and if altering ImageBufAlgo functions, also
exposed the new functionality as oiiotool options).
already run clang-format before submitting, I definitely will look at the CI
test that runs clang-format and fix anything that it highlights as being
nonconforming.