resizing photos

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
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

resizing photos

Post by GreenKoopa »

I have read all of the usage examples for resize and photos (and as much of filters as I could absorb). I am looking for a good default or starting point.

-resize vs -distort
Is there any advantage to -resize other than simplicity and possibly speed? -distort is more flexible and I'm usually cropping when resizing. When rotating and resizing, I assume it must better to resample in one pass.

-filter
It seems -resize defaults to Lanczos and -distort defaults to Robidoux. Is one of these better for down-sampling photographs? My cropped digital photos are 2 to 16 megapixels.
  • Use case 1: screen resolution (0.2-0.6 MP, 15-45% scale)
  • Use case 2: print resolution (60-110% scale, most frequently with a 1-3° rotate)
  • Use case 3: binning (use -scale, which is -filter box -resize)
I use Q16 (because it seems to be the default).

Sharpening
I have no experience with sharpening (sad but true). Is it better to do this with the resize filter, -unsharp, or both?

-colorspace and -gamma
I have been resizing without leaving sRGB. Apparently this has been my biggest mistake. RGB seems best, unless someone knows when Lab is better.


Hopefuly it's okay to use Anthony's photo beijing.jpg to demonstrate what I currently do:

Code: Select all

convert beijing.jpg -auto-orient -strip ^
-crop 1200x1800+334+500 ^
beijing_print_4x6.jpg

convert beijing.jpg -auto-orient -strip -quality 90 ^
-set option:distort:viewport 1200x1600+334+610 -set option:distort:scale %%[fx:576/1600] -distort SRT 0 ^
beijing_576.jpg

convert beijing.jpg -auto-orient -strip -quality 90 ^
-set option:distort:viewport 1200x1600+335+616 -set option:distort:scale %%[fx:576/1600] -distort SRT -2.2 ^
beijing_r_576.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: resizing photos

Post by fmw42 »

See Nicholas Robidoux's page on recommendations. He tends to like filters that remove artifacts. If one wants a filter that produces sharp results, try either Catrom or Lagrange.

http://www.imagemagick.org/Usage/filter/
http://www.imagemagick.org/Usage/filter/nicolas/
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: resizing photos

Post by snibgo »

GreenKoopa wrote:When rotating and resizing, I assume it must better to resample in one pass.
I agree with the assumption, although I haven't tested it.
GreenKoopa wrote:It seems -resize defaults to Lanczos and -distort defaults to Robidoux. Is one of these better for down-sampling photographs?
I know too little about filters.
GreenKoopa wrote:Is it better to do this with the resize filter, -unsharp, or both?
I use "-unsharp", but an alternative may be better.
GreenKoopa wrote:RGB seems best, unless someone knows when Lab is better.
I resize in sRGB space. Even when blowing up pixels, I can't see any difference between this or converting to RGB or Lab before the resize, and then converting back to sRGB. "compare -metric RMSE" confirms the difference is < 1%.
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: resizing photos

Post by anthony »

GreenKoopa wrote:I have read all of the usage examples for resize and photos (and as much of filters as I could absorb). I am looking for a good default or starting point.

-resize vs -distort
Is there any advantage to -resize other than simplicity and possibly speed? -distort is more flexible and I'm usually cropping when resizing. When rotating and resizing, I assume it must better to resample in one pass.
Well they do use two very different methods. resize using very fast 2 pass method, distort using a single pass but much slower method. And yes doing the resample in a single pass is better, but not always easy to achieve.

Resize as two pass method stores intermedate data in an image, and as such values can lose quality (unless you use HDRI version of IM.

However distort is much more general, It can not only rsize, but it can also distort (rotate, shear, skew, etc). Scaling (what resize is really doing) is generally the smallest, simplest aspect of a distort.

Also with distort you can specify a 'viewport', something which is actually required, though IM has some 'default' viewports (depending on if -distort or +distort is used). As such distort will let you crop at the same time and thus avoid doing calculations for areas that you would junk anyway.

-filter
It seems -resize defaults to Lanczos and -distort defaults to Robidoux. Is one of these better for down-sampling photographs? My cropped digital photos are 2 to 16 megapixels.
  • Use case 1: screen resolution (0.2-0.6 MP, 15-45% scale)
  • Use case 2: print resolution (60-110% scale, most frequently with a 1-3° rotate)
  • Use case 3: binning (use -scale, which is -filter box -resize)
I use Q16 (because it seems to be the default).
The two filters were picked as 'reasonable defaults' Robidoux is essentially a slightly sharper Lancoz, and turns out to be almost exactly equivalent to the other default 'Mitchell', which is actually another default for resize!

Really they are all just good compromises for general use.

Code: Select all

[b]Sharpening[/b]
I have no experience with sharpening (sad but true). Is it better to do this with the resize filter, -unsharp, or both?
True sharpening is often down as part of the filter. But people like controls, and so often like to do an extra unsharp, (which has thresholding) afetrwards. Photoshop makes that a default!
-colorspace and -gamma
I have been resizing without leaving sRGB. Apparently this has been my biggest mistake. RGB seems best, unless someone knows when Lab is better.
There has been debate as to whether doing resize in sRGB is actually better! Yes it makes 'averaged colors' mathematically correct (a black-white hash will become a correct perfect gray) But it seems the cost is in increase in halo effects.

Basically use what works for you. I myself don't really bother, but then I am not a photographer, and typical can see the artifacts using linear-RGB generates more that the color distortions I get from no colorspace change.

Some people actually swear by using LAB or LUV for resize/distorts.
Hopefuly it's okay to use Anthony's photo beijing.jpg to demonstrate what I currently do:

Code: Select all

convert beijing.jpg -auto-orient -strip ^
-crop 1200x1800+334+500 ^
beijing_print_4x6.jpg

convert beijing.jpg -auto-orient -strip -quality 90 ^
-set option:distort:viewport 1200x1600+334+610 -set option:distort:scale %%[fx:576/1600] -distort SRT 0 ^
beijing_576.jpg

convert beijing.jpg -auto-orient -strip -quality 90 ^
-set option:distort:viewport 1200x1600+335+616 -set option:distort:scale %%[fx:576/1600] -distort SRT -2.2 ^
beijing_r_576.jpg
No problem. It is a photo I personally took. and find it a useful 'test photo'.
Especially for Tilt Shift Effects as it is a nice 'landscale'. with little in the way of vertical walls.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: resizing photos

Post by GreenKoopa »

Thank you all for the advice.
anthony wrote: Photoshop makes that a default!
What was that about Photoshop?
snibgo wrote: I resize in sRGB space. Even when blowing up pixels, I can't see any difference between this or converting to RGB or Lab before the resize, and then converting back to sRGB.
I think colorspace would matter less when upscaling.

For most photos it probably doesn't matter. I had a photo of fireworks with sharp lightness contrasts and another with sharp hue contrasts. Resizing and sharpening had weird effects on these so I started thinking.

I wonder if ones choice depends on when in their workflow they resize. Binning as a first step to reduce noise may be a very different operation than resizing and sharpening as the final step.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: resizing photos

Post by anthony »

GreenKoopa wrote:
anthony wrote: Photoshop makes that a default!
What was that about Photoshop?
It does a 'unsharp' on the results of a resize.
See IM Examples, Resize and Scaling, Unsharped Resizing (USM) -- Photoshop Resize Technique
http://www.imagemagick.org/Usage/resize/#resize_unsharp
I think colorspace would matter less when upscaling.
Perhaps. As I have said previously. I generally don't do anything special.
So really if it seems to be a problem, then try something else. There is no ideal solution, just personal preference for the situation.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: resizing photos

Post by snibgo »

GreenKoopa wrote:
snibgo wrote:I resize in sRGB space. Even when blowing up pixels, I can't see any difference between this or converting to RGB or Lab before the resize, and then converting back to sRGB. "compare -metric RMSE" confirms the difference is < 1%.
I think colorspace would matter less when upscaling.
Sorry, I was unclear.

My standard workflow doesn't include upscaling, only downscaling. At that stage, my photos are sRGB. I have experimented by doing the downsizing in sRGB, or converting to Lab or RGB before the resize and converting back to sRGB after the resize.

I can't see any difference in the results, even when I examine critically by enlarging the results so one image pixel occupies many screen pixels.
snibgo's IM pages: im.snibgo.com
Post Reply