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:...
The "-gamma" operator is useful some times, when I wanna downsize CG as web buttons. "... -gamma 2 .... -resize 10% .... -gamma 0.5" does help building "strong" borders for dark details over light background. 8)
Cool trick.

-----

Also, except for the mysterious quantitative upsampling results in Adam Turcotte's upcoming thesis (at least as far as the preliminary results go), I'm pretty convinced that linear light should be the rule.
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:Conjecture With my favorite methods, no negative total weight can occur.
as long as that there is no programming or compiler bugs (or different rounding conventions, etc.) 8)

btw, though not DSLR, Nokia is introducing a 41MP mobile phone with a 1/1.2" sensor. :shock: Information and samples at:
http://www.slashgear.com/nokia-808-pure ... -27215885/

Its whitepaper claims its in-camera"oversampling" from 38MP to 5MP being "noise free, yet incredibly detailed and defined". IMO, it's worse than orthogonal box. Should Nokia have read this thread and tried EWA-JincJinc3, -Lagrange or -Catrom, they will definitely drop their jaws. An ARM-optimized implementation will be a killer companion of their 38MP sensor, slashing even IP4s.
henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: best downsampling method for DSLR photographs

Post by henrywho »

[duplicate post deleted]
Last edited by henrywho on 2012-05-29T07:06:23-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 »

henrywho wrote:...Should Nokia have read this thread and tried EWA-JincJinc3, -Lagrange or -Catrom, they will definitely drop their jaws. ...
Not to mention Adobe.

P.S. If I want more sharpness when downsampling, I think I prefer the even sharper EWA Jinc-windowed Jincs (Lanczos3Radius3, for example). But I've not looked quite enough to make this more than an uneducated opinion. Nonetheless, the evolving rule of thumb for me is that EWA Jinc-windowed Jinc is a better family for downsampling (adjusted through the blur parameter) than EWA Keys splines (adjusted through the b parameter). It's just that results are really predictable with Keys cubics w.r.t. parameter variations. Less so with the Jinc-windowed Jincs.

So, if I'm going to choose a few downsamplers, I'd base my small catalog on EWA Jinc-windowed Jincs, and if I wanted an easily tuneable family (that runs quite a bit faster too), I'd go with EWA Keys splines. But again, I'm not really sure.

And if I'm going to use only one, and go for "natural looking", I'll go with EWA LanczosSharp at this point. I however understand that "natural looking" may not be as popular as "in your face".
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:...Should Nokia have read this thread and tried EWA-JincJinc3, -Lagrange or -Catrom, they will definitely drop their jaws. An ARM-optimized implementation will be a killer companion of their 38MP sensor, slashing even IP4s.
BTW, with a suitable combination of image geometry convention and integer downsampling ratios, you can make EWA runs almost as fast as tensor methods: You can implement it so it's equivalent to convolve -> decimate (and of course, you'd compute the convolution result only at the decimated locations). The only "win" of tensor methods here is that the convolution can be implemented as two 1D passes, which cuts some flops. In any case, you pretty much get a constant flop count to compute any integer downsample, like for "exact integer ratio" box filtering, and you can arrange the computation so that memory is accessed efficiently. There's not even transparency to deal with, and dead pixels can be accomodated simply and efficiently. Trimming things a little near the boundary to get dimensions that are exact multiples of the ratio (or one more than a multiple of the ratio, if using the "align centers" image geometry convention) should be insignificant with so many pixels. You'd want to trim anyway to minimize boundary effects.

If the results don't look good, why didn't Nokia simply implement, say, tensor Lanczos3 or, as Luiz suggested, a directly computed blend of tensor Lanczos3 and Mitchell or Cubic or Gaussian blur? You have to have a really smart supersampling -> downsampling combination to do better. (Not that Nokia engineers are not smart...)
Or even exact ratio box filtering followed by a well-chosen USM (like vipsthumbnail)?

But then, what do I know? Will need to have a look at the white paper when I have a minute. At this point I'm lecturing without really knowing.
henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: best downsampling method for DSLR photographs

Post by henrywho »

That "whitepaper" is for marketing guys, nothing technical

I tend to believe that they are re-using the quick resample routine (the one for realtime display and "pureview" digital zoom) for that "oversampling" task, giving the sub-par results.
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 »

fmw42 wrote:Can you give your comments about techniques for upsampling, as well?
http://nuit-blanche.blogspot.ca/2012/05 ... d-its.html
User avatar
Dane Vandeputte
Posts: 14
Joined: 2012-07-01T18:26:53-07:00
Authentication code: 13
Location: Illinois, USA

Re: best downsampling method for DSLR photographs

Post by Dane Vandeputte »

NicolasRobidoux wrote: I wager that Eric Brasseur, in his famous post http://www.4p8.com/eric.brasseur/gamma.html, could have fixed things so that the Dalai Lama disappears when downsized through linear light, but looks fine when processed through sRGB.
Yes, this is possible, and just as the Dalai Lama disappears from the downsized linear light image, so too has he disappeared from the unscaled image.

Original image:
Image

50% via sRGB:
Image

50% via linear light:
Image

Yet again, downsizing in linear light has provided results most consistent with the original image.
Digital image processing and photography enthusiast :)
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 »

Dane Vandeputte wrote:...
Yes, this is possible, and just as the Dalai Lama disappears from the downsized linear light image, so too has he disappeared from the unscaled image.
...
Thank you.
But this is not quite what I meant.
I meant: The Dalai Lama is visible in the full size image, disappears in the linear light toolchain image, and remains in the sRGB toolchain image.
User avatar
Dane Vandeputte
Posts: 14
Joined: 2012-07-01T18:26:53-07:00
Authentication code: 13
Location: Illinois, USA

Re: best downsampling method for DSLR photographs

Post by Dane Vandeputte »

NicolasRobidoux wrote: Thank you.
I was glad to do it. :)
But this is not quite what I meant.
I meant: The Dalai Lama is visible in the full size image, disappears in the linear light toolchain image, and remains in the sRGB toolchain image.
I believe that what you seek is impossible, at least by any method resembling what Eric did.

Let me give a brief explanation as to how Eric's original image was constructed:

Given an input color, c, we seek two new colors, x and y, such that

(x + y)/2 = constantGray

and

((x^gamma + y^gamma)/2)^(1/gamma) = c


We can solve for x and y using numerical methods, unless we simplify using a gamma of 2, in which case there is a closed form solution. In any case, since either solution involves taking roots, we have to be careful about the values allowed to c. Furthermore, we want x and y to be limited to [0, 1]. As it turns out, if we assume that c is in [0, 1], we can solve both problems by applying a linear transformation to c.

-------

Now, if we wish to apply the same thinking to the reverse situation in which the Dalai Lama disappears from the image scaled via linear light and is visible in the image scaled via nonlinear light, we simply swap c and constantGray.

(x + y)/2 = c

and

((x^gamma + y^gamma)/2)^(1/gamma) = constantGray

The first equation cannot be changed because it ensures that the Dalai Lama will be visible in the nonlinear light downsized image. Furthermore, the second equation cannot be changed because it ensures that the Dalai Lama will disappear from the linear light downsized image. These are the two equations I used in the construction of the images in my previous post (using a gamma of 2.2).
Therefore, if we seek only two colors to replace each original color, the unscaled image will always appear gray. The only possibility I can think of to obtain what you want would be to replace each original color with three (or more) colors, but then I think the unscaled image would start to appear more and more convoluted. Even then, if you were to stand far enough away from your screen, I believe the unscaled image would still very likely appear as gray.

If you have any ideas how one might obtain the results you're looking for, I'd be very interested to read them. :)
Digital image processing and photography enthusiast :)
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 »

Dane: I think that I assumed there was symmetry where there is not, and indeed the full size and reduced images are always most similar in linear light in this situation.
Thank you!
(I really like how scrolling within my browser window makes the Dalai Lama jump up and down in the strobe light.)
User avatar
Dane Vandeputte
Posts: 14
Joined: 2012-07-01T18:26:53-07:00
Authentication code: 13
Location: Illinois, USA

Re: best downsampling method for DSLR photographs

Post by Dane Vandeputte »

NicolasRobidoux wrote:Dane: I think that I assumed there was symmetry where there is not, and indeed the full size and reduced images are always most similar in linear light in this situation.
Thank you!
You're very welcome!
(I really like how scrolling within my browser window makes the Dalai Lama jump up and down in the strobe light.)
Same here. :D
Digital image processing and photography enthusiast :)
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: best downsampling method for DSLR photographs

Post by anthony »

[quote="Dane Vandeputte"If you were to stand far enough away from your screen, I believe the unscaled image would still very likely appear as gray.[/quote]

If the image is sRGB and your monitor is correctly calibrated. YES the image will be a perfect gray when you stand back.

However few monitors are perfectly calibrated (mine isn't). And even then LCD screens have a variable intensity by angle. That is if you move to look at the image from above/below or to one side, the intensity values change in a non-linear way. The result is imperfect grays.

For example... I find that some almost but not quite blacks, which is indistinguishable to black when viewed straight on, are much brighter and highly visible when viewed from a high angle.

Look at this 'near' black image from IM Examples, Morphology Distance Example, from various angles on an LCD monitor, and you will see what I mean.
http://www.imagemagick.org/Usage/morphology/#distance
Image
At a high angle, look down at my display I can see the distance gradient 'ghost', but I can not see it from straight on or from a high angle to either side. Different LCD makes - different results.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
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 »

Henry and Luiz and whoever else feels like testing and posting opinions:
Could you please let me know what you think of EWA Lanczos2Sharpest, Lanczos3Sharpest and Lanczos4Sharpest as downsampling schemes, ideally through linear light?
With a very recent version of ImageMagick 7, the linear light versions of these schemes are

Code: Select all

magick INPUT.IMG -colorspace RGB \
-filter Lanczos2 -define filter:blur=0.88826421508540347 \
-distort Resize 840x840 \
-colorspace sRGB EWALanczos2Sharpest.IMG
magick INPUT.IMG -colorspace RGB \
-filter Lanczos -define filter:blur=0.88549061701764 \
-distort Resize 840x840 \
-colorspace sRGB EWALanczos3Sharpest.IMG
magick INPUT.IMG -colorspace RGB \
-filter Lanczos -define filter:lobes=4 -define filter:blur=0.88451002338585141 \
-distort Resize 840x840 \
-colorspace sRGB EWALanczos4Sharpest.IMG
under the assumption that INPUT.IMG is an sRGB 8 or 16-bit image.
With a recent enough version of ImageMagick 6, just replace

Code: Select all

magick
by

Code: Select all

convert
. If you must use an older version of ImageMagick 6 (before the -colorspace "swap"), let me know, and I'll figure out what works. (Using

Code: Select all

-gamma
is close enough to correct linear light conversion to be a "go". So is the use of good quality ICC profiles, or pre-converting to linear light 16-bit or HDRI images on disk before resampling.)

I know I kinda asked about this question already, but Adam Turcotte's near final thesis results suggest that in terms of numerical accuracy (which is not the same as visual pleasantness), for subcritical images (without too much content near the Nyquist limit, that is, slightly on the blurry side), these schemes are quite good at enlarging. To my eye, if you want sharpness, they are also quite good at downsampling. But I'd like second (and third, and fourth...) opinions. And I'm most interested in downsampling quality right now. (But of course I'm curious about enlarging too.)

If you find the use of linear light a hassle (or you just don't like to use it), I'm fine with feedback with this use too. (Just let me know that you did not go through linear light.)

Compare with whatever you like.

(Yes, I know these schemes are biased toward sharpening at the expense of moire. I want to get a sense of whether they are too biased.)
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 »

Surprise! When downsampling at least, RobidouxSharp gives results very very close to Lanczos2Sharpest.
Add it to the list.
Post Reply