a way to compare image quality after a resize?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
antoan
Posts: 2
Joined: 2011-09-04T13:14:43-07:00
Authentication code: 8675308

a way to compare image quality after a resize?

Post by antoan » 2011-09-04T13:26:03-07:00

Hello,

I am looking for a way to test for image quality degredation after a resize operation, programmatically. I understand 'image quality' is quite a loose term and the problem isn't specific to imageMagik, but was wondering if the library provides an easy way to do this?

Alternatively, would greatly appreciate any suggestions relating to how this type of thing is done in general - ie obtaining a quality metric for a given image, before and after a rezise operation.

Thanks in advance

NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: a way to compare image quality after a resize?

Post by NicolasRobidoux » 2011-09-04T17:38:01-07:00

Do I understand correctly that you want to evaluate the quality of the image without having a reference version of the same size as the enlargement? (So you are not doing the usual: reduce the image somehow, and then re-enlarge it, and compare the result of the re-enlargement with the original "full size" image.)

That is, you want a quality metric which does not know what the "ideal" is?

antoan
Posts: 2
Joined: 2011-09-04T13:14:43-07:00
Authentication code: 8675308

Re: a way to compare image quality after a resize?

Post by antoan » 2011-09-05T02:45:25-07:00

Hi there, NicolasRobidoux.

To clarify, I want to resize an image to make it smaller, and then have some way of evaluating (any) loss of quality as a result of the resize operation, with respect to the original image.

NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: a way to compare image quality after a resize?

Post by NicolasRobidoux » 2011-09-05T03:23:25-07:00

antoan wrote:...To clarify, I want to resize an image to make it smaller, and then have some way of evaluating (any) loss of quality as a result of the resize operation, with respect to the original image.
Then, because you don't have an "ideal" reference image at the smaller size, I don't have something off the shelf for you. (Not even an article to point you to.)

Think about it: If there was, you would have an objective function to optimize over. So, you could try "everything," and then select the result that scores the highest.

The fact that there is a bestiary of methods, still (endlessly) argued over, is evidence that there is no such thing.

So: Use your eyes, or the eyes of those who will use the images, in the context where they are used.

User avatar
glennrp
Posts: 1163
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: a way to compare image quality after a resize?

Post by glennrp » 2011-09-05T06:57:25-07:00

antoan wrote:Hi there, NicolasRobidoux.

To clarify, I want to resize an image to make it smaller, and then have some way of evaluating (any) loss of quality as a result of the resize operation, with respect to the original image.
Comparisons generally have to be between images with the same dimensions. Not exactly what you want, but I suppose you could rescale it back to the original size and see how much the image degraded over the round-trip.

User avatar
fmw42
Posts: 23429
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: a way to compare image quality after a resize?

Post by fmw42 » 2011-09-05T10:49:49-07:00

glennrp wrote:
antoan wrote:Hi there, NicolasRobidoux.

To clarify, I want to resize an image to make it smaller, and then have some way of evaluating (any) loss of quality as a result of the resize operation, with respect to the original image.
Comparisons generally have to be between images with the same dimensions. Not exactly what you want, but I suppose you could rescale it back to the original size and see how much the image degraded over the round-trip.

But then you don't know how much of the degradation is due to the downsizing or upsizing.

I know of no way other than visual inspection, which is really personal preference and can be different from person to person, if you don't have a "perfect" reference to compare to. The only thing you look for is distortions, jaggedness, aliasing, etc. But I know of no way to measure those without a reference. Nicolas pretty much summed up the situation and he is an expert on resampling.

NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: a way to compare image quality after a resize?

Post by NicolasRobidoux » 2011-09-06T06:26:58-07:00

To summarize:

Quality metrics generally are error metrics: You compare a result image with a same size "reference" image, assumed to be "perfect".

So, if you want to estimate the corruption when downsizing, you need to either have 1) a (good approximation of a) reference image of the same size as the reduced image, or 2) you need to re-enlarge the reduced version back to the original size and compare.

If all you have is a full size reference image, you're stuck, because what you'll end up measuring is either 1) how well your downsampling method matches the output of whatever method you used to produce the smaller size "reference" (in which case the winner among all methods is automatically the method you used to produce the smaller size "reference"!) or 2) how well your downsampling method matches your upsampling (enlargement) method. (There is yet a third approach, which involves resizing both the original and the reduced image to a different common size.)

1) is pointless (we know the winner from the get go). 2) depends very strongly on the method chosen to re-enlarge; however, because there is even less agreement regarding what the "best" enlargement method that what the "best" reduction method is, the result of 2) depends on an answer for which there is even less of a consensus than for the original question!

------

This being said, there is a simple answer to your implicit question: What is the best filter for downsizing?

A commercial client of mine, among a small collection of suggested methods for downsizing to produce thumbnails which are then heavily (but carefully) jpeg compressed, chose (with his team: this comes from a consensus-run business) the default -distort resize method. So, my totally unbiased advice is: Just use

Code: Select all

convert big.png -distort resize 50% small.png
http://www.imagemagick.org/Usage/distorts/#resize

(Of course, the default -distort resize method is the Robidoux filter, a filter that I do not particularly like. But it seems to be pretty balanced when downsizing, and its results JPEG compress pretty well so OK...)

-----

P.S. Wise words from my father:
Trust me: Don't trust anyone who begins a sentence with "Trust me".

Post Reply