-
-
Notifications
You must be signed in to change notification settings - Fork 476
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
[MRG] Fix decoding of JPEG compressed color images with Photometric Interpretation "RGB" #878
[MRG] Fix decoding of JPEG compressed color images with Photometric Interpretation "RGB" #878
Conversation
I noticed that the |
The test_PI_RGB tests just test that the reading of lossy compressed jpegs behaves the same way that using dcmtk's dcmcjpeg and dcmdjpeg do. The filenames being tested include the command line options passed to dcmcjpeg (version 3.6.1 as indicated in the file metadata). For example:
was created by running:
and the expected result was created by running:
These tests only assert that we decode these files the same way dcmtk decodes them. as noted in the discussion of #521, the gdcm and dcmtk command line tools disagreed in some of these cases. The dcmtk results "looked" better, so that is what is in the test (and what is supported). If these tests are failing, then the pillow handler is not replicating dcmtk's dcmdjpeg command line tool for that file. Whether it is correct or not is an open question. I would like to note that quite a lot of lossy compressed color jpeg DICOM files have the PI tag set to "RGB" incorrectly, and we should have some way to support them.... |
I think you are right about the incorrectly set I really don't like the idea of supporting invalid files, since this will lead to unexpected behavior down the line because users assume that files are valid and are then surprised if a different application fails to handle them. |
@darcymason @rhaxton Are there any objections against merging this PR? |
There's no test coverage of the actual correction. |
…m into bugfix/pillow-color-handling
@scaramallion I added a test case via 9cb6fc2. It would great if this bug fix could make it into the next release. |
…ix/pillow-color-handling
Codecov Report
@@ Coverage Diff @@
## master #878 +/- ##
=======================================
Coverage 95.22% 95.23%
=======================================
Files 60 60
Lines 9682 9691 +9
=======================================
+ Hits 9220 9229 +9
Misses 462 462
Continue to review full report at Codecov.
|
The two test datasets you added aren't based on the same image as the other SC* datasets, they should be renamed and their source and an explanation of what they contain/how they're encoded be added to the README in the test_files directory. |
…m into bugfix/pillow-color-handling
@scaramallion I renamed the file and added a description to the README as requested. Please let me know if anything else is required for getting this merged. I think it's important to get this fix released. Image without the fix (pydicom 2.0.0): Image with fix (b88d9b6): |
* some changes to PR workflow, harmonize flags between the two * flake8 for only the changed files * start pymedphys pydicom-only test setup, but not active currently
Remove unicode literals no longer needed since dropping Python 2
* Install pymedphys[tests] * Add pymedphys cache
* add download.py, delete test files that are hosted elsewhere * update data manager to filter the zenodo files as if they were still within that directory * add installation notes
* fix-1062 * Revert explicit comparisons, add check that value is set * Add test
* Refactor codedict._filtered * use generators/lazy evaluation where possible
* Added Dataset.copy() method - used method inherited from dict before, which always returned empty dict - fixes #1146 - adapt test for shallow/deep copy
* Move larger test files to separate repo (pydicom/pydicom-data) * update github actions scripts to cache the .pydicom data location * Change to commit hash for urls
* Add JLS tests * Add as_array() test * Add versioning info
…m into bugfix/pillow-color-handling
@scaramallion I updated the branch. First tried to rebase, but gave up after rebasing for over half an hour. Ultimately, ended up merging current master into the branch. Tests are passing. It would really be great if you could get this merged. |
Dang, I thought that would re-run the CI |
…ix/pillow-color-handling
The Pixel Data element of DICOM image instances may contain JPEG bitstreams that were not converted to YCbCr color space upon compression. In these cases the value of
PhotometricInterpretation
is"RGB"
rather than"YBR_FULL_422"
.JPEG is color blind, i.e. the JPEG bitstream may not contain any information about any color transformation, and Pillow's
JpegImagePlugin
assumes that images have been transformed into YCbCr space before compression. As a consequence, thepillow_handler
doesn't decode images correctly, which were compressed directly in RGB color space (see python-pillow/Pillow#3952).This PR fixes the color "mode" of the
Pillow.Image
object by providing additional color information to the decoder and thereby ensure that images are decoded correctly.