jp2: impossible to create lossless jpeg-2000
Swiss army knife of image processing
Brought to you by:
bfriesen
Hi,
jasper creates lossless jp2, gm doesn't:
jasper --input gm-snap.jpg --output gm-snap.jp2
gm compare -metric PSNR gm-snap.jpg gm-snap.jp2
Image Difference (PeakSignalToNoiseRatio):
PSNR
======
Red: inf
Green: inf
Blue: inf
Total: inf
vs.
gm convert gm-snap.jpg gm-snap.jp2
gm compare -metric PSNR gm-snap.jpg gm-snap.jp2
Image Difference (PeakSignalToNoiseRatio):
PSNR
======
Red: 43.01
Green: 44.13
Blue: 42.30
Total: 43.08
Both, jasper and gm convert are supposed to create lossless jp2 by default.
Best regards!
On Fri, 1 Apr 2016, aph1xeiz1ahth aph1xeiz1ahth wrote:
That is not actually the case. GraphicsMagick attempts to produce a
jp2 file with roughly similar levels of error as IJG JPEG does at
the default quality level 75.
Please see the GraphicsMagick documentation regarding -define, and in
particular '-define jp2:rate=<value>'. Specifying '-define
jp2:rate=1.0' is supposed to trigger lossless compression.</value>
Without using the '-define jp2:rate=<value>', the -quality value is
used to estimate a compression ratio which might produce results
roughly equivalent to IJG JPEG (based on my own testing).</value>
Bob
Hi Bob,
thanks for your reply. Sorry for mixing things up, but anyway:
The resulting JP2 image is still just near-lossless.
Best regards!
Last edit: aph1xeiz1ahth aph1xeiz1ahth 2016-04-01
It seems to be a jasper bug: Once you pass a rate to jasper, it becomes lossy:
Is there any possibility to prevent that gm is passing the rate option to jasper?
On Fri, 1 Apr 2016, aph1xeiz1ahth aph1xeiz1ahth wrote:
The GraphicsMagick source code is freely available so anything is
possible by editing the source code and recompiling.
Something which is not documented is that all of the Jasper encoding
option string values (from the Jasper documentation) may be passed to
the encoder in the same way as 'rate'. For example 'mode' may be
passed.
I am at the day job at the moment but it looks like adding '-quality
100' should block any addition of 'rate' to the options.
Bob
Thanks again for the hint. Passing the other jasper options works well, but the gm -quality 100 gives the same results as -define jp2:rate=1.0
I build my personal gm version without any rate support by compiling jasper with the rate setting commented out and compiling gm against it:
Thanks for your help. This workaround will work for me - as this is a jasper bug, you might want to close this ticket as wont-fix.
Best regards!
According do the author of Jasper, it is working as intended - so GM needs to change the way how it calls Jasper.
On 04.04.2016 15:39, Michael Adams wrote:
On 04.04.2016 16:07, Michael Adams wrote:
Possible fix: The automatic quality calculation did set the rate option in case the user didn't. Now it will only set rate option if quality is <99.5, so if you specify -quality 100, you will get a lossless JP2.
This problem is fixed by Mercurial changeset 14776:5017a9085264. Using '-quality 100' or '-define jp2:rate=1.0' now results in lossless compression.
It works, thank you Bob! :-)