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

feat(oiiotool): oiiotool new expression eval tokens IS_CONSTANT, IS_BLACK #4610

Merged

Conversation

lydia-zheng
Copy link
Contributor

Description

Included two additional metadata boolean checks for constant and black frame images, so that handling for those image cases are facilitated.

IS_CONSTANT and IS_BLACK return 1 when true, and 0 when false.

Tests

No new tests added to testsuite for now, but tested with local build copy of oiiotool and test images to ensure it behaved as expected.

Checklist:

  • I have read the contribution guidelines.
  • I have updated the documentation, if applicable. (Check if there is no
    need to update the documentation, for example if this is a bug fix that
    doesn't change the API.)
  • I have ensured that the change is tested somewhere in the testsuite
    (adding new test cases if necessary).
  • If I added or modified a C++ API call, I have also amended the
    corresponding Python bindings (and if altering ImageBufAlgo functions, also
    exposed the new functionality as oiiotool options).
  • My code follows the prevailing code style of this project. If I haven't
    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.


} else if (metadata == "IS_CONSTANT") {
std::vector<float> color((*img)(0, 0).nchannels());
if (ImageBufAlgo::isConstantColor((*img)(0, 0), color)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is not quite correct for the declaration of isConstantColor. I believe you want

Suggested change
if (ImageBufAlgo::isConstantColor((*img)(0, 0), color)) {
if (ImageBufAlgo::isConstantColor((*img)(0, 0), 0.0f, color)) {

The 2nd parameter is the threshold amount (0.0f would mean a "true constant", exact same value everywhere), and the 3rd parameter is the place to store the constant value it finds.

Copy link
Collaborator

@lgritz lgritz left a comment

Choose a reason for hiding this comment

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

Great feature addition, Lydia. I made a few comments, I think there is a logic error here, but it should all be an easy fix for you.

auto pixstat = ImageBufAlgo::computePixelStats((*img)(0, 0));
std::vector<float> color((*img)(0, 0).nchannels());
// Check constant first to guard against false positive average of 0 with negative values i.e. -2, 1, 1
if (ImageBufAlgo::isConstantColor((*img)(0, 0), color)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (ImageBufAlgo::isConstantColor((*img)(0, 0), color)) {
if (ImageBufAlgo::isConstantColor((*img)(0, 0), 0.0f, color)) {



} else if (metadata == "IS_BLACK") {
auto pixstat = ImageBufAlgo::computePixelStats((*img)(0, 0));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think you need to call computePixelStats. You can save the expense, since you are calling isConstantColor() and that will deposit the constant color it finds into color, then you can just check if the values of color[0..nchans-1] are all 0.0f to know if it's black.

Comment on lines 336 to 339
for (size_t i = 0; i < pixstat.avg.size(); ++i) {
// If any of the pixel doesn't have an average of (0,0,0), then we don't have a black frame
// Is this the best way to check? Feels fishy to have the specified number...should we look at 0.0f or other formats?
if (pixstat.avg[i] == 0.000000) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

0.0f is sufficient. But you don't need to look at the image's average color -- you can just use color[0] since isConstantColor returns that constant color.

Comment on lines 340 to 342
result = "1";
} else {
result = "0";
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this logic is incorrect. Doesn't this end up setting result based solely on whether the LAST channel is black or not? You want the result to be "0" if any channel is not black, right?

@lydia-zheng
Copy link
Contributor Author

Great feature addition, Lydia. I made a few comments, I think there is a logic error here, but it should all be an easy fix for you.

Thank you so much for taking such a thorough look, Larry!
Seeing all the comments and reading them over now.
Some of these are definitely what I was suspecting I got wrong, glad it's confirmed and I'll start looking into the fix in my free cycles :D

@lgritz lgritz changed the title Feat black constant frames feat(oiiotool): oiiotool new expression eval tokens IS_CONSTANT, IS_BLACK Feb 1, 2025
@lgritz lgritz added enhancement Improvement of existing/working features. oiiotool oiiotool labels Feb 1, 2025
@lydia-zheng lydia-zheng force-pushed the feat_black_constant_frames branch from a55baa0 to 9efbfd5 Compare February 10, 2025 22:22
@lydia-zheng
Copy link
Contributor Author

Hi @lgritz !

Took another jab at this with your amazing feedback, and fixed the feedstock/git commits such that CLs are all green.

Let me know if this is good to merge or if the new logic still looks off!

Copy link
Collaborator

@lgritz lgritz left a comment

Choose a reason for hiding this comment

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

LGTM, thanks Lydia. Ready to merge.

Signed-off-by: Larry Gritz <[email protected]>
@lgritz lgritz force-pushed the feat_black_constant_frames branch from 634b877 to 616553b Compare February 11, 2025 05:09
@lgritz
Copy link
Collaborator

lgritz commented Feb 11, 2025

Just before merging, I got cold feet. I didn't feel good about this not having a test, so I took the liberty of adding one and amending your PR (it's just a few lines). I'll merge after it passes PR.

@lydia-zheng
Copy link
Contributor Author

Just before merging, I got cold feet. I didn't feel good about this not having a test, so I took the liberty of adding one and amending your PR (it's just a few lines). I'll merge after it passes PR.

That’s super fair and thanks for adding the tests and checking, Larry!

Actually had some local files in test suite but was waiting for the base PR to go through first, though what you did was much better for ensuring it worked.

@lgritz lgritz merged commit 1fdc5d0 into AcademySoftwareFoundation:main Feb 11, 2025
28 checks passed
lgritz pushed a commit to lgritz/OpenImageIO that referenced this pull request Feb 11, 2025
…LACK (AcademySoftwareFoundation#4610)

Included two additional metadata boolean checks for constant and black
frame images, so that handling for those image cases are facilitated.

IS_CONSTANT and IS_BLACK return 1 when true, and 0 when false.

Signed-off-by: Lydia Zheng <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement of existing/working features. oiiotool oiiotool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants