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

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?".
User avatar
anthony
Posts: 8884
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post by anthony »

I do not recommend XYZ colorspace for sigmoidal resize. It is linear, but not centered so a 50% color is 50% data value.
It is for color referencing.

Now linear light is also linear data. But is that really the right way to proceed?

Remember LAB image is linear perceptually!

As such perhaps blending in a linear-perceptual colorspace may not really such a bad thing after all.

Remember sRGB is only perceptually-linear in intensity. It is not perceptually-linear in color, and as such it also may not nessarilly be the best.

Now that LAB is fixed, I am starting to see it as a much better colorspace for resample filters and composite blending.

I looked at YUV (thinking it was LUV colorspace) but it is really a TV colorspace that has the exact same clipping problems that
RGB and XYZ has.


I would like to try the related CIE LUV and its cylindrical version, CIE LHC (or better still HCL to better match HSL used for modulate) implemented as colorspaces. Like the A,B channels in LAB the U,V channels are also signed numbers and thus needs a bias.
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: Don't use linear light when enlarging with Lanczos et al

Post by NicolasRobidoux »

Anthony:
There are some good and interesting ideas and points of reflexion in some of your recent postings in "my" threads.
Still thinking and processing.
What I think may be useful is something which I'm not sure exists (but maybe does): A space derived from linear RGB with sRGB primaries but which separates luminance from chrominance, ideally without over and undershoots possible in the conversion. This last thing---no over/under in the colourspace conversion---may be impossible. The reason is that I vaguely remember a theorem that says that a matrix with non-negative coefficients can only have an inverse of the same type if it is a permutation times a diagonal matrix. Will need to think. Note, for example, that the transformation matrix in one of the two directions between linear RGB and XYZ has negative coefficients, and I think you can't have both have non-negative coefficients unless you do nothing).
W.r.t. sigmoidal, I'm going to put a comment in the sigmoidal thread viewtopic.php?f=22&t=21415.
(BTW, this is why the ImageMagick forums are such a bloody godsend: Ideas move really fast here.)

User avatar
anthony
Posts: 8884
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post by anthony »

Sorry for late response - my very busy at this time.

I believe a HSL conversion that fixes intensity issues will do this. This is looked at in a number of places. The type of colorspace you talk about is but one step on this special conversion.


NOTE: even with that conversion many aspects of the non-linear response of our eyes remain. That is what LAB and LUV was supposed to fix.
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: Don't use linear light when enlarging with Lanczos et al

Post by NicolasRobidoux »

Anthony:
(No worries.)
Note: Now that I have tried sigmoidization with XYZ, and that I realize that the scaled sigmoidal has "mild" range restrictions in the "forward" (+sigmoidal-contrast) direction, and no restrictions in the "backward" (-sigmoidal-contrast) direction, I am not so concerned about negative coefficients in the colourspace transformation, esp. if they happen in the "backward" direction.
-----
I'll have another look at "alternate colourspaces". Thank you.

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

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

Post by NicolasRobidoux »

A head to head comparison: viewtopic.php?f=1&t=21703&p=89500#p89498.

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

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

Post by NicolasRobidoux »

Fine print: Enlarging through linear light is a good idea when the filter does NOT have negative lobes (for example, EWA Quadratic).

Piotr Grochowski
Posts: 8
Joined: 2019-08-27T21:27:33-07:00
Authentication code: 1152

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

Post by Piotr Grochowski »

This seems to be some sort of a paradox. On one hand, using anything but linear RGB (or some obscure transform of it that gives equivalent results, I don't know if XYZ is one) is mathematically incorrect and distorts the general brightness/color of the picture just like wrong colorspace downscaling does. On the other hand, ringing artifacts downwards are more visible.

http://entropymine.com/imageworsener/gamma/ also discusses enlarging with incorrect colorspace.

For various image editors, I believe that correct gamma should always be the default for both downscaling and upscaling, but at the same time offer users the option to directly use the sRGB values, for example if users had to manipulate (interpolate or blend) raw data that just so happened to be in an sRGB image.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

Piotr Grochowski wrote:... mathematically incorrect ...
Resizing a photograph, whether up or down, should give the same result that another camera with the required number of pixels would give.

All resizing algorithms are guesses -- they guess what this other camera would show. There is no perfect algorithm, and no mathematically "correct" method for resizing. A digital photo is a sampled version of a scene, and resizing amounts to re-sampling that photo at a different spatial frequency. In particular, any algorithm will result in one or more artifacts: blocking, blurring, ringing or aliasing. And then we have more subjective factors: colour fidelity, tonal fidelity, sharpness and acutance (which is caused by "good" ringing). Any algorithm is a trade-off between these factors.

If your interest is in resizing ordinary photos, then beware of websites like the linked one that do not use ordinary photos.
snibgo's IM pages: im.snibgo.com

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

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

Post by fmw42 »

Using linear colors was studied by Nicolas Robidoux. He suggested that in his opinion, one got less distracting artifacts with certain resampling filters. But someone who wants a sharper image and is willing to take the other artifacts, might like it better with non-linear colors or with other resampling filters. As snibgo says, it is a matter of taste and what you are willing to put up with in terms of artifacts vs blurring/sharpness

Piotr Grochowski
Posts: 8
Joined: 2019-08-27T21:27:33-07:00
Authentication code: 1152

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

Post by Piotr Grochowski »

The point is, anything else than linear RGB is technically incorrect because it introduces artifacts that don't make sense.

Image

The artifacts introduced by the misuse of sRGB values are nasty.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

Hmm, well, I would say you have shown that the artifacts introduced by rasterizing text too small, then upscaling it, are nasty.
snibgo's IM pages: im.snibgo.com

Piotr Grochowski
Posts: 8
Joined: 2019-08-27T21:27:33-07:00
Authentication code: 1152

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

Post by Piotr Grochowski »

snibgo wrote:
2019-08-31T09:51:46-07:00
Hmm, well, I would say you have shown that the artifacts introduced by rasterizing text too small, then upscaling it, are nasty.
Those artifacts are there in the "<font face='DMCA Sans Serif' style="font-size: 15px">incorrect upscaling</font>" column because it really is incorrect. The rasterization itself is performed by GDI so it's done correctly. The correct upscaling doesn't have the artifacts that the incorrect upscaling has. Examples of rasterized text being viewed upscaled are when images of rasterized text are viewed on smartphone browsers where everything is automatically zoomed in. And of course any image (except for the degenerate case of a picture with one color) would have the artifacts if upscaled incorrectly. As for the ringing with some filters, it's a matter of weighing preferences of users: accept the ringing performed by such a filter, or use another filter while preserving the correct RGB interpolation, or use something entirely different (including the popular misuse of sRGB values in interpolation).

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

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

Post by fmw42 »

What is the point of this discussion. As I mentioned before there has been a rather extensive study of the benefit of doing resizing in linear light by Nicolas Robidoux on this forum. What new information are you adding?

Locked