Summary: reducing (downsizing) natural images

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
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Summary: reducing (downsizing) natural images

Post by NicolasRobidoux » 2012-08-10T07:38:26-07:00

Here is my overall take on viewtopic.php?f=1&t=20992 and some other threads (discussions tend to bleed between related topics). This is still evolving but I am fairly confident that what follows will survive additional investigation.
The following is most pertinent to the common sRGB to sRGB natural image reduction (or thumbnail production) but the main ideas should apply in general. This is probably is a good guide for synthetic (CG) images as well, but less testing has been done with those. Transparency channels may also complicate matters.

FOR BEST QUALITY
Rule 1. Always go through linear light (RGB colourspace in ImageMagick): http://www.imagemagick.org/Usage/resize ... colorspace.
Heed the warning RE: older versions than IM6.7.5.
Rule 2. At equivalent sharpness/faithfulness, EWA (-distort resize) filters give better results (less moire, jaggies and halo) than orthogonal (-resize) filters.
Rule 3. Unless you are really averse to haloing, use the EWA Lanczos 3,4,5 family of Jinc-windowed Jinc filters. (LanczosSharp, LanczosRadiusN and LanczosSharpest are members of this family.) That is, choose
  • LOBES among 3,4,5 (maybe 2 if you really dislike haloing, in which case you probably should consider EWA Mitchell, Robidoux, Quadratic or Triangle instead of EWA Lanczos),
  • BLUR between .7 and 1.0 (values between .88 to .95 generally work well),
  • SIZE according to the syntax given in http://www.imagemagick.org/Usage/resize/#resize, for example WIDTHxHEIGHT,
and run

Code: Select all

convert INPUT.IMG -colorspace RGB -filter Lanczos -define filter:lobes=LOBES -define filter:blur=BLUR -distort Resize SIZE -colorspace sRGB OUTPUT.IMG
A larger value of LOBES decreases moire (good) and jaggies (good), and increases halo (bad) and perceived sharpness (good).
A smaller value of BLUR increases sharpness (good), moire (bad) and jaggies (bad).
When downsampling (downsizing), the exact value of BLUR appears to matter less than when upsampling (enlarging). For specific suggestions, see the aforementioned thread.
Rule 4. With well chosen parameters (which depend on content and personal preferences), you should not need to apply unsharp masking (USM) afterward, and things should look more natural than if you rely on USM to keep things sharp. At least, you should not have to USM as much to regain sharpness.
Disclaimer: What precedes is my personal opinion, and does not necessarily represent the opinions of others, including ImageMagick developers. Everyone is of course welcome to comment below.

Note: There are shortcuts to some of the suggested parameter values. The above is meant to be tweakable, not concise.
Last edited by NicolasRobidoux on 2012-08-10T13:16:29-07:00, edited 12 times in total.

henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: Summary: reducing (downsizing) natural images

Post by henrywho » 2012-08-10T09:39:22-07:00

Are "LanczosRadiusN" and "LanczosSharpestN" available directly in IM6 or 7 now?

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

Re: Summary: reducing (downsizing) natural images

Post by NicolasRobidoux » 2012-08-10T09:42:01-07:00

henrywho wrote:Are "LanczosRadiusN" and "LanczosSharpestN" available directly in IM6 or 7 now?
No.

henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: Summary: reducing (downsizing) natural images

Post by henrywho » 2012-08-10T09:49:03-07:00

A small note that some ppls like to take BW (gray) photos but IM6 behaves weirdly with gray photos and -colorspace options. Better use -gamma with gray photos for the time being.

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

Re: Summary: reducing (downsizing) natural images

Post by fmw42 » 2012-08-10T10:18:21-07:00

henrywho wrote:A small note that some ppls like to take BW (gray) photos but IM6 behaves weirdly with gray photos and -colorspace options. Better use -gamma with gray photos for the time being.
If you want to convert to grayscale in newer IM releases, it will be converted to linear. Before it was kept as non-linear sRGB. To get the old results add -set colorspace RGB before -colorspace gray.

Post Reply