"Sigmoidal" minimization of resampling filter haloing & blur

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: "Sigmoidal" minimization of resampling filter haloing &

Post by NicolasRobidoux »

A response to Joerg Beutel in a related LinkedIn forum:
One way to make sense of this is to think about what sharpening, and actually applying any convolution with negative coefficients and sum of coefficients equal to 1, does near gamut limits, when applied to values spanningn the gamut. Even though it is interpolatory, resampling with Lanczos-like filters has a strong sharpening component "between pixels" for some combinations of values, because of the negative lobes. Same with Catmull-Rom, for example.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: "Sigmoidal" minimization of resampling filter haloing &

Post by NicolasRobidoux »

EWA LanczosSharp (and cousins) with 3, 4, and 8 lobes is now in the GPU assisted closed source video renderer madVR under the name "Jinc". (Not programmed with any involvement of yours truly. Hurray!)
So is a form of sigmoidization that robustly handles (hopefully) BTB (Blacker-than-Black) and WTW (Whiter-Than-White).
http://forum.doom9.org/showthread.php?p ... ost1595241
At some point, I may fix ImageMagick so that +sigmoidal works with over and undershoots (in HDRI).
One of the solutions that came out of discussions with Mathias, the dev of madVR would be simple to implement in ImageMagick, would not change the current behavior when there are no overshoots, and would appear to be pretty harmless.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: "Sigmoidal" minimization of resampling filter haloing &

Post by NicolasRobidoux »

I know what I'll try next:

Symmetrized Lab: Enlarge through Lab, and average with the result of

negate -> Lab -> enlarge -> sRGB -> negate

(Or maybe symmetrize sRGB. Or maybe negate inside Lab.)

This should take care of the "thinning of light features".
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: "Sigmoidal" minimization of resampling filter haloing &

Post by NicolasRobidoux »

I'm not really sure, but I think that some of the other built-in color space transformations are not "reversible enough" for sigmoidization.
Maybe this statement is defamation. Or maybe sigmoidization is not good enough for other color spaces.
I'm just stating that I'll be paying close attention to what happens with values out of the nominal gamuts when I have time to dig into things.
For example, thoughtless sigmoidization through XYZ seems to be a disaster.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: "Sigmoidal" minimization of resampling filter haloing &

Post by NicolasRobidoux »

I had been wondering for quite a long time why exactly I liked sigmoidization values between 6 and 7 (the 7.5 value recommended in "The Recommendations" is a bit on the showy side, and I was planning to reduce it). A bit more for some filters, and even more for blurry images.
They looked good. But it seemed like there should be a reason.
I was not totally satisfied with the "overshoot test" values (that I called "safer" and "less safe") because they only work with methods that have at least 3 lobes.
So ???
-----
Tonight, I think I may have found another possible explanation.
Recall that sigmoidization "fixes" values near gamut extremes.
So, put a white dot on a black background.
Enlarge it "a lot".
Now, the average color of the result should be, if "total light" is preserved, the white value (65525 in 16-bit) divided by the number of pixels of the enlargement.
Is it?
Let's see: 65525/49 = 1337 (when rounded)

Code: Select all

convert xc: -bordercolor black -border 3 -filter Point -resize 12800% dotresize.ppm
convert dotresize.ppm -scale 1x1\! txt:-
# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: ( 1337, 1337, 1337)  #053905390539  srgb(2.04083%,2.04083%,2.04083%)
So far so good.
This was with nearest neighbour, but the same result is obtained with -filter Triangle, Quadratic and Spline. Note that none of these filters have negative lobes. It does not matter if I use -resize or -distort Resize.
I had already noted that EWA Quadratic, for example, looks very good when enlarging in linear light (but have not gotten around to add this observation to "The Recommendations" yet).
But not with Mitchell. It gives 1434.
What's happening is that filtering should give 1337, but because the negative ripples are clipped, and there is no light overshoot, the mass of the impulse data is pushed up toward white.
Lanczos gives 1897.
EWA Robidoux gives 1523.

Code: Select all

convert xc: -bordercolor black -border 3 +sigmoidal-contrast 3.4 -filter Mitchell -resize 12800% -sigmoidal-contrast 3.4 dotresize.ppm
shows that the mass is correct with sigmoidal-contrast 3.4 with Mitchell (which is not one of the filters I initially considered) and

Code: Select all

convert xc: -bordercolor black -border 3 +sigmoidal-contrast 6.5 -distort Resize 12800% -sigmoidal-contrast 6.5 dotresize.ppm
shows that contrast 6.5 is just about perfect with EWA Robidoux.
And, having scrutinized results quite a bit, this is about right to my eyes as well.
(With tensor Lanczos you need to push the sigmoidization real high to get the right mass.)
Last edited by NicolasRobidoux on 2012-11-06T06:39:01-07:00, edited 4 times in total.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: "Sigmoidal" minimization of resampling filter haloing &

Post by NicolasRobidoux »

There are all sorts of nonlinear caveats to what I just wrote, but I think that there is at least a white pixel of truth to it.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: "Sigmoidal" minimization of resampling filter haloing &

Post by NicolasRobidoux »

I also suspect that when the feature is black on white (instead of white on black), sRGB processing actually gives a better mass (must be computed carefully). It's because the small nonnegative ripples will correspond to near black, so they don't push things up so much.
But the opposite goes when it's white on black.
Last edited by NicolasRobidoux on 2012-11-06T06:36: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: "Sigmoidal" minimization of resampling filter haloing &

Post by NicolasRobidoux »

Still not sure, but I think that the right amount of contrast for methods that have more than two lobes (like Lanczos 3) is to fix things so that the first, central, lobe of the impulse has the right mass.

For Robidoux and Mitchell and Lanczos2 (tensor or EWA) this makes, of course, no difference.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: "Sigmoidal" minimization of resampling filter haloing &

Post by NicolasRobidoux »

I also think that sigmoidization, like sharpening, generally works well with methods that have reasonable antialiasing. And, generally, this means that it should work better with EWA (-distort Resize) methods than tensor (-resize) methods.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: "Sigmoidal" minimization of resampling filter haloing &

Post by NicolasRobidoux »

To a good amount of surprise on my part, Bart van der Wolf, well known for scrutinizing image resizing results (and an early advocate of the use of ImageMagick in the digital photographer community), likes the results of enlarging with the Robidoux EWA filter with what I now consider a very high value of the contrast, namely 12.09375: http://www.luminous-landscape.com/forum ... #msg571631.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: "Sigmoidal" minimization of resampling filter haloing &

Post by NicolasRobidoux »

This being said, high contrast works well when the image is "sub-critical", meaning that the content stays clear of Nyquist.
And I have the impression that what comes out of top of the line high megapixel DSLRs fits this description.
henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: "Sigmoidal" minimization of resampling filter haloing &

Post by henrywho »

NicolasRobidoux wrote:This being said, high contrast works well when the image is "sub-critical", meaning that the content stays clear of Nyquist.
And I have the impression that what comes out of top of the line high megapixel DSLRs fits this description.
What about Sigma DP1/DP2 Merrill? No bayer pattern. Breathtaking quality at ISO100 and 200.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: "Sigmoidal" minimization of resampling filter haloing &

Post by NicolasRobidoux »

Henry: You know a lot more than me about this.
But I think that we are at the point where the sensors are more "accurate" than the lenses, which means that at the pixel level, there is lens blur -> subcritical image.
Or is the camera software able to compensate for that?
henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: "Sigmoidal" minimization of resampling filter haloing &

Post by henrywho »

NicolasRobidoux wrote:But I think that we are at the point where the sensors are more "accurate" than the lenses, which means that at the pixel level, there is lens blur -> subcritical image.
It's hard to judge because lenses have varied quality (http://www.lenstip.com/). We dunno whether we are having the sharpest lens, not to say the camera's focus accuracy. Though, by laws of physics, bigger sensors like full-frame and APS-C have more stringent requirements.
NicolasRobidoux wrote:Or is the camera software able to compensate for that?
Lytro (http://www.lytro.com/) has a light field camera (consumer product). It records 11M pixels in a 3D manner, and you can choose the focus point afterwards. Pretty impressive.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: "Sigmoidal" minimization of resampling filter haloing &

Post by NicolasRobidoux »

I have found a new criterion for choosing the contrast value: Enlarge an impulse (one single white pixel on a black background; the same result is obtained with a black pixel on a white background) "infinitely", and ensure that the "mass" is perfectly preserved, that is, make sure that no light has been added or subtracted. When no clipping occurs, most IM resize and EWA filters have this property (which makes more sense in linear light), because of the way they are normalized so that the sum of all weights at every point is exactly 1. With clipping, this property generally goes out the window.
Doing a quick and dirty estimation of what this gives with the Robidoux EWA filter, a contrast value of 6.4797 is obtained.
Perserving the "mass" of a grey impulse on a black (or white) background leads to a value that's just above 6.5987.
I must say that I find reassuring that these values are close to each other.
Amazingly, these values match the early "safe" value determined with the eyeball metric, and used from very early on in Anthony's examples, namely 6.5!
-----
I'll update "Nicolas' Recommendations" when I have a minute.
Post Reply