Sign in to follow this  
null54

JPEG 2000 Filetype (2018-09-26)

Recommended Posts

7 hours ago, StephanB79 said:

please include lossless compression mode and allow metadata in next release of your jp2 plugin.

 

The plugin should use lossless compression when the quality is set to 100.

As for metadata the plugin will save the image resolution, but the JasPer library does not support saving any other metadata formats.

Share this post


Link to post
Share on other sites

Thanks for your plugin, actually thanks for all of them! I have used your WebP plugin for a while and just stumbled on a need to explore JPEG2000 for another project.

 

One thing I've noticed as I have gotten acquainted with pdn-jpeg-2000, though, is that, when saving a file, the slider is labeled "Quality" but maps to JasPer's "rate" (/100). For example, Quality 50 in the plugin currently maps to rate 0.50.

 

I don't think this mapping works very well. Here's my reasoning: with standard JPEG, a regular user may not know what quality technically means, but from experience they learn that something in the 90's usually has few artifacts, 80's can be OK, and something below 50 or 60 is likely to look bad.

 

The JPEG 2000 rate, though, appears to literally be the target file size for the .JP2 file, expressed as a percentage of the size of the uncompressed image. Say I take a test image that is 512x512 -- that is 768KB uncompressed (512*512*3 bytes). If I save it with pdn-jpeg-2000 "Quality" 25 (== rate 0.25), I'm going to get a JP2 file that's approximately 768KB * 0.25 = 192KB. If I save it with rate 0.10, I'll get a JP2 file that is approximately 76.8KB.

 

Just multiplying the rate by 100 gives someone "Quality" numbers that are not aligned with the intuitive notion of regular JPEG quality at all. For example, with a copy of the infamous Lena.png image I tested with, everything pdn-jpeg-2000 Quality 57-99 results in what appears to be a byte-for-byte identical .jp2 file, roughly the size of the lossless version. "Quality" 12 (rate 0.12, or about an 8:1 compression ratio) is the first value that ends up with a .JP2 file smaller than a Q95 standard .JPG. Quality 12 in standard JPEG would be a disaster, but it appears to be a somewhat conservatively-encoded JP2.

 

This just seems to be how JPEG 2000 and JasPer in particular works; it's not content-adaptive but very focused on hitting a certain bitrate / compression ratio.

 

I can think of two potential alternatives to the current quality<->rate mapping:

  1. Change the slider to be "Rate" and assume the user knows what they're doing if they are saving JPEG2000 files. If you go this route, it might be more useful to specify the rate in the UI as the reciprocal compression ratio (i.e., 8:1 instead of 0.125) since most of the lossy rates between 0.75 and 0.99 are rarely even different, yet 0.01 is a pretty big change for compression rates between 0.01 and 0.10.
  2. Keep the Quality slider, but use the non-linear conversion formula ImageMagick used to use when they used JasPer (they have apparently since switched to OpenJPEG and I guess it's different now.) I looked it up in their v7 source code, and it is roughly Rate = 100/(115-Quality)^2 for lossy mode, with Q100 mapped to lossless.

Personally I like the ImageMagick curve; working it out in Excel, the mapping goes like: Quality 95 = 4:1 (rate 0.25), Q90 = 6.25:1 (rate 0.16), Q85 = 9:1 (rate 0.111), Q75 = 16:1 (rate 0.0625), Q65 = 25:1 (rate 0.04), Q45 = 49:1 (rate 0.0204), Q15 = 100:1 (rate 0.01). A little conservative, perhaps, but reasonably intuitive if you are used to standard JPEG quality values.

 

Also, what is a sensible default? The current default of 0.95 seems like it's rarely what someone would want, since it's usually the same size as lossless, but with the potential for minor errors. Maybe something between 8:1 and 12:1 is more appropriate since it's closer to a standard JPEG compression ratios?

Share this post


Link to post
Share on other sites

Thanks for the detailed bug report and analysis.

 

I will most likely be changing the plugin to use the ImageMagick formula with a default quality of 85 (compression ratio of 9:1).

 

22 hours ago, ektekmek said:

The JPEG 2000 rate, though, appears to literally be the target file size for the .JP2 file, expressed as a percentage of the size of the uncompressed image.

 

That is exactly what JasPer does (at least the version that is currently used by this plugin).

 

Share this post


Link to post
Share on other sites

Changed the quality slider in the save dialog to more closely match the JPEG compression ratios.
Reduced memory usage when loading images.
Fixed the loading of gray scale images with an alpha channel.

 

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this