cuslide2: raise an error instead of returning zeros when no JPEG 2000 decoder is loaded #1222
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 532 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.376
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1222"
general
weight: 0.35
gigony
The issue fixed was discovered along with #1211 and described there, but was not the main focus of that issue.
This PR is on top of #1219 (https://github.com/rapidsai/cucim/pull/1219), which adds the
synthetic-image tests that this PR extends. Until #1219 is merged, this PR also shows its two
commits. The change here is the last commit.
Summary
If the nvJPEG2000 or nvTIFF library cannot be loaded,
read_regionon a JPEG 2000 TIFF (Aperiocompression 33003 and 33005, or TIFF compression 34712) returns an all-zero image without an
error, on the CPU and on the GPU. nvImageCodec prints
Failed to load nvjpeg2k library!orFailed to load nvtiff library!once, and OpenCV printsCompression scheme 33003 tile decoding is not implementedfor each tile, but the call returnsnormally. The caller cannot tell the image from a black one.
Cause: nvImageCodec has CPU-only fallback decoders for TIFF (libtiff and OpenCV extensions). They
accept a JPEG 2000 TIFF, fail on every tile, and report success. cuslide2 checks the processing
status of the decode, but the status is success.
#1219 adds the nvImageCodec extras to the pip requirements, which removes the usual cause for pip
installs. This PR makes the failure visible when the libraries are missing anyway (a pip install
without the extras, a conda environment without
libnvjpeg2korlibnvtiff, or a system install).Changes
NvImageCodecTiffParserManager::get_decoder_for(codec, compression_known)returns the defaultdecoder, except for JPEG 2000 IFDs, and for IFDs whose compression is not known because no TIFF
tags were returned (nvTIFF is not loaded, so the compression cannot be ruled out). For those it
returns a second decoder, created on first use, that allows only the GPU-only, hybrid CPU/GPU and
hardware backends and not the CPU-only ones. If nvJPEG2000 or nvTIFF is missing, nvImageCodec then
reports that the image cannot be decoded, and the existing error path raises.
get_decoder_for.the default decoder is used as before.
test_cuslide2_jpeg2000_is_decoded_or_an_errorwrites a JPEG 2000 TIFF with tifffile(33003, 33005 and 34712). A read must either match the source image (mean absolute error of at
most 1) or raise an error that mentions nvImageCodec, and must never return blank data. No sample
data is downloaded.
Behavior change
Without nvTIFF, every compression now raises. Before, JPEG, Deflate and LZW TIFFs were decoded
correctly by the CPU fallbacks, but with a wrong pyramid (extra levels for the macro, thumbnail and
label images) and tile sizes of
(0, 0), so the image was not usable as a slide anyway. A pipinstall with the extras from #1219 is not affected. Only a setup without nvTIFF is. If you prefer,
this can be limited to IFDs that are known to be JPEG 2000 (the second case in
get_decoder_for),which keeps the old behavior without nvTIFF but leaves the all-zero result in that setup.
Testing
I built the plugin from this branch against a source build of libcucim and ran the new test with
three nvImageCodec layouts, with the old plugin (before this change) and the new one:
| nvImageCodec layout | old plugin | new plugin |
|---|---|---|
| pip package, no extras | 3 failed: blank region | 3 passed: error raised |
| pip package plus nvTIFF only | 3 failed: blank region | 3 passed: error raised |
| all libraries | 3 passed | 3 passed |
With all libraries, the 7 tests of
test_cuslide2_plugin.pypass (the pyramids and pixels ofDeflate, LZW, JPEG and JPEG 2000 TIFFs on the CPU and the GPU). With the pip layout without extras,
the pyramid tests now fail with the new error instead of reading a wrong pyramid.
The
libnvimgcodeclibraries in these layouts are not loaded the same way in every environment, soI did not add a test that removes them. The new test is a regression check that is useful when run
where a library is missing, and it passes where all libraries are present, as in CI.