Skip to content

Commit

Permalink
Improve handling of IFD counts across Image elements (#94)
Browse files Browse the repository at this point in the history
* Fix multi-image BoundsError

* improve tracking of IFD counts

This improves handling of IFDs where the embedded IFDs are reset
between Images in the OMEXML so we don't accidentally overwrite
the index

* Add test for improved tracking of IFD count

Co-authored-by: Tamas Nagy <[email protected]>
  • Loading branch information
HsupoLeng and tlnagy authored Jan 26, 2022
1 parent 0065ef6 commit 2cd4adb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OMETIFF"
uuid = "2d0ec36b-e807-5756-994b-45af29551fcf"
authors = ["Tamas Nagy <[email protected]>"]
version = "0.4.0"
version = "0.4.1"

[deps]
AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
Expand Down
8 changes: 5 additions & 3 deletions src/parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ function ifdindex!(ifd_index::OrderedDict{Int, NTuple{4, Int}},
tiffdatas = findall(".//ns:TiffData", image, ["ns"=>namespace(image)])

ifd = 1
# this is an offset value since multiple ifds can share the same index if
# they are split across files, IFD1 (File1), IFD1 (File2), etc
prev_ifd = 0
# to avoid overwriting previous IFD indices from other images, we make sure
# to start counting from the maximum previously observed IFD index.
#
# TODO: This assumes a dense numbering of the indices, is this always true?
prev_ifd = length(ifd_index) > 0 ? maximum(keys(ifd_index)) : 0
for tiffdata in tiffdatas
try # if this tiffdata specifies the corresponding IFD
ifd = parse(Int, tiffdata["IFD"]) + 1
Expand Down
24 changes: 24 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,30 @@ end
@test size(img) == (24, 18, 5)
end
end
@testset "Multi file T stack with multiple OME image nodes" begin
# 3 images, each embedded in one OME image node, each with XYCT = (512, 512, 2, 4)
# load master file that contains the full OME-XML
@testset "Load master file" begin
open(abspath(joinpath(testdata_dir, "multiples/multi_image_node/TSeries-camp-005_Cycle00001_Ch1_000001.ome.tif"))) do f
s = getstream(format"OMETIFF", f)
img = OMETIFF.load(s)
@test size(img) == (128, 128, 2, 4, 3)
# check channel indexing
@test size(img[Axis{:channel}(:Ch1)]) == (128, 128, 4, 3)
# check time indexing
@test size(img[Axis{:time}(1)]) == (128, 128, 2, 3)
# check image indexing
@test size(img[Axis{:position}(:Pos1)]) == (128, 128, 2, 4)
end
end
@testset "Load secondary file" begin
open(abspath(joinpath(testdata_dir, "multiples/multi_image_node/TSeries-camp-005_Cycle00002_Ch1_000001.ome.tif"))) do f
s = getstream(format"OMETIFF", f)
img = OMETIFF.load(s)
@test size(img) == (128, 128, 2, 4, 3)
end
end
end
end
# let's make sure that the values we return are identical to normal TIFF readers
@testset "TIFF value verifications" begin
Expand Down

2 comments on commit 2cd4adb

@tlnagy
Copy link
Owner

@tlnagy tlnagy commented on 2cd4adb Jan 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/53190

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.1 -m "<description of version>" 2cd4adb7bd737abaca4161898f97f78926977a9b
git push origin v0.4.1

Please sign in to comment.