cuslide2: add pyramidal OME-TIFF semantics and nvImageCodec 0.9 readiness #1122
Please rebase your PR to avoid changes to VERSION, dependencies.yaml, and .github/workflows/*.yaml that update the version. This branch is targeting 26.08 and should not be merged with anything from main.
Requested changes.
Approved these changes.
/ok to test 57aa61598203ec068971feb89ba37ac97547bfdd
I'm wondering why we're setting this to 0 now.
I am wondering if nvImageCodec v0.9 still has these limitation.
Is this still specific to nvImageCodec v0.9.0, or does the code also work with nvImageCodec v0.6.0?
* SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION.
Thanks @cdinea for adding ome-tiff support!
Overall, it looks good to me.
In the conda yaml file you set requirements >= 0.9 for nvimagecodec. Why do we need 0.8 here then?
Similar question as above. Also maybe the cmake structure can be simplified so nvimagecodec search is done in a single place? But this is a question for a future pull request
This doesn't look right. Why would we ask for offset of struct member instead of the whole struct size? And also limit_images was removed in 0.9 so I have no idea how is this working right now
This can overflow for large width, I would static cast widt to size_t if you store it in that type anyway
The same overflow can happen here
With this pull request you support only nvimagecodec 0.9, right? Is this workaround still needed? If yes please update the comment
But the old have different API (e.g. limit_images in old view). And I didn't see any compile time checks for nvimagecodec macros, so I assume that the old nvimagecodec will no longer compile. I would either verify that it works with the old nvimagecodec, or drop the old code
What kind of metadata extraction do you want? In the cpu only env getting metadata connected to an image (size, datatype, color spec, etc) should work. But I don't think getting tiff tags would work, as this is done with nvtiff, which I assume need some cuda libs. But I will check with rest of the team and come back.
You should update to the full new headers, using old headers can easily cause a nontrivial bug.
We do support generic tags in the API, here is python example: https://docs.nvidia.com/cuda/nvimagecodec/samples/metadata.html#Generic-tiff-tag-reading
iirc this was already supported in 0.8? Lev can know more details on this and how to querry the tags
There is already error message in the else above - I would move the details from this error message there. I don't see a reason for having two similar error messages when the ifd_infos is empty. And having more details when only some ifd infos are missing would be great too
I would remove mentions for the old nvimagecodec (as the API is not compatible) and just keep the code for the newest version
I would change the check to samples_per_pixel_ <= 2 - in case there is grayscale with alpha image (this is a rather rare case, but it doesn't cost us anything to implement
can samples_per_pixel ever be zero?
you already set the default value with as_uint(1). is the max still needed? If the xml has zero as size, maybe it should be left at that value?
I would move this check up, where you read the size_x and y
You always populate out_model - I would change its type from pointer to reference
the exception will be propagated up when parsing fails. Is this expected? It will also mean that this function will return on the first error, rather than continuing and ignoring errors as it did before
Why are you removing the limit now? And why was it needed before? Maybe you should just increase the limit?
can file_handle_shared_ ever be null? It looks like it is reset only if there is an error (and in that case, new exception is thrown after cleanup so this code won't be reached)
NIT: it looks like the res is only used in this if. So maybe you can just call missmatch().first as you did before?
IMO the old named constant were more readable, what was the reason for removing them?
you already set the size to at least 1 in the ome::parse, there is no need to repeat it here
Also in the main lib you always pass out_error. So maybe it can be changed to reference as well? Then you won't need the checks for nullptr. The only place where nullptr is passed is in a single test - but imo you can pass there a valid string
Is this is a valid file if the channels are missing?
Requested changes.
/ok to test ce00b564c98f5d209cfd0a1679ed81c608f3039a
/ok to test eac5aeec3ac69e9d6c5b6999cbcfe949f72dfec8
/ok to test aef0ca15476ad240a44f46ebb5d4cb222c370565
/ok to test 15752d3e3a45ebc16ff336cfa32b7db91e3c8342
/ok to test aeca33b5ea643257248a3d55839ebfbadc1ae24d
/ok to test 729d27a0d3848edbacccdf54f49c852b2c3c32cb
/ok to test 729d27a0d3848edbacccdf54f49c852b2c3c32cb
/ok to test e011f4429f5d0ebbaed344e4e8764d76989d4a6a
/ok to test
/ok to test
@cdinea, there was an error processing your request: E1
See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/1/
/ok to test
78b8b15
/ok to test 78b8b15
There are a few of my comments left not addressed. But they are more nitpicks / code style, so I approve
/ok to test 05bd513
/merge
KyleFromNVIDIA
cdinea
What this PR changes
ome_xml.h/.cpp)TiffDatacompanion-file referencesTiffDataonly references full-resolution planescuslidefree()Scope notes
Validation
cucim.kit.cuslide2successfully in the prepared build environmentcuslide2_testspre-commit run --hook-stage manual --all-filespassesRunning the pyramidal OME-TIFF script
The script needs no GPU-specific flags: it decodes each region on both CPU and
GPU and compares the results, so a GPU is required for the comparison checks to
run rather than be skipped. Pass
--no-cacheto exercise the direct decode pathinstead of the tile cache.
If you rebuild the C++ but see unchanged behavior under
pytest, note that thePython package loads the plugin from
python/cucim/src/cucim/clara/, not fromcpp/plugins/cucim.kit.cuslide2/build-release/lib/. Re-running./run build_localrefreshes that copy.Expected output, multi-plane OME-TIFF
retina_large.ome.tiff, 2 resolution levels,SizeC=2,SizeZ=64, uint16:Two details worth checking in that output.
Levels: 2confirms the pyramidsub-resolution survives: OME
TiffDataentries reference only thefull-resolution planes, so mapping planes alone collapses the list to level 0 and
makes level 1 unreachable through
read_region(). And the run must end at✅ Pyramidal OME-TIFF test completedwith exit status 0; a trailingfree(): invalid pointer/Abortedwas the exit-time teardown crash fixed here,which reproduced on roughly one run in five.
Expected output, non-OME pyramidal TIFF
The same script accepts ordinary WSIs. Against
CMU-1.tifthe OME and planechecks report as skipped, which is correct for a file with no OME-XML:
Note that per-axis downsample ratios differ on real WSIs, so the geometry check
compares against the mean of the axis ratios rather than assuming a single factor.
Unit tests
All 26 pass with
cuslide2enabled and with the default plugin. The threetest_tiff_stripe_outsidecases previously failed undercuslide2withFailed to decode IFD[0] with nvImageCodec. ROI: (-48,-40) 16x16: nvImageCodecfills out-of-bounds pixels for a partially overlapping region, which is why
boundary reads passed, but rejects a region that does not intersect the image at
all.