Repository navigation
BUG: Keep 2D scalar images 2D in image_from_vtk_image - #6996
hjmjohnson merged 1 commit into
Conversation
dzenanz
left a comment
There was a problem hiding this comment.
Test looks good. Does looking at git history reveal why was is_vector in the if condition? Oversight, or some special handling of color or some other non-spatial dimension?
|
Checked history. Both functions were added together in f13e760 (2020-04-29, "Add itk.vtk_image_from_image and itk.image_from_vtk_image"), and the is_vector check goes back to that same commit, unchanged since. The original code was actually two separate branches, not one shared trim: The vector branch needs is_vector specifically because it has to append the component count as its own trailing axis, which only makes sense for a vector image. The else branch just reverses all 3 dims unconditionally, including the padded 1, so a 2D scalar image always kept its spurious third axis. The PR's own test suite only ever covered a 3D scalar round trip and a 3D vector round trip, never 2D of either kind, so this never got exercised. Nothing in the commit message, code, or tests points to intentional handling of color or some other non-spatial dimension for the scalar case. Looks like a plain oversight to me, not a deliberate choice. |
|
LGTM. It would be good if Matt reviewed, too. |
thewtex
left a comment
There was a problem hiding this comment.
This looks ok.
Since VTK does not have a way to represent non-3D rank images, we loose the original rank. So, if it was a 3D image with a size of 1 in the third dimension, it is always converted to a 2D image. That may be a better default.
|
Thanks both for reviewing. Marked this ready for review now that it's approved by both of you — happy to make any more changes if something still needs a look, otherwise it should be good to merge. |
[Medium impact] The change reaches callers converting VTK images with a trailing size-1 dimension. Preserve single-slice 3D scalar images before merging. Findings
|
e46a41d to
ac517c5
Compare
ac517c5 to
67f4007
Compare
|
Rebased on main (plain rebase, patch unchanged) to pick up #7028, which fixes the |
|
Got it, thanks for sorting that out. Noted, will pull before pushing anything further to this branch. |
image_from_vtk_image only trimmed a trailing size-1 VTK z dimension for vector-pixel images, so round-tripping a 2D scalar image through the VTK bridge produced a 3D image. Apply the same trim for scalar pixels.
AI assistance
image_from_vtk_imageinWrapping/Generators/Python/itk/support/extras.py; drafted the fix and the added round-trip testimage_view_from_array, but the scalar branch had no equivalent check, so 2D scalar images silently grew a spurious 3rd dimension on the VTK round trip