future of image enlargement?

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: future of image enlargement?

Post by anthony »

NicolasRobidoux wrote:I think that my worries about high contrast leading to colour drift were just that?
P.S. No, they are not: It depends on the sharpness of the input image.
It is likely that doing resize in another linear colorspace that separates intensity from the color components (such as LAB now that it is fixed to allow this) will ensure you do not get color drift along edges.

Code: Select all

convert rose: -colorspace RGB -filter Lanczos  -distort resize 600x -colorspace sRGB  rose_RGB.png
convert rose: -colorspace LAB -filter Lanczos  -distort resize 600x -colorspace sRGB   rose_LAB.png
Well a compare did not show any color drift.

BUT

The RGB version has extreme clipping of the ringing.
But the LAB version does not as the intensity difference between white and red is only 1/3 (roughly) as great as between the two colors in the red channel in RGB!

This is probably a much better overall solution that sigmoidal to prevent ring-clipping.


See IM Examples... (should be up by now)
Resizing in LAB colorspace
http://www.imagemagick.org/Usage/resize/#resize_lab
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: future of image enlargement?

Post by NicolasRobidoux »

Maybe sigmoidization should only be used on the luminance channel of a suitable colorspace?

Anthony: I should have tried Lab. Good find! Have you tried XYZ?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: future of image enlargement?

Post by anthony »

LAB was broken until just a few versions ago (storage of signed integers in unsigned integers)

XYZ has the intensity mixed with color, so will have, and does have, the same problems as linear RGB.
In fact XYZ and RGB are very close, with just sligthly different color vectors, to better and universally define all colors humans can see, rather that a practical working color space.


Just as an aside I tried something completely non-sensical... resize in HSL colorspace.
With the rose image it produces some weird psychedelic effects along the edges where colors
switch between red-green to red-yellow colors.

convert rose: -colorspace HSL -filter Lanczos -distort resize 300x -colorspace sRGB show:


I also thought about another colorspace YUV but it seems to show the same clipped effects as linear RGB!

Note enlarging in sRGB and LAB seems to produce identical images!

I am starting to wonder if internally something unexpected is being done for non-RGB colorspaces? As sRGB is a non-linear, we should see some differences between them!

Actually I would expect sRGB to show some clipping too! But it does not seem to.

The story is not quite complete!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: future of image enlargement?

Post by henrywho »

Isn't "Y" of XYZ linear but "L" of LAB nonlinear? :shock:
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: future of image enlargement?

Post by NicolasRobidoux »

I also don't understand: Lab is a perceptual color space.
Also: The "Y" of XYZ is the standard luminance channel: http://en.wikipedia.org/wiki/CIE_1931_c ... .2CY_and_Z
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: future of image enlargement?

Post by NicolasRobidoux »

anthony wrote:...
Note enlarging in sRGB and LAB seems to produce identical images!
...
If you look at the formulas for La*b* (often called Lab: there are two "Lab"s, BTY) http://en.wikipedia.org/wiki/Lab_color_ ... onversions, you will see that the "philosophy" behind Lab is quite similar to sRGBs. (XYZ is linear, like linear RGB with sRGB primaries.)
It is starting to look like you are reproducing with another colorspace the fact that if you go through a colorspace with stretched out darks like sRGB and Lab (compared to linear RGB and XYZ), the dark halos, which are generally the most offensive, are minimized.
The point of "sigmoidalization" is to equally stretch the lights and darks, restoring symmetry (within the limitations of having a fixed white point). The other "point" of sigmoidization is to set the stretching so it jives with the amount of overshoot built into the filter (I've only looked at Sinc and Jinc Lanczos 3).
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: future of image enlargement?

Post by NicolasRobidoux »

Anthony: I think that you may have a really good hunch RE: separating chroma from luminance/luma when resampling, even if you use the same filter across all channels.
I'll have to try sigmoidalization through XYZ instead of linear RGB. Although I think that the way the sigmoidal transformation is set up in IM may not be friendly to XYZ obtained from sRGB. Will need to check.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: future of image enlargement?

Post by anthony »

Okay so let me be clear. I am mistakenally assuming that LAB colorspace is linear, when it is only perceptually linear, with non-linear data.

Hmmm okay one thing I have been wanting to look at is creating a colorspace like HSL but where L is actually a tru intensity level for the associated hues. I wanted this so that hue rotations correctly preserve the intensity of the color as the hue is rotated. Wikipedia has the transformations needed for this colorspace conversion.
http://en.wikipedia.org/wiki/HSL_and_HSV


However if this colorspace also properly separates intensity from color, and we avoid that final conversion from color to hue angle, then presumably we can do resizing in that space and avoid clipping on primary and secondary colors (only on black and white which is not so bad).

Hmmm perhaps CIELCH (cylindrical LUV) or better still HCL (channel reordered to make it more compatiable to HSL) though the L channel is probably again non-linear. We should arrange to have that colorspace implemented as a alternative to HSL in -modulate, or better still make it is the IMv7 default for modulate.

Hmmm sorry I am getting off track.


LAB is not linear. but perhaps a good perceived colorspace just works better for filter and composite blending!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: future of image enlargement?

Post by fmw42 »

Perhaps this topic should be linked to or from viewtopic.php?f=1&t=20992&start=165#p88014 and the subsequent posts.
henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: future of image enlargement?

Post by henrywho »

NicolasRobidoux wrote:
henrywho wrote:...
Let me try Avisynth+NNEDI3+EEDI3 tonight.
Thank you Henry.
Pure NNEDI3
Image
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: future of image enlargement?

Post by NicolasRobidoux »

NNEDI3: Stunning. (Now you know why I wrote that I would not be surprised if something like this may be "it".)
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: future of image enlargement?

Post by NicolasRobidoux »

... and yet, sigmoidal EWA enlargement fights back. Here is a setting that seems to work pretty well:

Code: Select all

magick input_small.png -set colorspace sRGB -colorspace RGB +sigmoidal-contrast 50,50% -filter lanczossharp -distort resize 400% -sigmoidal-contrast 50,50% -colorspace sRGB lanczossharpFiftyFiftyLinear.png
Image
Look at the smaller letters and digits. Sigmoidal EWA wins there. In any case, it really pushes the limit on what one can do with a linear filter.
P.S. EWA Lanczos is as good, and barely different. There really is little reason to use LanczosSharp instead of Lanczos here.
P.S. 2 I'm doing a lot of things quickly these days, but I am finding out that (in HDRI) immense constrasts can be used in sigmoidal-constrast without any visible ill effect. (This negates some of my earlier fears.) Starting at about contrast=15, however, there is very little change in the final image when one ups the contrast. These comments are very preliminary, but seem robust.
P.S. 3 If someone had shown me these results a few year ago, stating that would come from a relative of Lanczos 3, I simply would not have believed them. They have none of the Lanczos "overdoneness" about them.
P.S. 4 Actually, with this test image and enlargement ratio, it is impossible to see the difference with orthogonal Lanczos 3 and EWA Lanczos Radius 3 at my current favorite sigmoidal contrast, namely 1000. I bet it's also impossible at contrast 15. Sigmoidization irons out the subtle differences between orthogonal and EWA filters. Same with windowing functions. EWA LanczosSharp 3 is different from the above two (smoother without major loss of key detail, although it IS slightly less sharp), but not very different. I feel like I am getting somewhere.
P.S. 5 This test image is fairly smooth. Differences may be more obvious with another one.
Last edited by NicolasRobidoux on 2012-07-27T07:39:12-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: future of image enlargement?

Post by fmw42 »

Nicolas,

Was that test image done with HDRI mode? I was shocked you had used a settting of 50 contrast? I had tried even 15 or 20 in non-hdri with horrible results. I had not thought about HDRI mode being any better. Quite amazing.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: future of image enlargement?

Post by NicolasRobidoux »

Fred:
I always use HDRI when:
1) I do fancy pants colourspace stuff (including sigmoidalization), or
2) I use -resize with a filter with negative lobes, because the overshoots are clipped between the orthogonal passes, and this creates artifacts.
Last edited by NicolasRobidoux on 2012-07-26T17:39:45-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: future of image enlargement?

Post by NicolasRobidoux »

Here is the EWA LanczosRadius3 version with contrast=1000. (I tried 10000, and get posterization. So, there is a practical limit even with HDRI. Maybe I'm overdoing it even with 1000. With this test image, it really does not make much difference past around 15.)

Code: Select all

magick input_small.png -set colorspace sRGB -colorspace RGB +sigmoidal-contrast 1000,50% -filter Lanczos -define filter:blur=.9264075766146068 -distort resize 400% -sigmoidal-contrast 1000,50% -colorspace sRGB lanczosRadius3OnethousandFiftyLinear.png
Image
A bit more jaggies, but very sharp, and the artifacts don't jump at you.
NNEDI3 looks cleaner and is better at straight lines, but EWA LanczosRadius3 renders the curved digits and letters more accurately.
Post Reply