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): Allow decision making about fixnan #4171

Merged
merged 1 commit into from
Mar 5, 2024

Conversation

lgritz
Copy link
Collaborator

@lgritz lgritz commented Mar 2, 2024

Added a new bit of pseudo-metadata that can be retrieved by oiiotool's expression substitution: {TOP.NONFINITE_COUNT} will be replaced by the count of inf and nan values present in the top image.

Also, the -fixnan command now has the side effect of setting a user variable called NONFINITE_COUNT to the number of nonfinite values that were detected or repaired.

Between the two of these, it's now easy to solve the following problem that actually came up in production for us.

Sometimes, nans creep into images, and it's easier to repair them than to fix the complicated process that produced them in the first place. For some process in the studio, we had a script that was doing this preemptively on every image it encountered:

oiiotool image.exr -fixnan black -o image.exr

It was very expensive to repair every image whether it needed it or not, when actually it's only needed once every
many-thousands-of-images. Most of the expense was in outputting the repaired file overtop the original. Now we can do this

oiiotool image.exr -if "{TOP.NONFINITE_COUNT}" -fixnan black -o image.exr -endif

It still has to read the image and look for NaN values, but since there are almost never any actual NaN's, now for the usual case, it can skip writing the output -- which was the vast majority of time.

Added a new bit of pseudo-metadata that can be retrieved by oiiotool's
expression substitution: `{TOP.NONFINITE_COUNT}` will be replaced by
the count of inf and nan values present in the top image.

Also, the `-fixnan` command now has the side effect of setting a user
variable called `NONFINITE_COUNT` to the number of nonfinite values that
were detected or repaired.

Between the two of these, it's now easy to solve the following problem that
actually came up in production for us.

Sometimes, nans creep into images, and it's easier to repair them than
to fix the complicated process that produced them in the first
place. For some process in the studio, we had a script that was doing
this preemptively on every image it encountered:

    oiiotool image.exr -fixnan black -o image.exr

It was very expensive to repair every image whether it needed it or
not, when actually it's only needed once every
many-thousands-of-images. Most of the expense was in outputting the
repaired file overtop the original. Now we can do this

    oiiotool image.exr -if "{TOP.NONFINITE_COUNT}" -fixnan black -o image.exr -endif

It still has to read the image and look for NaN values, but since
there are almost never any actual NaN's, now for the usual case, it
can skip writing the output -- which was the vast majority of time.

Signed-off-by: Larry Gritz <[email protected]>
@lgritz lgritz added enhancement Improvement of existing/working features. oiiotool oiiotool labels Mar 2, 2024
@lgritz
Copy link
Collaborator Author

lgritz commented Mar 2, 2024

@grdanny

Copy link
Contributor

@grdanny grdanny 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! thanks for putting this together!

@lgritz lgritz merged commit edb2b4f into AcademySoftwareFoundation:master Mar 5, 2024
26 checks passed
lgritz added a commit to lgritz/OpenImageIO that referenced this pull request Mar 5, 2024
…undation#4171)

Added a new bit of pseudo-metadata that can be retrieved by oiiotool's
expression substitution: `{TOP.NONFINITE_COUNT}` will be replaced by the
count of inf and nan values present in the top image.

Also, the `-fixnan` command now has the side effect of setting a user
variable called `NONFINITE_COUNT` to the number of nonfinite values that
were detected or repaired.

Between the two of these, it's now easy to solve the following problem
that actually came up in production for us.

Sometimes, nans creep into images, and it's easier to repair them than
to fix the complicated process that produced them in the first place.
For some process in the studio, we had a script that was doing this
preemptively on every image it encountered:

    oiiotool image.exr -fixnan black -o image.exr

It was very expensive to repair every image whether it needed it or not,
when actually it's only needed once every
many-thousands-of-images. Most of the expense was in outputting the
repaired file overtop the original. Now we can do this

oiiotool image.exr -if "{TOP.NONFINITE_COUNT}" -fixnan black -o
image.exr -endif

It still has to read the image and look for NaN values, but since there
are almost never any actual NaN's, now for the usual case, it can skip
writing the output -- which was the vast majority of time.

Signed-off-by: Larry Gritz <[email protected]>
@lgritz lgritz deleted the lg-nan branch March 5, 2024 19:54
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