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.
henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: future of image enlargement?

Post by henrywho » 2012-07-26T18:46:16-07:00

Hey, it's not fair. I am an amateur using defaults and you are THE expert using tuned parameters. :lol:

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 » 2012-07-26T18:53:48-07:00

henrywho wrote:Hey, it's not fair. I am an amateur using defaults and you are THE expert using tuned parameters...
for a new family of methods that's 2 weeks old. And you're standing on the shoulders of a giant, the creator of NNEDI3 (known as "tritical"). I'm standing in the body of a dwarf (known as Nicolas Robidoux).
-----
I am trying to figure out what the "defaults" should be.
And, in doing that, you and Fred and Anthony and Luiz (and Cristy behind the scenes, as well as my grad student Adam) are hugely helpful.
I'm pretty sure now that the "best" deblur for Jinc-windowed Jinc to get sharpness without overwhelming artifacts is somewhere between .88 and .99, and most likely between .92 and .97. And I'm pretty sure that the best windowing for Jinc is Jinc itself. But I'm still hunting. When I have a minute, I need to sit down and program, because there is an objective function just waiting to be poked. (The one I used to create the LanczosSharpest and RobidouxSharp methods, except applied to all possible relative positions, not only the original pixel locations.)
And the best sigmoidal contrast is still a work in progress. Something between 6.5 and much below 10,000 ;)
Last edited by NicolasRobidoux on 2012-07-28T13:50:49-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 » 2012-07-27T05:46:45-07:00

One nice thing about sigmoidization is that it allows using a lot of lobes without the usual tax. I'm not recommending using this many, but the following 8-lobe EWA makes this point:

Code: Select all

magick input_small.png -set colorspace sRGB -colorspace RGB +sigmoidal-contrast 1000,50% -filter lanczos -define filter:lobes=8 -define filter:blur=.970238549334149 -distort resize 400% -sigmoidal-contrast 1000,50% -colorspace sRGB LanczosRadius8OnethousandFiftyLinear.png
Image
The halos are there, but they are as overpowering as they would be in linear light.
Conclusion: With sigmoidization, using more lobes than 3 may be worthwhile.
P.S. It is visually extremely difficult to see the difference between the above EWA Lanczos Radius 8 and orthogonal Lanczos 8.
Last edited by NicolasRobidoux on 2012-07-27T06:20:11-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: future of image enlargement?

Post by NicolasRobidoux » 2012-07-27T06:00:42-07:00

Warning: I may be pushing it with contrast=1000. I've not noticed any ill effect yet, but this gives a rather radical "sigmoidal colourspace".

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 » 2012-07-27T09:03:47-07:00

Again, I have a good amount of parameter space exploration (and probably numerical optimization) ahead of me, but EWA LanczosRadius5 seems to work well with sigmoidization:

Code: Select all

magick input_small.png -set colorspace sRGB -colorspace RGB +sigmoidal-contrast 1000,50% -filter lanczos -define filter:lobes=5 -define filter:blur=.9536953485948749 -distort resize 400% -sigmoidal-contrast 1000,50% -colorspace sRGB LanczosRadius5OnethousandFiftyLinear.png
Image
Radius 4 is not very different, but I find Radius 5 to be slightly less jaggy without being more haloy.
Haloing is a smidgeon over what I find tolerable, however, in both of them.
P.S.The above, made with contrast=1000, is only different, in max norm, by 1 (in 8-bit) from the contrast=15 result. (Contrast=14.5 is different by 2.)
Last edited by NicolasRobidoux on 2012-07-28T19:05:15-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: future of image enlargement?

Post by NicolasRobidoux » 2012-07-27T09:20:09-07:00

So, sigmoidalization is prodding me to venture where I had never gone before: "lots'o lobes" land.

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 » 2012-07-27T10:12:15-07:00

Argh! With text, contrast=1000 makes "art". Sticking to values under 50 from now on?
P.S. Actually, for an "all around safe value", probably stick to 5 to 8.5. This may depend on the exact filter used. 6.5ish is for Radius5. (Funnily enough, 6.5 is the value chosen by Anthony for his http://www.imagemagick.org/Usage/resize ... _sigmoidal.)
P.S.2 The above P.S. is wrong. See below.
Here is the last one, redone with contrast=6.5:

Code: Select all

magick input_small.png -set colorspace sRGB -colorspace RGB +sigmoidal-contrast 6.5,50% -filter lanczos -define filter:lobes=5 -define filter:blur=.9536953485948749 -distort resize 400% -sigmoidal-contrast 6.5,50% -colorspace sRGB LanczosRadius5SixpfiveFiftyLinear.png
Image
Last edited by NicolasRobidoux on 2012-07-28T20:33:16-07:00, edited 3 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 » 2012-07-27T17:19:38-07:00

As it turns out, contrast=6.5 is probably on the conservative side. But since it's the "safe best" I have right now, here is the eye chart that started it all:

Code: Select all

magick input_small.png -set colorspace sRGB -colorspace RGB +sigmoidal-contrast 6.5,50% -filter lanczos -define filter:lobes=5 -define filter:blur=.9536953485948749 -distort resize 400% -sigmoidal-contrast 6.5,50% -colorspace sRGB LanczosRadius5SixpfiveFiftyLinear.png
Image
Definitely better than enlarging with straight sRGB: The "ripples" away from the letters are gone.
Last edited by NicolasRobidoux on 2012-07-28T09:13:34-07:00, edited 3 times in total.

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

Re: future of image enlargement?

Post by fmw42 » 2012-07-27T18:44:57-07:00

Just for curiosity I used lagrange (in IM 6.7.8.6 Q16 HDRI) and got the following results, which are sharper, but show more artifacts (as expected).

1) support=2 (order=3)

Code: Select all

imh convert eyechart.png \
-set colorspace sRGB -colorspace RGB +sigmoidal-contrast 6.5,50% \
-define filter:support=2 -filter lagrange -distort resize 400% \
-sigmoidal-contrast 6.5,50% -colorspace sRGB \
eyechart_lagrange_o3_400_sigm_6p5x50.png
Image

Code: Select all

imh convert chip.png \
-set colorspace sRGB -colorspace RGB +sigmoidal-contrast 6.5,50% \
-define filter:support=2 -filter lagrange -distort resize 400% \
-sigmoidal-contrast 6.5,50% -colorspace sRGB \
chip_lagrange_o3_400_sigm_6p5x50.png
Image


2) support=2.5 (order=4)

Code: Select all

imh convert eyechart.png \
-set colorspace sRGB -colorspace RGB +sigmoidal-contrast 6.5,50% \
-define filter:support=2.5 -filter lagrange -distort resize 400% \
-sigmoidal-contrast 6.5,50% -colorspace sRGB \
eyechart_lagrange_o4_400_sigm_6p5x50.png
Image

Code: Select all

imh convert chip.png \
-set colorspace sRGB -colorspace RGB +sigmoidal-contrast 6.5,50% \
-define filter:support=2.5 -filter lagrange -distort resize 400% \
-sigmoidal-contrast 6.5,50% -colorspace sRGB \
chip_lagrange_o4_400_sigm_6p5x50.png
Image


Attempts to use sigmoidal_contrast 12,50% showed color distortions in the maxim chip image (though not in the eyechart image, since it was nearly binary and as expected seems to increase the binarization)

Order 4 is a bit too excessive in artifacts. I think I like the compromise of Nicolas's results better, but the order=3 lagrangian is marginally sharper if one can live with the increased artifacts.

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 » 2012-07-28T05:28:11-07:00

Thank you Fred. I woke up thinking "I've got to put up Lagrange examples as Fred suggested."
-----
It appears that sigmoidization requires a very good low pass filter to work well, because if the upsampling filter's artifacts "separate colours", sigmoidization will make it worse. Good low pass filtering does not produce sudden "spikes" or what not in any of the colour channels, so subpixel colour drift will not be noticeably larger than what happens normally. (At least that's the way I understand things.)
Last edited by NicolasRobidoux on 2012-07-28T09:12:28-07:00, edited 3 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 » 2012-07-28T06:36:42-07:00

Henry: Would you be kind enough to enlarge the small image shown in viewtopic.php?f=22&t=21435#p87630 by 400% using NNEDI3?

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 » 2012-07-28T09:33:34-07:00

Anthony: I think that enlarging through Lab is a very bad idea. My "guts"---which, admittedly, are often wrong---were grumblingly telling me so but I think I have proof. (Or else there is a bug in my fairly recent HDRI install, possibly having to do with clipped gamut? See my recent post in the Developers forum which briefly discusses how, when converting between esoteric colourspaces, you probably can't assume that you stay in nominal gamut if you use the usual formulas.) Here is the result of enlarging the usual chip image:

Code: Select all

magick input_small.png -colorspace LAB -resize 400% -colorspace sRGB LABresize.png
Image
If what's wrong does not jump at you, download the image and zoom in, or look at the image from a different angle (stand up and look down, or look at the screen sideways): The blackish areas are turned into posterized purple. I can't be sure of course, but I think this is the result of the interaction of the negative lobe of the default -resize filter with the "linear perceptuality".
I did not have to hunt for a bad example: This is the very first image I try with your LAB trick.
(Note: The rose image is a great test image, but it is starting to look like it's not the best at revealing not totally obvious resize artifacts. I've been thinking that for a while. But this is my final proof. Likewise, pushing the sigmoidal contrast to 1000 with impunity with Lanczos filters is something allowed by the "chip" image but which gives dreadful results with the eye chart image.)
-----
Now, what this says is that one must try a new method with a lot of examples before declaring it "great". This applies, especially, to my "sigmoidization" idea. The jury is definitely still out.
P.S. I just svn upped and recompiled with HDRI to make sure my result was up to date. Oddly enough, there is some non-visually obvious difference between the "new" Lab enlargement and the one I show here. But the purple is still there.

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 » 2012-07-28T16:16:45-07:00

I've almost certainly been playing way too safe with the thigh quality low pass filters like LanczosRadius5, or orthogonal Lanczos5. Contrast=20 is almost certainly too much. But 12, most probably not. And 6.5 is almost certainly not enough.
P.S. I'm now pretty sure that an excellent all around setting can be found for any filter. It's just that the best setting depends on the filter. An upper bound on the contrast can be found by enlarging text. (Not a downsample of text or digital photograph of text; actual text typeset, say, in GIMP.)

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

Re: future of image enlargement?

Post by fmw42 » 2012-07-28T21:13:33-07:00

I tried adding a bit of unsharp masking and it does not seem to me to introduce much artifacts and makes the output sharper.

imh convert chip.png -set colorspace sRGB -colorspace RGB \
+sigmoidal-contrast 6.5,50% \
-filter lanczos -define filter:lobes=5 -define filter:blur=.9536953485948749 -distort resize 400% \
-sigmoidal-contrast 6.5,50% \
-unsharp 0x2 \
-colorspace sRGB LanczosRadius5_s6p5_u0x2.png

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 » 2012-07-28T21:53:15-07:00

fmw42 wrote:I tried adding a bit of unsharp masking...
This is a good idea for a final step (and I had not gotten there yet). Thank you Fred.
Note: At this point, I'm not sure that EWA is better than orthogonal (in HDRI) if one wants sharpness, and also not sure that 5 lobes is better than 4 (or 3). Pretty sure that 5 lobes is better than 6, 7 or 8. Also I'm pretty sure that contrast=15 or so is better than 6.5. I don't think such high contrast (14.5 or 15) leaves much "space" for further sharpening, but I may be wrong.
P.S. I think in the balance of things, good ol' orthogonal Lanczos 3 wins over Lanczos 4 or 5.
P.S. My earlier hesitations about contrast=15 had to do with artifacts already present in one of the test images that I thought where caused by sigmoidization after enlargement.
Last edited by NicolasRobidoux on 2012-07-28T22:08:21-07:00, edited 2 times in total.

Post Reply