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

Bug in the Writing ImageJ compatible metadata example #184

Open
lanceXwq opened this issue Feb 25, 2025 · 6 comments
Open

Bug in the Writing ImageJ compatible metadata example #184

lanceXwq opened this issue Feb 25, 2025 · 6 comments
Labels
bug Something isn't working

Comments

@lanceXwq
Copy link

Hello,

I was going over the Writing ImageJ compatible metadata example and noticed a bug may exist. After running this example, ImageJ seemed to misinterpret the produced tiff file. Specifically, although this example should create an "imagej.tiff" with only zeros, I got nonzero pixel values at some slices and frames in ImageJ, as shown in the screenshot below (also see the "Pixel value range" field in the second screenshot).
Image
Moreover, running TiffImage.load("imagej.tiff") still produces an all-zero image stack.

I am using Julia 1.11.3, TiffImages 0.11.3, ImageJ 1.54p (see below).
Image

Please let me know if you need any more info. I appreciate any help you can provide!

@lanceXwq
Copy link
Author

Upon a second look, I noticed that this could actually be ImageJ's issue. None of Icy, Ubuntu's document viewer, or Bio-Formats Importer shares the same problem. I will close this issue for now.

@cgohlke
Copy link

cgohlke commented Feb 26, 2025

@lanceXwq
Copy link
Author

I am reopening this issue for the reason @cgohlke stated in the link posted above. For the sake of convenience, I am posting it here.

While the file is (almost) valid TIFF, it is not a valid ImageJ TIFF. When ImageJ encounters a ImageDescription tag value in the first IFD starting with “ImageJ”, it stops reading other IFDs and instead assumes that all image data are contiguously stored at an offset specified in the StripOffsets tag. In this TIFF file, the image stack is stored non-contiguously. For larger stacks, ImageJ requires that IFD tags are written before the contiguous image data, which is not the case here either.

@lanceXwq lanceXwq reopened this Feb 26, 2025
@tlnagy tlnagy added the bug Something isn't working label Feb 28, 2025
@tlnagy
Copy link
Owner

tlnagy commented Feb 28, 2025

Hi @lanceXwq, thanks for the bug report and sorry that the demo was overly primitive. The original impetus behind the demo was trying to showcase TiffImages.jl's API for manipulating IFD data.

It appears from @cgohlke's comment that ImageJ is less flexible than I was expecting when I wrote this short demo. It would be quite easy to modify TiffImages.jl's writer to write the IFDs first when saving ImageJ compatible TIFFs. Honestly, this complexity shouldn't be exposed to the user at all and use something like tifffile's imagej flag, see #135 for a bit of the thinking there.

@tlnagy
Copy link
Owner

tlnagy commented Feb 28, 2025

The one commenter who brought up the exiftool -validate -a -warning has a point. It's clear from the output that this demo falls short:

Validate                        : 49 Warnings (36 minor)
....snip.....
Warning                         : [minor] Odd offset for IFD11 tag 0x011a XResolution
Warning                         : [minor] Odd offset for IFD11 tag 0x011b YResolution
Warning                         : Non-standard format (int8u) for IFD11 0x0128 ResolutionUnit
Warning                         : [minor] Odd offset for IFD11 tag 0x0131 Software
Warning                         : Missing required TIFF IFD0 tag 0x0116 RowsPerStrip

Looks like the primary issues are with odd offsets in this demo. I'm not actually sure what exiftool means with this, but I'm guessing it has something to do with the bit packing.

@juliohm
Copy link

juliohm commented Feb 28, 2025

It would be quite easy to modify TiffImages.jl's writer to write the IFDs first

That would be very useful @tlnagy. If IFDs are written first, we are one step closer from what people call cloud-optimized geotiff (COG). GeoTIFF.jl would directly benefit from this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants