Decoding a JP2 that contains an embedded ICC profile with OpenJPEG 1.5 (command-line tool) results in a degraded output image. Original test data here.
We're starting with the image below, which is a losslessly compressed JP2 that was created from a source TIFF using Aware's encoder:
Below is a summary of the image's main characteristics (extracted with ExifTool 8.99):
Note that the image contains an embedded ICC profile, which I'll get back to later.
So let's decode this back to TIFF using the latest version (1.5.0) of OpenJPEG. I used following command line:
j2k_to_image -i target.jp2 -o target_oj.tif
This is what the resulting image looks like (not a pretty sight):
Although the visual check really says enough, I also used ImageMagick's compare tool to count the number of pixels tht are changed, relative to the source image. For this I used the following command (note I used the upstream source TIFF from which the JP2 was created rather than the actualJP2 as a reference; this is because I encountered problems getting the latest version of IM to work with JPEG 2000, don't ask why!):
compare -metric AE -verbose target.tif target_oj.tif diff.tif
I.e. all pixels have been changed.
As a control, I repeated the same conversion in Irfanview, which resulted in this:
Again I counted the number of changed pixels:
compare -metric AE -verbose target.tif target_iv.tif diff.tif
I.e. all pixel values are unchanged relative to the source image (note that neither OpenJEG nor IrfanViewpreserved the ICC profile, although this isn't really important here).
As I was wondering whether the embedded ICC might have anything to do with these results, I also created a version of the JP2 with the ICC profile removed, and then decoded the image with OpenJPEG again:
j2k_to_image -i target_noICC.jp2 -o target_noICC_oj.tif
Here's the resulting image:
Now that looks more like it! So let's compare the pixel values again:
compare -metric AE -verbose target.tif target_noICC_oj.tif diff.tif
I.e. all pixel values are unchanged relative to the source image!
So apparently something goes wrong when OpenJPEG tries to decode a JP2 whose colour space is defined by an ICC profile. This results in a degraded output image where the pixel values of the original source image are not preserved.
target.jp2 - created from target.tif
target_noICC.jp2 - same, without ICC profile
target_oj.tif - decoded from target.jp2 using OpenJPEG
target_iv.tif - decoded from target.jp2 using IrfanView
target_noICC_oj.tif - decoded from target_noICC.jp2 using OpenJPEG
The December 2012 Windows binaries of OpenJPEG 2.0 show the same behaviour (using opj_decompress).