Skip to content
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

Incorrect color space on decompression of JPEG Baseline with RGB components #2208

Closed
hackermd opened this issue Oct 11, 2019 · 6 comments
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@hackermd
Copy link

Color images that have PhotometricInterpretation RGB are not correctly rendered to image/jpeg or image/png media type (see also #2192).

@hackermd
Copy link
Author

Please note that JPEG-compressed images with PhotometricInterpretation RGB cannot be communicated directly using image/jpeg, since this MIME type requires YCbCr color space (see JPEG File Interchange Format). In this case, the image needs to be decompressed, transformed from RGB into YCbCr color space and then re-compressed.

@gunterze
Copy link
Member

Not reproducable:

$ curl http://gunter-nb:8080/dcm4chee-arc/aets/DCM4CHEE/rs/studies/1.3.6.1.4.1.5962.1.2.14.20040826185059.5457/series/1.3.6.1.4.1.5962.1.3.14.1.20040826185059.5457/instances/1.3.6.1.4.1.5962.1.1.14.1.1.20040826185059.5457/metadata | python -m json.tool | grep -A3 00280004 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2495    0  2495    0     0   110k      0 --:--:-- --:--:-- --:--:--  110k
        "00280004": {
            "Value": [
                "RGB"
            ],
$ curl -v -O http://gunter-nb:8080/dcm4chee-arc/aets/DCM4CHEE/rs/studies/1.3.6.1.4.1.5962.1.2.14.20040826185059.5457/series/1.3.6.1.4.1.5962.1.3.14.1.20040826185059.5457/instances/1.3.6.1.4.1.5962.1.1.14.1.1.20040826185059.5457/rendered
* Expire in 0 ms for 6 (transfer 0x5638080f55c0)
* Expire in 1 ms for 1 (transfer 0x5638080f55c0)
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Expire in 0 ms for 1 (transfer 0x5638080f55c0)
* Expire in 0 ms for 1 (transfer 0x5638080f55c0)
*   Trying 192.168.2.131...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x5638080f55c0)
* Connected to gunter-nb (192.168.2.131) port 8080 (#0)
> GET /dcm4chee-arc/aets/DCM4CHEE/rs/studies/1.3.6.1.4.1.5962.1.2.14.20040826185059.5457/series/1.3.6.1.4.1.5962.1.3.14.1.20040826185059.5457/instances/1.3.6.1.4.1.5962.1.1.14.1.1.20040826185059.5457/rendered HTTP/1.1
> Host: gunter-nb:8080
> User-Agent: curl/7.64.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Access-Control-Allow-Headers: origin, content-type, accept, authorization
< Date: Tue, 15 Oct 2019 08:24:09 GMT
< Connection: keep-alive
< Access-Control-Allow-Origin: *
< ETag: "-832103520"
< Last-Modified: Tue, 15 Oct 2019 07:52:06 GMT
< Access-Control-Allow-Credentials: true
< Transfer-Encoding: chunked
< Content-Type: image/jpeg
< Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS, HEAD
< 
{ [16392 bytes data]
100 38008    0 38008    0     0   843k      0 --:--:-- --:--:-- --:--:--  843k
$ mediainfo rendered
General
Complete name                            : rendered
Format                                   : JPEG
File size                                : 37.1 KiB
FileExtension_Invalid                    : h3d jpeg jpg jpe jps mpo

Image
Format                                   : JPEG
Width                                    : 756 pixels
Height                                   : 486 pixels
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Compression mode                         : Lossy
Stream size                              : 37.1 KiB (100%)

@hackermd
Copy link
Author

Sorry, I should have been more precise. The problem only occurs with JPEG images that have been compressed in RGB color space (without color transformation), i.e. image data sets with TransferSyntaxUID=1.2.840.10008.1.2.4.50 and PhotometricInterpretation=RGB.

@gunterze
Copy link
Member

Can you provide me a sample. Typically, the value of the PhotometricInterpretation=RGB is just wrong - the application which compressed it did not adjust the PhotometricInterpretation of the uncompressed image.

@hackermd
Copy link
Author

Can you provide me a sample.

Sure, I will send you a small sample via email.

Typically, the value of the PhotometricInterpretation=RGB is just wrong - the application which compressed it did not adjust the PhotometricInterpretation of the uncompressed image.

I strongly argue against trying to provide workarounds for data sets that are not compliant with the standard. If the value of Photometric Interpretation is RGB, I would simply interpret it as such and pass it to the JPEG decoder to avoid incorrect color transformations upon decoding.

@gunterze gunterze changed the title Incorrect color space of rendered images Incorrect color space on decompression of JPEG Baseline with RGB components Oct 16, 2019
@gunterze
Copy link
Member

Fixed by dcm4che/dcm4che#565

@gunterze gunterze self-assigned this Oct 16, 2019
@gunterze gunterze added the bug Something isn't working label Oct 16, 2019
@gunterze gunterze added this to the 5.19.1 milestone Oct 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants