Page 1 of 2

Don't use linear light when enlarging with Lanczos et al

Posted: 2012-07-12T11:05:48-07:00
by NicolasRobidoux
The notorious http://www.4p8.com/eric.brasseur/gamma.html makes it pretty clear that if you reduce the size of an image, you should resample through linear light (not sRGB), as also discussed here http://www.imagemagick.org/Usage/resize/#problems.

There is a physical basis to wanting to downsize in linear ("physical") light, as opposed to perceptual (sRGB et al) light: You want downsampling to mimick the physical process of "averaging" photons hitting one spot of your retina, and this averaging is almost certainly better modeled by averaging linear light values.

One may be tempted to infer that enlarging (upsampling) should also be done through linear light. I certainly made this inference myself. And it is wrong.

Although I have not checked things with sufficiently many ways of enlarging through linear light (using both different conversion methods and different linear light colourspaces), I feel pretty confident that the following statement will not come back to haunt me:
(Nicolas') Conjecture
If you are enlarging (specifically, if you are not significantly downsampling) an sRGB image with a filter that has significant negative lobes (like Lanczos or Catmull-Rom), do not go through linear light, even if your set up allows you to convert between sRGB and linear light with insignificant loss (with IM, anything but an 8-bit compile if you use linear RGB with sRGB primaries; with XYZ, stick to HDRI). You are better off resampling with "straight" sRGB values.

Short version: With a sharpening filter (Lanczos, Catmull-Rom etc), don't enlarge in linear light.
(The same probably holds with Adobe RGB and some of the other "perceptual" colourspaces.)

P.S. There has to be someone who noticed this before. If you have references (web, books or articles), please communicate them to me.

P.S. The above assumes that your image is reasonably close to being a "natural image" in which sharply focused foreground objects are generally darker than their background. If your sRGB image is better described as being "reverse video", you may or may not (I don't really know) be better off enlarging in linear light (or, at least, enlarging with a "positive" version of the image). An attempt at dealing with this caveat is discussed here: viewtopic.php?f=22&t=21415.

P.S. These conclusions were made comparing a "straight" IM enlarge with one that goes through linear RGB with sRGB primaries using the IM7 -colorspace command. At some point, I'll need to make sure that they are not specific to the comparison of these two toolchains.

P.S. I forgot to thank my graduate student Adam Turcotte. The above conjecture was formulated while trying to make sense of the results that are coming out of his Masters thesis work in progress EXQUIRES (https://github.com/aturcotte/exquires).

Re: Don't use linear light when enlarging with lanczos et al

Posted: 2012-07-12T11:18:33-07:00
by NicolasRobidoux
Conjecture unchecked by experience:
Don't (blindly) sharpen in linear light.

(This one's trickier, since clearly someone who is sharpening wants "sharpening artifacts" :))

Re: Don't use linear light when enlarging with lanczos et al

Posted: 2012-07-13T19:45:21-07:00
by Dane Vandeputte
I fully agree that enlarging via linear light is not a good idea, at least not without some sort of artifact reduction. Even then, I personally haven't seen enough perceptible advantage to bother.

I think the reason behind this is that when upsampling, the interpolated values are generally not too different from the existing samples, except at discontinuities like edges (but if the discontinuities are large enough to matter, they tend to be plagued by ugly artifacts when using linear light). On the other hand, the result of a lowpass filter can generate values very different from the original samples when enough high frequencies are attenuated, thereby being much more affected by the gamma value.

Re: Don't use linear light when enlarging with lanczos et al

Posted: 2012-07-14T03:49:59-07:00
by NicolasRobidoux
Dane Vandeputte wrote:...
I think the reason behind this is that when upsampling, the interpolated values are generally not too different from the existing samples, except at discontinuities like edges (but if the discontinuities are large enough to matter, they tend to be plagued by ugly artifacts when using linear light).
...
Exactly my thinking.

Re: Don't use linear light when enlarging with Lanczos et al

Posted: 2012-07-19T11:00:23-07:00
by NicolasRobidoux
"Nicolas'" Conjecture may appear to contradict the general statement made in http://www.poynton.com/notes/colour_and ... tml#linear:
If you wish to simulate the physical world, linear-light coding is necessary.
The contradiction is only apparent:
Because producing "negative light", which can occur when using a filter with negative lobes, is definitely not physical---of course, these values are generally clamped, but the fact that things have to be clamped is also a sign that the operation is not "physical"--- and producing "whiter than white" (white "brighter" than the white point) is also of dubious "physicality", although less obviously so, when you use Lanczos 3 or Catmull Rom to resample, you have unwittingly introduced the "non-physical" into your toolchain. Which means that Charles Poynton's admonition is N/A.

Re: Don't use linear light when enlarging with Lanczos et al

Posted: 2012-07-19T19:33:42-07:00
by NicolasRobidoux
viewtopic.php?f=22&t=21435&p=87862#p87862 suggests that maybe what I should have written is
"Don't use linear RGB with sRGB primaries when enlarging with Lanczos et al".

Re: Don't use linear light when enlarging with Lanczos et al

Posted: 2012-07-19T22:16:34-07:00
by anthony
In summary. Linear colorspaces is correct. But you need to separate intensity from color handling.

Resizing using a linear LAB colorspace works But only in ImageMagick v6.7.8-2 onward as before this LAB color value storage was not quite linear!

I would say the same is true for composition as well.

The LAB storage problem was discovered when trying to blur/sharpen just an images intensity, rather than its colors.


PS: the reason this is only a problem when enlarging is when shrinking colors are merged and strong edges tend to have more colors merged so as to generally produce less of a ringing effect. It is also only really a problem on edges involving primary colors like red and blue. This is why ringing is often seen on edges involving a clear blue sky.

Re: Don't use linear light when enlarging with Lanczos et al

Posted: 2012-07-20T05:03:25-07:00
by NicolasRobidoux
Where did you guys find a definition for "linear Lab"? You realize that the "linearity" often attached to Lab refers to "perceptual linearity"? Standard Lab is not "physical light" by any means.
(I hope I'm not sticking my mouth on my foot in my scattered responses to Anthony's "Lab idea". What am I missing?)

Re: Don't use linear light when enlarging with Lanczos et al

Posted: 2012-07-20T06:46:20-07:00
by NicolasRobidoux
anthony wrote:...It is also only really a problem on edges involving primary colors like red and blue. This is why ringing is often seen on edges involving a clear blue sky.
Although I don't have time for this right now, this is why I'd be curious to compare enlarging through linear RGB with sRGB primaries with enlarging through XYZ.

Re: Don't use linear light when enlarging with Lanczos et al

Posted: 2012-07-21T06:55:54-07:00
by NicolasRobidoux
The results of a quantitative re-enlargement study performed by my Masters student Adam Turcotte (almost ready to be filed) suggest that there is caveat to the above conjecture:
(Nicolas') Conjecture (caveat)
However, if you are re-enlarging images produced by downsampling directly through sRGB (instead of going through linear light), you will get more accurate results going through linear light, even if you use a filter without negative lobes.
My guess as to why this should be the case is that if the image was downsampled without using linear light, upsampling filter artifacts are the least of your worries. Your primary goal should be to correct the "crime" committed by downsampling directly with sRGB (or at least not make things worse).
P.S. I would think that what holds for sRGB generally holds for colorspaces which relate to linear light in a similar "gamma larger than 1" way, that is, "reserve much of your gamut for darks".

Re: Don't use linear light when enlarging with Lanczos et al

Posted: 2012-07-21T21:35:03-07:00
by Dane Vandeputte
NicolasRobidoux wrote:Although I don't have time for this right now, this is why I'd be curious to compare enlarging through linear RGB with sRGB primaries with enlarging through XYZ.
Linear sRGB is related to XYZ through a simple matrix multiplication, so the results would be visually the same.

Re: Don't use linear light when enlarging with Lanczos et al

Posted: 2012-07-22T06:02:29-07:00
by NicolasRobidoux
Dane Vandeputte wrote:...
Linear sRGB is related to XYZ through a simple matrix multiplication, so the results would be visually the same.
Nonlinearity beware! I don't expect a huge difference, but I expect one.

Re: Don't use linear light when enlarging with Lanczos et al

Posted: 2012-07-22T08:44:01-07:00
by Dane Vandeputte
NicolasRobidoux wrote:
Dane Vandeputte wrote:...
Linear sRGB is related to XYZ through a simple matrix multiplication, so the results would be visually the same.
Nonlinearity beware! I don't expect a huge difference, but I expect one.
Where is the nonlinearity?

Re: Don't use linear light when enlarging with Lanczos et al

Posted: 2012-07-22T09:56:04-07:00
by NicolasRobidoux
Dane Vandeputte wrote:...
Where is the nonlinearity?
Oops! Got my conversations crossed: I meant I'm curious to try XYZ with sigmoidalization (instead of linear RGB with sRGB primaries): viewtopic.php?f=22&t=21415.
Apologies.

Re: Don't use linear light when enlarging with Lanczos et al

Posted: 2012-07-22T11:11:37-07:00
by Dane Vandeputte
NicolasRobidoux wrote:
Dane Vandeputte wrote:...
Where is the nonlinearity?
Oops! Got my conversations crossed: I meant I'm curious to try XYZ with sigmoidalization (instead of linear RGB with sRGB primaries): viewtopic.php?f=22&t=21415.
Apologies.
No problem. :)