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

Files with inconsistent image slice sizes break loading #139

Closed
tlnagy opened this issue Dec 8, 2023 · 4 comments · Fixed by #156
Closed

Files with inconsistent image slice sizes break loading #139

tlnagy opened this issue Dec 8, 2023 · 4 comments · Fixed by #156
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@tlnagy
Copy link
Owner

tlnagy commented Dec 8, 2023

Currently TIFF images with embedded reduced resolution images cause problems since TiffImages assumes the images aren't ragged.

Take DAPI Myog Pax7_CH1.zip for example, which fails to load:

julia> TiffImages.load("DAPI Myog Pax7_CH1.tif")
ERROR: EOFError: read end of file
Stacktrace:
  [1] unsafe_read(s::IOStream, p::Ptr{UInt8}, nb::UInt64)
    @ Base ./iostream.jl:428
  [2] unsafe_read
    @ ./io.jl:761 [inlined]
  [3] read!
    @ ./io.jl:779 [inlined]
  [4] read!(file::TiffFile{UInt32, FileIO.Stream{FileIO.DataFormat{:TIFF}, IOStream, String}}, arr::Matrix{ColorTypes.RGB{FixedPointNumbers.N0f8}})

However, loading the image planes separately works:

tf = read(open("DAPI Myog Pax7_CH1.tif"), TiffFile)
ifds = collect(tf)
TiffImages.load!.(Ref(tf), ifds)
size(TiffImages.load(tf, ifds[1:1], nothing))

(720, 960)

and

size(TiffImages.load(tf, ifds[2:2], nothing))

(120, 160).

It appears as though we are handling everything just fine, it's just that we should detect when images are "ragged", i.e. don't have the same XY sizes and load those images as the currently unimplemented StridedTaggedImage

@tlnagy tlnagy added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels Dec 8, 2023
@chrstphrbrns
Copy link
Contributor

I've come across GeoTIFFs with ragged data, so this is a must for 1.0 IMHO

@tlnagy
Copy link
Owner Author

tlnagy commented Mar 26, 2024

Agreed, this would be nice to have in 1.0. AFAIK the TIFF spec doesn't record raggedness anywhere. There's some information in SubfileType and NewSubfileType tags, but it doesn't seem universal.

I think the best strategy is to assume consistent slice sizes and fail gracefully if we detect ragged images and build a StridedTaggedImage and let the user (or wrapping package e.g. OMETIFF.jl) deal with it.

@chrstphrbrns
Copy link
Contributor

Thoughts on how to handle LazyBufferedTIFF, which assumes slices are homogeneous in size and color type?

@tlnagy
Copy link
Owner Author

tlnagy commented Mar 29, 2024

LazyBufferedTIFF is currently a subtype of AbstractDenseTIFF so it should just error and not support ragged TIFFs. We could discuss whether that subtyping is the best, but just erroring could be fine for now.

EDIT: Discussion over in #154

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants