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

Color chanel swapping for some JPEG2000 pictures #1382

Closed
nicoinn opened this issue Oct 20, 2021 · 10 comments
Closed

Color chanel swapping for some JPEG2000 pictures #1382

nicoinn opened this issue Oct 20, 2021 · 10 comments

Comments

@nicoinn
Copy link

nicoinn commented Oct 20, 2021

I believe there is a bug in the colour channel interpretation for the photo attached.

dg2img-3f096fe9d00296bc3734ac4f01b5bf60.j2k.zip

I'm trying to open it from Python and it ends up with swapped color channels --- Pillow or OpenCV will give the same result, both use OpenJPEG under the hood.

Screenshot 2021-10-20 at 10 48 41

To be noted that other JPEG2000 photos open correctly, and that this photo open correctly in many other applications (Preview, Safari).

This photo comes from a Belgian passport (stored in the biometric chip), and all Belgian passports I could get access to have the same issue.
In case anyone worries about personal information sharing, this photo is from my passport --- and I hereby grant right to anyone to play with it for the purpose of debugging this issue and nothing else ;)

@szukw000
Copy link
Contributor

@nicoinn ,

1. Which openjpeg library do you use?

2. Which program viewer did you use?

3. My viewer shows a correct image with version openjpeg2-2021-09-15 .

4. opj_decompress shows correct images (PNG,BMP,TGA).

5. I tried ValZapod proposals: same result (ffmpeg-4.4).

winfried

@nicoinn
Copy link
Author

nicoinn commented Oct 25, 2021

  1. Which openjpeg library do you use?

=> Not 100% sure. I used Pillow==8.3.2 and opencv-python==4.5.3.56, both fail.
OpenCV fails since long ago, but some older versions of Pillow were working fine. Recent ones behave exactly as OpenCV, thus I believe both rely on the same OpenJPEG lib by now.

  1. Which program viewer did you use?
    The viewers that work: Apple Preview, Safari,... many others.
    The blue photo you are looking at was displayed in a Jupyter notebook, but opening with PIL/OpenCV and saving in JPEG/PNG/BMP results in a blue photo. i.e. the blue is not a display bug.

3-4-5: well, can't say much, I haven't tried that. I'm mainly interested in opening that in Python. If you think the bug is in PIL and OpenCV, I can move there. I just thought that two completely independent implementation having the same issue may be a sign of a problem in the underlying library (?)

@ValZapod
I can confirm that photos from Russian passports open just fine, with correct colors.

The image data is raw. We read the chip with our app (svipe.com), locate the photo datastream as per the ICAO standard specs and the dg2img is a direct extraction from the passport bytes for bytes. No conversion involved.

I have a few other Belgian passport photos I could share for debugging (my kids), but I'd prefer to not post these publicly here.

I can also share the entire datagroup 2 of my passport if you think some of the metadata could help :)

@nicoinn
Copy link
Author

nicoinn commented Oct 25, 2021

And in case anyone with the same problem googled his or her way up to here, a workaround this issue is to use wand.image . Open, convert to bitmap, send blob to PIL, done... Just very inelegant.

@nicoinn
Copy link
Author

nicoinn commented Oct 25, 2021

I found that both openjpeg 2.1 and 2.4 get installed as dependencies. I suppose each of PIL/OpenCV wants its how version...

@rouault rouault closed this as completed May 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@rouault @nicoinn @szukw000 and others