Skip to content

Test opening single-channel OME-TIFF file #102

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

Merged
merged 2 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tokio = { version = "1.43.0", optional = true, default-features = false, feature
weezl = "0.1.0"

[dev-dependencies]
object_store = "0.12"
object_store = { version = "0.12", features = ["http"] }
tiff = "0.9.1"
tokio = { version = "1.9", features = [
"macros",
Expand Down
21 changes: 21 additions & 0 deletions tests/ome_tiff.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// Integration tests on OME-TIFF files.
use async_tiff::tiff::tags::PhotometricInterpretation;

mod util;

#[tokio::test]
async fn test_ome_tiff_single_channel() {
let tiff =
util::open_remote_tiff("https://downloads.openmicroscopy.org/images/OME-TIFF/2016-06/bioformats-artificial/single-channel.ome.tif").await;
Copy link
Member

Choose a reason for hiding this comment

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

yeah I think it would be better to either check in this file into this repo, or perhaps create an async-tiff-fixtures separate repo that we can check data into.

Assuming this file is large, it would be great if we could extract like a one-pixel or very small subset of this file, while maintaining all header metadata the same.

Or, we could find the size of the last IFD and just clip the existing buffer to that region. So all IFD parsing would succeed but any image loading would fail as the image data is past the byte region checked in to the test fixture.

Copy link
Member Author

Choose a reason for hiding this comment

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

This file is 74.3KB, not huge but having many test files like these will add up (the vendored images from #28 add up to 4.5MB already 🙂).

Probably best to bring this discussion over to #23.


assert_eq!(tiff.ifds().len(), 1);
let ifd = &tiff.ifds()[0];

assert_eq!(
ifd.photometric_interpretation(),
PhotometricInterpretation::BlackIsZero
);
assert_eq!(ifd.image_description(), Some("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!-- Warning: this comment is an OME-XML metadata block, which contains crucial dimensional parameters and other important metadata. Please edit cautiously (if at all), and back up the original data before doing so. For more information, see the OME-TIFF web site: http://www.openmicroscopy.org/site/support/ome-model/ome-tiff/. --><OME xmlns=\"http://www.openmicroscopy.org/Schemas/OME/2016-06\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" Creator=\"OME Bio-Formats 5.2.2\" UUID=\"urn:uuid:2bc2aa39-30d2-44ee-8399-c513492dd5de\" xsi:schemaLocation=\"http://www.openmicroscopy.org/Schemas/OME/2016-06 http://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd\"><Image ID=\"Image:0\" Name=\"single-channel.ome.tif\"><Pixels BigEndian=\"true\" DimensionOrder=\"XYZCT\" ID=\"Pixels:0\" SizeC=\"1\" SizeT=\"1\" SizeX=\"439\" SizeY=\"167\" SizeZ=\"1\" Type=\"int8\"><Channel ID=\"Channel:0:0\" SamplesPerPixel=\"1\"><LightPath/></Channel><TiffData FirstC=\"0\" FirstT=\"0\" FirstZ=\"0\" IFD=\"0\" PlaneCount=\"1\"><UUID FileName=\"single-channel.ome.tif\">urn:uuid:2bc2aa39-30d2-44ee-8399-c513492dd5de</UUID></TiffData></Pixels></Image></OME>"));

assert!(ifd.bits_per_sample().iter().all(|x| *x == 8));
}
24 changes: 24 additions & 0 deletions tests/util/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::sync::Arc;

use async_tiff::metadata::{PrefetchBuffer, TiffMetadataReader};
use async_tiff::reader::{AsyncFileReader, ObjectReader};
use async_tiff::TIFF;
use reqwest::Url;

pub(crate) async fn open_remote_tiff(url: &str) -> TIFF {
let parsed_url = Url::parse(url).expect("failed parsing url");
let (store, path) = object_store::parse_url(&parsed_url).unwrap();

let reader = Arc::new(ObjectReader::new(Arc::new(store), path)) as Arc<dyn AsyncFileReader>;
let prefetch_reader = PrefetchBuffer::new(reader.clone(), 32 * 1024)
.await
.unwrap();
let mut metadata_reader = TiffMetadataReader::try_open(&prefetch_reader)
.await
.unwrap();
let ifds = metadata_reader
.read_all_ifds(&prefetch_reader)
.await
.unwrap();
TIFF::new(ifds)
}
Loading