fix(io): nvjpeg2000 are not always able to encode synthetic data
Description
nvjpeg2000 is not always able to encode synthetic data with 100% accuracy: the final buffer comparison fails, with some pixels having a +-1 value compare to original pixels.
The test
libs/io/dicom/test/tu/WriterTest.cpp
in Sight does reproduce the problem when using the "best" and not the "fast" (default) nvjpeg2000 encoder settings.
Generating a pixel buffer as this does exibit the problem in "fast" mode:
auto it = imageSeries->begin<sight::data::iterator::rgb>();
const auto end = imageSeries->end<sight::data::iterator::rgb>();
std::size_t index = 0;
std::uint8_t r = 0;
std::uint8_t g = 0;
std::for_each(
it,
end,
[&](auto& x)
{
if(index++ < (size[0] * size[1]))
{
x.r = r++;
x.g = 0;
x.b = 0;
}
else
{
x.r = 0;
x.g = g++;
x.b = 0;
}
});
Actually, the error can be reproduced in Linux; however it only happens on Windows CI because CUDA is enabled on Windows CI and not on Linux CI because Linux CI doesn't have a GPU.
We tested with real worl medical images (the one from sight-data) and we do not reproduce this behavior We also tested with more than 10.000 non medical images, but real life photography and we also do not reproduce this behavior
Steps to reproduce
- Launch a test which uses io::dicom::Writer with synthetic data
Proposal
In libs/io/dicom/Writer.cpp, when deciding whether to use the UserCodec or not, don't use SIGHT_ENABLE_NVJPEG2K macro, and instead check the return of io::bitmap::Writer::nvJPEG2K. This might not fix the issue, but is a step in the right direction at least.
Using the BEST mode instead of FAST might help. → Actually, using BEST mode will break other tests, it isn't a very good workaround.
- report and track this issue on nvidia github: see https://github.com/NVIDIA/CUDALibrarySamples/issues/100 and https://github.com/NVIDIA/CUDALibrarySamples/issues/110
- deal with it. Our exhaustive tests showed that this problem is highly improbable on real image..
Functional specifications
If there is any change to the workflow, UX/UI design, screenshots, etc..., please describe it here
Technical specifications
Details of the implementation of the fix
Test plan
- Use nvJPEG2K on the Windows CI on Sight so that we can detect these kind of problems sooner.
- Add the problematic test case on Sight in io::dicom