fix(IBA): reorient() cases for transpose and transverse - #5350
Conversation
|
The orientation codes are so inherently confusing to think about in words. I also think, if we don't have it, we really need a testsuite verification of reorient for EACH of the 8 values. I guess we don't, or the code change you made would either be failing tests, or be accompanied by updated reference images? I have to admit I'm afraid to accept this change in behavior without a visual test that proves that the new code definitely does the right thing. |
Yes, the wording is super confusing. A visual illustration sounds good. That'd be helpful. Also, the intro paragraph in the display hints docs does define the ordering convention, but still it requires some eyeballing for me. For values like 6 and 8, I couldn't tell which part of '(right to left, top to bottom)' described what. |
|
It feels like the right order of operations is:
Without the visual example (and multiple people looking it over), I honestly don't trust myself to get this right just using the words and my head. It's really easy to make mistakes when reasoning about it. |
|
Maybe something that looks like this: |
|
oh no, did I already mix up rows and columns? |
|
It's even confusing visually :-) Does "cols" mean "this line is an example of a column" or does it mean "column indices increase in this direction?" |
|
Better? |
|
I want to make something that nobody could possibly look at and still be confused. :-) |
That is exactly what confused me. An example of Orientation 6. |
I think I should've done this before opening the PR. I thought I understood it correctly. Lesson learned. I'm going to work on step 1 and share soon! |
But not IN the image. If we're showing how each one should display, top is always top, etc. but the contents of the image rotate. OH, I just realized I described the process incorrectly. (See? Confusing!) I think the correct description is:
|
|
Love it! Now I need to stare at these with the TIFF spec open and convince myself that every one is correct. The nomenclature is really hard. If the starting image is And you asked me what this image was: I would say that second image is "rotated 90 degrees clockwise" (relative to the starting image). Does that help? |
|
OH, YES!! Super helpful. Thanks! The "what this image was" framing is the best part. |
|
I'm very confused by Apple's preview describing orientation 6 as "rotated counter-clockwise". That feels like the opposite of how I conceptualize it. I will look for other explanations of orientation in the other file format specs. (They all ultimately borrowed TIFF's meaning of the flags, but they might explain it in different ways. I notice that TIFF doesn't say anything about rotation, it just says which sides of the view are the 0th row and column.) |
|
I am convinced that the images you posted (that is, as displayed by Apple Preview) match the descriptions in the TIFF spec. Now we just need to verify that OIIO is also doing the right thing when displaying with iv, and that reorient() works correctly in all cases (i.e. the reoriented result should LOOK just like those apple images, but say that they are orientation 1). And then we need to clean up our own documentation to be less confusing/ambiguous. |
|
Yep, sounds great! I'm going to work on the testsuite so that the results of reorient() look just the same as those intended orientations (the images in the screenshot), but with all images having Orientation=1 in the spec. Also, I'll check the display in iv (haven't tried it yet, so I'd like to explore). |
7e8ad8f to
b40d8b0
Compare
|
I'm not sure if it's easy given the documentation system, but I was imagining that the picture for each could be incorporated directly into a single table. Like Also, given how much we have been confused by those textual descriptions, I wonder if it would be better to directly adopt the descriptions used in the TIFF spec. I need to check the various image file format specs (not just TIFF) that incorporate this encoding to see if any of them do a better job with explanations. I'm not sure I remember where I got the wording that we have now. |
|
Yes, I like that. |
|
Great! Just to be sure: the version with the box (first screenshot) or without (second)? (Personally, the second one looks cleaner!) And about the "right to left, top to bottom" style of wording (if that is what you meant): a very similar phrasing appears in |
|
I also prefer the second one. |
I'm not sure what I like best here, but I note that the wording from the original TIFF spec (which I posted above a few messages) is at least unambiguous, saying things like "the 0th row is the visual top of the image and the 0th column is the visual left side of the image." I'm thinking now that this is a lot better than talking about rotations, which are harder to discern which direction they mean (rotate memory to get appearance or rotate appearance to get the memory layout). We should also probably explain, right before the table, that "row/column" refers to the order that the pixels are arranged in memory: starting with scanline/row 0, and within each scanline, starting with column 0. The orientation merely describes how that data is intended to be shown visually on a display. It's tricky, so easy to get confused, and there is a real tension between wanting the explanations to be unambiguous and not open to misunderstanding, but not wanting to end with a long word salad that nobody understands. |
Orientations 5 and 7 were swapped: case 5 produced transverse and case 7 produced transpose. Fix both cases. This adds reorient() tests covering all 8 values to the oiiotool-xform testsuite, and updates the python-imagebufalgo reorient() test to use the new test image for consistency. Also, add orientation example images to documentation. Fixes AcademySoftwareFoundation#4661 Signed-off-by: Luna Kim <177369799+luna-y-kim@users.noreply.github.com>
I really like the "in memory" wording here. It clears up the vagueness of "0th row", and it also implicitly explains how software that doesn't honor Orientation will show the image. In addition to this part, maybe worth stating that "this means value 1 is displayed in memory order"? It can give readers a concrete anchor for what 'in memory' means in their mental model. (...Could this be part of a long word salad? or redundant?)
When I read the TIFF spec for the first time, I was also confused by the wording "the visual right" together with "0th row" because neither term was defined clearly. So I think "intended to be shown visually on a display" is great here. |
I think maybe this lands us right back into ambiguity, since there is no particular reason to think a display will show the pixel with the lowest memory address at the visual "top". Many display and windowing systems over the years have considered the coordinate origin to be at the bottom of the screen. |
|
Ah, right! I didn't think of bottom-origin coordinate systems. Thanks for pointing that out! There's more to consider than I thought. |
b40d8b0 to
54d121e
Compare
| "reorient1.tif", "reorient2.tif", "reorient3.tif", "reorient4.tif", | ||
| "reorient5.tif", "reorient6.tif", "reorient7.tif", "reorient8.tif", |
There was a problem hiding this comment.
I'm slightly worried about the ways this can fail, since in order to support multiple references when they differ per-platform, we consider a test to pass if an output we are checking matches any of the reference images. So if orientation 2 were to break and started making the image that should be orientation 4 instead, I think this would still pass?
Here is an idea, what do you think?
After you make the reorient?.tif images, assemble them into one big image using oiiotool --mosaic, and compare THAT (not the individual reoriented images) to a reference image. Then any individual reorient images being wrong will certainly be a failure and can't pass by coincidentally matching a different reorientation.







Orientations 5 and 7 were swapped: case 5 produced transverse and case 7 produced transpose. Fix both cases.
This adds reorient() tests covering all 8 values to the oiiotool-xform testsuite, and updates the python-imagebufalgo reorient() test to use the new test image for consistency.
Also, add orientation example images to documentation.
Fixes #4661
Checklist:
and if I used AI coding assistants, I have an
Assisted-by: TOOL / MODELline in the pull request description above.
behavior.
PR, by pushing the changes to my fork and seeing that the automated CI
passed there. (Exceptions: If most tests pass and you can't figure out why
the remaining ones fail, it's ok to submit the PR and ask for help. Or if
any failures seem entirely unrelated to your change; sometimes things break
on the GitHub runners.)
fixed any problems reported by the clang-format CI test.
corresponding Python bindings. If altering ImageBufAlgo functions, I also
exposed the new functionality as oiiotool options.