Page 1 of 1

Batch convert to JPEG2000 - no way to get stable output

Posted: 2014-11-01T13:03:35-07:00
by m0n5ter
Hello. I am trying to use IM to batch convert multiple PNG files to JPEG 2000. But it turns out there is no reliable way to predict the quality value which will satisfy all the files at the same batch.

For example, I have two source files (https://drive.google.com/file/d/0B76EVd ... sp=sharing and https://drive.google.com/file/d/0B76EVd ... sp=sharing). They are both the same size/depth, but second file has more details in it.

I convert them using the same settings:

convert.exe 001.png -quality 28 001.jp2
convert.exe 002.png -quality 28 002.jp2

As a result I am getting almost unrecognizable 001.jp2, sized less than 5 kb and relatively good quality 002.jp2, almost 60 kb in size.
I have to provide different quality values to get comparable quality resulting images, something like 37 for 001 and 28 for 002. Well.. In my case I even could do this (I call convert.exe from my application, so I could supply different parameters for different files), but I can't se a way how I could calculate these values. This ruins all the idea of batch processing

Any help is appreciated.

Re: Batch convert to JPEG2000 - no way to get stable output

Posted: 2014-11-01T13:33:36-07:00
by snibgo
I don't use and can't readily view jp2, so won't comment on that.

Lossy compression will always lose detail. The question is, how much that loss matters to the image. As a rule of thumb I find that if two images have 1% difference, spread evenly across them, I can't see easily see any difference.

So, when making images for the web, I don't compress if this threshold is exceeded. A script executes two commands, compressing and comparing:

Code: Select all

convert in.png -quality XX out.jpg
compare -metric RMSE in.png out.jpg NULL:
It repeats this, increasing XX, while the difference is greater than a threshold.

This generally works well. But I still need to look at each resulting image, just in case all the lossy compression has occurred in a small area, making it noticeable.

Re: Batch convert to JPEG2000 - no way to get stable output

Posted: 2014-11-01T22:51:51-07:00
by m0n5ter
Thank you for your reply. I was thinking about this iterative approach too. But the problem is there is no metric able to detect this difference correctly. All the metrics implemented in IM (except for PHASH which is a completely different story) seem to correlate with PSNR value, so if I compress two images to JPEG 2000 with the same quality value (which in case of J2K is target PSNR value), I am getting the same numbers from other metrics as well.

For the example images I posted above,

convert.exe 001.png -quality 28 001.jp2
convert.exe 002.png -quality 28 002.jp2
compare.exe -metric RMSE 001.png 001.jp2 NULL: - this returns 2699.39 (0.04119)
compare.exe -metric RMSE 002.png 002.jp2 NULL: - this returns 2630.29 (0.0401357)

As you can see, RMSE values are pretty close to each other, they do not reflect the fact the first image is visually much-much worse damaged. According to this methic both images differ from their originals by the same amount.

Re: Batch convert to JPEG2000 - no way to get stable output

Posted: 2014-11-02T00:32:30-07:00
by snibgo
m0n5ter wrote:...quality value (which in case of J2K is target PSNR value)
Ah, I didn't know that. Yes, this means the RMSE differences are the same, more or less.

But 4% RMSE is massive, I'd say. So the surprise to me isn't that J001 looks bad, but that J002 looks good. Probably because of its fractal nature.

If we get the RMSE down to 1%, j001.jp2 looks good (to me). This needs "-quality 41", resulting size 130kb.

For the same RMSE, jpg needs "-quality 90", size 220kb.

Re: Batch convert to JPEG2000 - no way to get stable output

Posted: 2014-11-02T01:51:14-07:00
by m0n5ter
Well.. The point is not making some image look good... What I want to achieve is: user points the app to a folder full of different images, selects quality (let's say from 1 to 100), presses "Convert" button - and all the files get converted to JPEG2000 and they look the same. If user selected quality=1 - they should look the same way bad, but have small file sizes. This should be predictable. Right now it is not. Some images look good (and they are bigger files), some bad (smaller files).
The problem is the quality value should be different for different files and there is no way to calculate the value for some particular file, because there is no metric to measure real image quality (4% RMSE can look good or bad depending on the original image content, the same is for other metrics)..

Re: Batch convert to JPEG2000 - no way to get stable output

Posted: 2014-11-02T02:39:59-07:00
by snibgo
I see what you mean. There is no measure for real image quality (good/bad, visual, aesthetic quality).

However, you might find a measure that tells you how much JP2 compression an image can take. Note that j001.png has far less detail than j002.png. One measure of this would be the amount of edge:

Code: Select all

F:\web\im>%IM%convert j001.png -edge 2 -format %[fx:mean] info:
0.127248

F:\web\im>%IM%convert j002.png -edge 2 -format %[fx:mean] info:
0.223423
From this, the inverse ratios are about 22/13 or 44/26.

Code: Select all

F:\web\im>%IM%convert j001.png -quality 44 j1.jp2

F:\web\im>%IM%convert j002.png -quality 26 j2.jp2
Perhaps j1.jp2 and j2.jp2 have similar "visual quality".