Page 1 of 1
Quality loss after compressing JPEG image to lossless JP2
Posted: 2015-08-25T05:14:04-07:00
by johan
After compressing a JPEG image to
lossless (!) JP2, the pixel values of the resulting JP2 are not identical to those of the source JPEG. Full description, tests and sample images here:
https://github.com/bitsgalore/jpegToLosslessJP2
The issue doesn't occur for other input formats (and neither for different output formats), and it looks like IM somehow doesn't properly decode the source JPEG.
Issue encountered with ImageMagick 6.8.9-8 Q16 x64 2014-08-26; running under Windows 7.
Re: Quality loss after compressing JPEG image to lossless JP2
Posted: 2015-08-25T09:13:13-07:00
by fmw42
I do not believe you can start with a simple jpg and save to jp2 and expect to get a perfect comparison. You lose quality when the jpg is loaded and decompressed. Try starting with jp2 and going to another jp2. However, I am not a compression or JP2 expert and would defer to some one who is more expert in the field.
Re: Quality loss after compressing JPEG image to lossless JP2
Posted: 2015-08-25T09:31:59-07:00
by johan
If you look at the JPEG to JP2 via TIFF example in my original link, you see that it is actually possible to get a perfect match (also if I do the comparison between the source JPEG and the result TIFF both are identical). So it is definitely possible, but the JPEG decode behaviour appears to depend on the selected output format (which shouldn't be the case).
Re: Quality loss after compressing JPEG image to lossless JP2
Posted: 2015-08-25T10:50:36-07:00
by fmw42
Perhaps I misunderstand, but if you start with a tiff, (unless it has lossy jpg compression,) then there is no decompression involved in reading the tiff and then converting it to JP2. So the comparison of tiff to jp2 should be exact.
compare -metric PSNR balloon.jpg balloon_im.tiff balloon_im_from_tiff.jp2 NUL
I am not sure IM can do a 3 image compare. So I am not sure what which images are being compared. Also it should be null: not NUL
Try comparing only two images at a time.
Re: Quality loss after compressing JPEG image to lossless JP2
Posted: 2015-08-25T13:16:18-07:00
by magick
Try convert image.jpg -quality 0 image.jp2.
Re: Quality loss after compressing JPEG image to lossless JP2
Posted: 2015-08-25T13:26:16-07:00
by dlemstra
I just submitted a patch to our git repository to no longer use the quality of the input image but use the specified '-quality' instead. You can use magick's until the next version has been released.
Re: Quality loss after compressing JPEG image to lossless JP2
Posted: 2015-08-26T02:23:28-07:00
by johan
Great, I can confirm that setting -quality to 0 fixes the issue. Changing the default behaviour makes a lot of sense, good to see this will be changed in the next version. Many thanks all for the fast responses!
Re: Quality loss after compressing JPEG image to lossless JP2
Posted: 2015-08-26T05:11:23-07:00
by johan
fmw42 wrote:
I am not sure IM can do a 3 image compare. So I am not sure what which images are being compared. Also it should be null: not NUL
Oops, I see I made a typo there; that should've been:
Code: Select all
compare -metric PSNR balloon.jpg balloon_im_from_tiff.jp2 NUL
Result is still 1.#INF though.
(BTW NUL seems to be correct for Windows, if I use null it creates a diff file with that name!)
Re: Quality loss after compressing JPEG image to lossless JP2
Posted: 2015-08-26T05:34:21-07:00
by dlemstra
It should be 'null:' not 'null'.