TIFF images flipped in vtkTIFFReader

(Marcus D. Hanwell) #1

I have been looking into an issue with the vtkTIFFReader, and commit 84f9a173d81 made by @lorensen in 2014. The line that confuses me is:

const bool flip = this->InternalImage->Orientation != ORIENTATION_TOPLEFT;

This is opposite to what I would expect, where vtkImageData has its origin in the bottom-left, and so with an orientation in top-left I would expect that to cause the image to be flipped, i.e. == rather than !=. Is there something I am missing. In a simple test I get a single page TIFF, and it is flipped opposite to what my system viewer renders in Tomviz.

I can propose a patch making all of these == and it would fix my issue, maybe there is something about tiled TIFFs I don’t appreciate (I use multi-page, but not tiled).

(Marcus D. Hanwell) #2

I can fix the bug I am seeing by switching FlipTrue and FlipFalse in vtkTIFFReader::ReadGenericImage which I wrote in 2014 to speed up reading of files. I would appreciate a second opinion in case I am missing something as everything seems to be geared to only flip if not top-left. It seems like we only really support bottom-left and top-left correctly from looking through the code.

(Marcus D. Hanwell) #3

I posted a branch and am letting buildbot test it now, https://gitlab.kitware.com/vtk/vtk/merge_requests/5596 has the patch, and comparing to ImageJ, Gwenview, system preview the image matches what is expected.