best downsampling method for DSLR photographs

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

Re: best downsampling method for DSLR photographs

Post by NicolasRobidoux »

henrywho wrote:Do you mean " ... -define filter:filter=Sinc -define filter:window=Sinc -define filter:lobes=2 -distort resize ... "?
Yes.
henrywho wrote:BTW, while I am suggesting EWA Lagrange downsize as a better alternative to the common downsize+USM approach, my current choice of downsizing it still EWA-JincJinc3.
I understood.
Basically, the search for a good downsizer has been split in two:
"Neutral" downsampler.
"Sharpening" downsampler, that recent DSLR photographers will like, and which would obviate the need to use USM while simultaneously reducing the amount of aliasing.
For the second search, I'd put my biased money on one of the heavily sharpened EWA 3- or 4-lobes (heavily sharpened = blur significantly less than 1). I believe that the EWA Jinc Lanczoses are much better at antialiasing than the standard (tensor Sinc) Lanczoses.
Last edited by NicolasRobidoux on 2012-05-12T11:50:58-07:00, edited 1 time in total.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: best downsampling method for DSLR photographs

Post by NicolasRobidoux »

... and I may need to add a new acronym to my collection: TYH ("Thank you Henry") :-)
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: best downsampling method for DSLR photographs

Post by NicolasRobidoux »

@henriwho: I'd put my money on a heavily sharpened EWA Jinc Lanczos way before I'd put it on EWA Sinc Lanczos. But if EWA Catrom and Lagrange work well for you, this means that my intuition is (possibly more than) a bit off. After hearing from Anthony RE: the breakdown of Sinc-windowed Sinc in some situations (summarized here:viewtopic.php?f=22&t=20960#p84624), I would never have imagined EWA Catrom or Lagrange to be usable, let along useful! And I would think that EWA Sinc-windowed Sinc would work better than EWA Catrom or Lagrange, esp. for downsampling. So...
Last edited by NicolasRobidoux on 2012-05-16T14:10:14-07:00, edited 1 time in total.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: best downsampling method for DSLR photographs

Post by NicolasRobidoux »

(Warning: possible Big Foot in mouth sighting ahead.)

Let me make an hypothesis RE: why some, or at least some portions of, images may be more accurately downsampled is sRGB than going through linear light, even if the conversion is lossless: It's because of how a combination of clamping and averaging interacts with a nonlinear transformation.

To keep the arithmetic simple, I'll assume that sRGB is a power transformation with gamma = 2, and that I am downsampling a 9x9 image of 1 pixel wide vertical stripes down to 1 pixel with box filtering. In other words, my final 1x1 image is the average of the whole image.

Suppose that the "scene" that was captured was a greyscale affine gradient with values, from left to right, equal to 0 7 12 15 16 17 20 25 32. In linear light, the average value, and consequently the linear light value of my 1x1 downsample, is 16.

However, the black point was (coincidentally) moved to 16 in linear light, during raw processing or whatever. W.r.t. to this black point, the exact average value, in linear light, is now 0 which, converted to sRGB, is also 0.

Now, let's see what happens to the image when things are first converted to sRGB.

In linear light with this black point, the vertical stripes have values 0 0 0 0 0 1 4 9 16. In "sRGB" (remember that encoding uses the reciprocal of gamma), the values are 0 0 0 0 0 1 2 3 4.

Now, I again downsample with 9x9 box filtering.

If I use "sRGB" resizing, my new "sRGB" image has an average of (1+2+3+4)/9 = 1.11.

If I losslessly convert my "sRGB" image back to linear light, I get a one pixel linear light image with value (1+4+9+16)/9 = 3.33. If I now convert back to "sRGB", I get sqrt(3.33)=1.83.

The "sRGB" result is closer to the "perfect" one (namely 0) than the linear light result!

Conjecture If the black point was moved up significantly somehow, "darks" will be more accurate if averaged in sRGB. No matter what, however, "lights" will be more accurate if averaged in linear light (it's because the light end of "sRGB" is kinda like doing things in reverse video with something like the reciprocal of gamma).

Note that the sRGB people actually use a linear (proportional) relationship between linear light and sRGB at the dark end. That is, they flattened the nonlinearity exactly where it could hurt the most. So, the above effect should be, in general, really small. Probably insignificant.

On the other hand, things of course are more complicated than this: How does the combination of clamping and nonlinearity interact with a filter with negative weights applied to an area with both light and dark pixels?

----

Maybe I'm off the track, but I am still mystified by the preliminary results of my grad student Adam Turcotte which suggest that enlarging is better done in sRGB than linear light. The above is my attempt at making sense of this nonsense.
Last edited by NicolasRobidoux on 2012-05-13T06:30:06-07:00, edited 1 time in total.
henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: best downsampling method for DSLR photographs

Post by henrywho »

NicolasRobidoux wrote:Which one? What you call JincJinc3 (which is the "improved" version of the current EWA LanczosSharp, with a blur barely below 1)?
Over/strong-sharpening downsampler means EWA-Lagrange, not JincJincSharpest3 or 4.

BTW, orthogonal box (odd integer ratio) downsizing of real life photos like http://www.dcfever.com/cameras/enlarge.php?id=6967 is generating moire patterns. This Nikon D800E (full-frame sensor without AA filter) seems really giving fine details!
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: best downsampling method for DSLR photographs

Post by NicolasRobidoux »

@henrywho: Interesting. (TYH!)
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: best downsampling method for DSLR photographs

Post by NicolasRobidoux »

So far, when downsampling images produced with a high quality, recent vintage DSLR, my biased eye prefers the EWA (Jinc) Lanczoses over the standard (tensor Sinc) lanczoses.

Pushing -define filter:blur=VALUE down from 1 makes things sharper (of course! I think it's mentioned in Anthony's IM Resize example page). Back of the envelope says that you should never go much below sqrt(2)/2 (about .7), although Henry made pretty clear that the backs of my envelopes don't always have a good return address. This being said, I expect that you will get more moire if you push the blur down a lot.

Three lobes (the Lanczos default) makes things look more "natural".

However, lobes = 4 (-define filter:lobes=4) seems to anti-alias a bit more (no big surprise) and makes things very slightly sharper, compared to 3 lobes. When pixel peeping, as mentioned by Fred ages ago, it gives the image kind of a tight USM look, the kind that many people seem to like. On a calibrated monitor, I imagine that many would like this effect. On a Galaxy looked at indoors, say, I'm not so sure. (I am not fond of haloing.)

Comment: A lot of people like the "in your face" look. My understanding is that this annoys quite a few graphic designers. ("If my brother in law yells "Isn't the bass great!" one more time, I'm buying him a subscription to Gramophone.")

I've only looked at results of the linear light (through -colorspace) toolchain.

-----

The one thing I've not explored is that messing with blur to get more sharpness is also something that could be done with standard (tensor Sinc) Lanczos. Makes lots of sense, though: When downsampling, there is no overwhelming reason to stick to blur=1.

-----

"Too many resampling methods, too little time."
Last edited by NicolasRobidoux on 2012-05-13T11:52:34-07:00, edited 2 times in total.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: best downsampling method for DSLR photographs

Post by NicolasRobidoux »

Among them all, I like the "maximally sharpened" Jinc Lanczos 3-lobe (blur=0.88549061701764) for a fairly sharp yet "natural" look, and Jinc Lanczos 4-lobe (blur=0.88451002338585141) for a "definitely sharpened" look, a lot.

P.S. I've not compared with the (tensor) Sinc Lanczos/Mitchell mix. I have looked at mixing Sinc and Jinc Lanczos, and I feel that Sinc brings Jinc down. Back of the envelope says that someone who likes to blend Sinc Lanczos with Mitchell may actually like EWA (-distort Resize) LanczosSharp, or the "radius 3" version of EWA Jinc Lanczos, namely

Code: Select all

magick INPUT.IMG -colorspace RGB -filter Lanczos -define filter:blur=.9264075766146068 -distort Resize WIDTHxHEIGHT -colorspace sRGB -strip OUTPUT.IMG
(with the usual caveat that this uses the recent, IM7, use of -colorspace).
Last edited by NicolasRobidoux on 2012-05-13T06:42:40-07:00, edited 1 time in total.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: best downsampling method for DSLR photographs

Post by NicolasRobidoux »

'Tis the time to set me straight, guys! What do you like?
henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: best downsampling method for DSLR photographs

Post by henrywho »

NicolasRobidoux wrote:'Tis the time to set me straight, guys! What do you like?
Test cases (all downsized to 1000 on the longest side) are:
Backpack: http://dcfever.com/cameras/viewsamples. ... cture=6967
RockBeach: http://dcfever.com/cameras/viewsamples. ... cture=5587
Bike: http://dcfever.com/cameras/viewsamples. ... cture=5594

-> EWA-SincSinc3 and 4 are altering the brightness of areas packed with small high-contrast spots.
-> EWA-SincSinc2 does so too, though in a much lesser extent. And EWA-Catrom too, yet milder.
-> EWA-Lagrange is only a little less sharp but does not show this problem (at least easily detectable flipping back and fore with EWA-Robidoux).
-> Orthogonal LanczosSharp is always a bit bigger than JincJinc4Sharpest but is not really sharper.
henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: best downsampling method for DSLR photographs

Post by henrywho »

NicolasRobidoux wrote:In linear light with this black point, the vertical stripes have values 0 0 0 0 0 1 4 9 16. In "sRGB" (remember that encoding uses the reciprocal of gamma), the values are 0 0 0 0 0 1 2 3 4.
After pushing the shadow, those dark details are clipped as zero and lost (we do not have negative brightness). sRGB just happens to produce a smaller average.

Let's try another case: 30 80 130 180 235 236 237 238 239 (linear) ... avg = 178
then we boost the highlight: 50 100 150 200 255 255 255 255 255 (+20) ... avg = 197
converting to sRGB gives: 122 167 200 228 255 255 255 255 255 (take gamma 2.2 for simplicity) ... avg = 221 (sRGB) = 186 (linear)

This time we have 178 > 177 (= 197-20) > 166 (= 186-20).
NicolasRobidoux wrote:Maybe I'm off the track, but I am still mystified by the preliminary results of my grad student Adam Turcotte which suggest that enlarging is better done in sRGB than linear light. The above is my attempt at making sense of this nonsense.
Are the sRGB interpolated values dampening the artifacts? lol
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: best downsampling method for DSLR photographs

Post by NicolasRobidoux »

henrywho wrote:...
then we boost the highlight: 50 100 150 200 255 255 255 255 255 (+20) ... avg = 197
...
Indeed things may depend on whether you raise or lower the black or white points, and whether the active clamping is floor or ceiling.
-----
I'll wait for Adam's final results to comment more.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: best downsampling method for DSLR photographs

Post by Bonzo »

I am afraid that I can not view your images henrywho as the page will not load. Last time I looked at one of your pages it didn't load until I pressed stop in the browser. This time tried on IE and Firefox and they are the same - just says transfering data from dcfever.com

Both times I gave up at about 3 min.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: best downsampling method for DSLR photographs

Post by NicolasRobidoux »

@Bonzo: I put a copy of the full size backpack image here: http://web.cs.laurentian.ca/nrobidoux/m ... iginal.jpg. Indeed, it took me some time to download this from the (Honk Kong?) server.
P.S. Removed, because there may be copyright issues.
Last edited by NicolasRobidoux on 2012-05-18T17:14:54-07:00, edited 1 time in total.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: best downsampling method for DSLR photographs

Post by NicolasRobidoux »

I put some downsamples, all through linear light (with -colorspace), and all with size 640x427, here:
Standard tensor Sinc-windowed Sinc Lanczos 3: http://web.cs.laurentian.ca/nrobidoux/m ... /Sinc3.png
Standard tensor Sinc-windowed Sinc Lanczos 4: http://web.cs.laurentian.ca/nrobidoux/m ... /Sinc4.png
Jinc-windowed Jinc EWA Lanczos 3 "maximally sharpened": http://web.cs.laurentian.ca/nrobidoux/m ... arpest.png
Jinc-windowed Jinc EWA Lanczos 4 "maximally sharpened": http://web.cs.laurentian.ca/nrobidoux/m ... arpest.png
Jinc-windowed Jinc EWA Lanczos 3 "radius 3": http://web.cs.laurentian.ca/nrobidoux/m ... adius3.png
Jinc-windowed Jinc EWA Lanczos 4 "radius 4": http://web.cs.laurentian.ca/nrobidoux/m ... adius4.png
EWA RobidouxSharp: http://web.cs.laurentian.ca/nrobidoux/m ... xSharp.png

I'll add a few after dinner.

It's not as if the differences just jump at you.

@Henry: Could you let me know if it's OK that I posted these images? If not, I'll remove them.
Last edited by NicolasRobidoux on 2012-05-13T16:18:36-07:00, edited 1 time in total.
Post Reply