I have found an odd behavior, but only tested in my local computer.
If I use any automatic IO detection (pre 4.13 approach, or newer/cleaner ITKImageIO) and try to read a 3D .tiff image, for example, 64x64x16, I get a 64x64x1 image from the reader.
However if I explicitly use ITKIOTIFF, it works as expected.
Here is the minimal working example to test/reproduce it: https://github.com/phcerdan/bug_itkimageio.
test it using ctest -V and see differences changing the cmake option USE_ITKIMAGEIO:
if (USE_ITKIMAGEIO) # All available IO
set(use_itk_modules
ITKImageIO
)
else (USE_ITKIMAGEIO) # Only a few IO
set(use_itk_modules
ITKIOImageBase
ITKIOTIFF
)
endif (USE_ITKIMAGEIO)
find_package(ITK COMPONENTS ${use_itk_modules} REQUIRED)
include(${ITK_USE_FILE})
In the end, it may be best create a itk::TIFFImageIO, call CanReadFile() on it, then set it as the ImageIO for the itk::ImageFileReader if it can read the file.
Thanks @matt.mccormick, I would go for your last suggestion.
Fixing it will be way better of course, but maybe it’s not even a bug but a failure in converting the image from the microscopy format to tiff.
The bioformat reader is reading the image as a 4D:
In itk: Dimensions: ( 64 64 1 16 ).
In OME Metadata (from imageJ bioformats plugins):
This is tangentially related. The ImageFileReader by default just produced the first “slice” of a higher dimension volume. Part of this behavior is dictated by this section of code in the ImageFilterReader:
I believe an important motivation for this behavior is that a DICOM slice is reported as (X,Y,1), and this behavior enables it to be loaded into a 2D image.
There is no automatic middle dimension squishing for ITK.
I recently enabled SCIFIO for SimpleITK and the if I recall correctly a basic 2D image was reported as (X,Y,1,1) for it’s size and refused to load. I should try it with the new 4D feature in SimpleITK though.