tlnagy / OMETIFF.jl

I/O operations for OME-TIFF files in Julia
Other
24 stars 7 forks source link

BoundsError when accessing Tag #109

Closed RpfR2000 closed 5 months ago

RpfR2000 commented 5 months ago

Hi, I'm getting the following error when trying to load a .ome.tif image with coords (X,Y,C,Z,T): LoadError: BoundsError: attempt to access 0-element Vector{TiffImages.Tag} at index [1]. I am able to open this image in Fiji/ImageJ without an issues. How can I go about figuring out what is wrong? Thanks!

tlnagy commented 5 months ago

Unfortunately, it's really difficult to figure out what the problem might be with the information you provided. Do you have a minimal example that you can send me that reproduces the problem? If you can share a file that causes this problem that would be ideal.

Does TiffImages.jl open the file? OMETIFF.jl is a wrapper with some extra processing of the OME rich metadata that is embedded in the TIFF, but TiffImages does all the heavy lifting.

RpfR2000 commented 5 months ago

I did try with TiffImages.jl and ran into the same issue. I'll send you an example.

RpfR2000 commented 5 months ago

Just checking -- did you get the file I sent?

tlnagy commented 5 months ago

Using

julia> using TiffImages, ImageView

julia> img = TiffImages.load("/home/tlnagy/Downloads/Reporter_check_0321_test.ome.tif")
Loading: 100%|███████████████████████████████████████████| Time: 0:00:03
2304×2304×29 TiffImages.DenseTaggedImage{ColorTypes.Gray{FixedPointNumbers.N0f16}, 3, UInt32, Array{ColorTypes.Gray{FixedPointNumbers.N0f16}, 3}}:
...

julia> imshow(img[:, :, 1])

image

This looks correct?

It does look that OMETIFF.jl is heavily out-dated with respect to what TiffImages versions are considered "compatible": https://github.com/tlnagy/OMETIFF.jl/blob/4f685045442ce3ce2029d1044ba17ad272f77c5f/Project.toml#L28

110 may fix this.

tlnagy commented 5 months ago

Actually, I can reproduce this error with OMETIFF v0.4.4:

julia> img = load("/home/tlnagy/Downloads/Reporter_check_0321_test.ome.tif")
Error encountered while load File{DataFormat{:OMETIFF}, String}("/home/tlnagy/Downloads/Reporter_check_0321_test.ome.tif").

Fatal error:
ERROR: BoundsError: attempt to access 0-element Vector{TiffImages.Tag} at index [1]
Stacktrace:
  [1] getindex
    @ ./essentials.jl:13 [inlined]
  [2] first
    @ ./abstractarray.jl:452 [inlined]
  [3] getindex
    @ ~/.julia/packages/TiffImages/yETMK/src/ifds.jl:69 [inlined]
  [4] getindex
    @ ~/.julia/packages/TiffImages/yETMK/src/ifds.jl:68 [inlined]
  [5] read!(target::Matrix{ColorTypes.Gray{…}}, tf::TiffImages.TiffFile{UInt32, Stream{…}}, ifd::TiffImages.IFD{UInt32})
    @ TiffImages ~/.julia/packages/TiffImages/yETMK/src/ifds.jl:207
  [6] macro expansion
    @ ~/.julia/packages/OMETIFF/3RcZb/src/loader.jl:131 [inlined]
  [7] macro expansion
    @ ~/.julia/packages/ProgressMeter/dMfiC/src/ProgressMeter.jl:1010 [inlined]
  [8] inmemoryarray(ifds::OrderedCollections.OrderedDict{…}, dims::@NamedTuple{…}; verbose::Bool)
    @ OMETIFF ~/.julia/packages/OMETIFF/3RcZb/src/loader.jl:130
  [9] load(io::Stream{DataFormat{:OMETIFF}, IOStream, String}; dropunused::Bool, verbose::Bool, inmemory::Bool)
    @ OMETIFF ~/.julia/packages/OMETIFF/3RcZb/src/loader.jl:90

TiffImages can properly load the file (if OMETIFF/FileIO isn't loaded), so this is definitely a bug in OMETIFF.

tlnagy commented 5 months ago

Great news, #110 fixes this. OMETIFF v0.4.5 has no issues:

julia> using FileIO

julia> load("/home/tlnagy/Downloads/Reporter_check_0321_test.ome.tif")
Progress: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████| Time: 0:00:01
Gray ImageMeta with:
  data: 3-dimensional AxisArray{Gray{N0f16},3,...} with axes:
    :y, (0.0:0.325:748.475) μm
    :x, (0.0:0.325:748.475) μm
    :z, 1:29
And data, a 2304×2304×29 Array{Gray{N0f16},3} with eltype ColorTypes.Gray{FixedPointNumbers.N0f16}
  properties:
    Description: 
    Elapsed_Times: Quantity{Float64, 𝐓, FreeUnits{(s,), 𝐓, nothing}}[3.2821 s, 3.38214 s, 3.48218 s, 3.58222 s, 3.68226 s, 3.78231 s, 3.88235 s, 3.98239 s, 4.08243 s, 4.18247 s  …  5.18289 s, 5.28293 s, 5.38297 s, 5.48301 s, 5.58305 s, 5.68309 s, 5.78314 s, 5.88318 s, 5.98322 s, 6.08326 s]

I'm going to go ahead and close this issue. Please open a new one if it doesn't resolve your problem.