Now live: EWA-Cubics shader!

I think we can agree that, as far as upscaling/reconstruction filters go, Catrom bicubic and Lanczos (2 lobe) windowed sinc are among the best approaches. However, if one examines the image from a distance from the screen (especially relevant to pc monitor usage), then I think we can also agree that the image becomes highly aliased/blocky. There’s a particular distance at which the perceived screen pixels reach a point of maximum sharpness or acutance. This is where we should be testing our shaders and presets to ensure that they look okay at any screen distance/size. This is why there tend to be two different CRT shader/preset approaches–sharp or smooth. The former looks good up close to the screen (where the image naturally becomes smoother) and the latter from a further distance (or smaller screen size).

The current best practice smoother approach will take one of these upscaling filters (eg, Catrom or Lanczos) and then apply a second Gaussian blur pass, or similar. The problem with this is that it will blur everything together–both the things that look good and we want to remain sharp and clear and the things we want smoothed (like harsh texture patterns or ringing artifacts). I realized that it would be better if we could have an upscaling/reconstruction filter that does both natively, thus working with the upscaler, rather than against it. The result of my search: EWA Cubics. It preserves details and smooths just where you’d want it. I’ve tested it and can confirm that the resulting image will be, paradoxically, both sharper and smoother than the aforementioned 2 pass approach. Smoothing during reconstruction/upscaling can preserve perceived sharpness better than reconstructing sharply and then blurring afterward.

With the old approach the first pass already creates a high-resolution image with its own edge structure, ringing, stair-step emphasis, and texture pattern. The Gaussian blur then operates on that already-created output image. It cannot distinguish between “bad sharpness” and “good sharpness.” It just diffuses everything: real edges, ringing, pixel texture, line contrast, and fine detail. With EWA-Cubics, the smoothing is built into the resampling itself, so the filter can blend neighbouring source pixels at the moment the new samples are being created. That tends to reduce the harsh high-frequency pixel texture without first producing a too-sharp intermediate image that then needs to be blurred back down in a post-hoc way.

EWA stands for elliptical weighted average. It’s also known as a radial, cylindrical, or circular reconstruction filter. It will sample in a uniform circular/radial manner unless the image is stretched/distorted in a non-uniform manner (thus the ellipse is the more general case).

Why is this better and why does it result in a more natural, pleasing looking image? I think it’s because the prior best practice case of using Catrom or Lanczos etc, are called separable or orthogonal filters that sample along each axis, thus they are grid-aligned and may result in an overly harsh, angular appearance, emphasizing aliasing; also they are strict interpolation filters, meaning when the output sample lands exactly on a source texel center, the original texel is reproduced exactly. So there may be no inherent pixel blending in the separable/orthogonal filter case, whereas there pretty much always is in the case of the EWA filter family (more detail on that below). Finally, because of its circular/radial sampling approach, I think it more naturally aligns with the image display done on a CRT in that such a display exhibits more of a gaussian-style blur from the phosphor glow. This EWA approach, therefore, obviates the need to do a second blur pass (which is detrimental to the image). The reduced ringing of these EWA filters also obviates the need for an anti-ringing filter (which, in any case, can cause its own issues, as HunterK knows all too well from my many edits…! :sweat_smile: ).

EWA filters tend to blend textured pixel patterns better, especially around diagonals, curves, and mixed high-frequency detail due to their radial sampling nature, not unlike Gaussian radial sampling (except with the negative lobes which allow them to function properly as reconstruction filters, unlike standard Gaussian).

Due to how they sample, EWA filters are much higher energy than their separable cousins. So Catrom and Lanczos EWA look incredibly bad as they have very strong negative lobes. Conversely, this means named filters that looked overly smooth in the separable case look much sharper and clearer in the EWA case. This is why Mitchell (Mitchell-Netravali, specifically) looks excellent in the EWA use case, despite looking very glow-y, blurry, yet still somewhat aliased, in the standard bicubic case.

Note: even though you’ll find this in the Interpolation folder, it isn’t, strictly-speaking, an interpolation filter per se given the intrinsic sampling from neighbouring pixels. That said, the Robidoux EWA filter was specifically designed to exactly preserve horizontal and vertical lines in the no-op/unscaled case; it also just happens to virtually eliminate aliasing in the max acutance viewing distance case. RobidouxSharp EWA was specifically designed to preserve images containing pure black and white pixels with the minimum of error in the “no-distort” case. Specifically, the weightings of orthogonal neighbouring pixels will exactly match the negative weightings of diagonal neighbouring pixels in a ‘no-distort’ case. It is very similar in sharpness to traditional Catrom and Lanczos, but with less ringing and with a smoother, less processed look (especially in textures). Finally, it is just a coincidence that Mitchell happens to land pretty much exactly right in between the two on the Cubic Keys line (which sum to 1 as in 1B+2C). Mitchell also produces near equivalent ‘sharp’ results for the ‘no distort’ case. So you can consider it a pseudo-interpolation filter.

cubic_survey

Side note: you might be wondering why is this called a cubic shader instead of bicubic and does that mean it’s inferior or less technically sophisticated (?). No, being radial it is still a 2d filter like bicubic and the formula is more sophisticated than the bicubic case, but it just doesn’t sample separately along x & y, so the convention is to refer to it as a cubic filter.

Dev note: I also tried EWA Jinc2 which is a Jinc windowed Jinc filter and is the EWA analogue of Lanczos being a Sinc windowed Sinc filter, but it was too blurry, despite it similarly being the most “mathematically ideal” in terms of energy preservation and being the ideal low-pass filter for the EWA case.

I firmly believe that this should be the default RA shader. Let me know what you think after trying it out!

Credit: Nicolas Robidoux and the ImageMagick team. A treasure trove of info:

https://usage.imagemagick.org/filter/#robidoux

https://usage.imagemagick.org/filter/nicolas/

2 Likes

Lanczos:

EWA RobidouxSharp:

EWA Mitchell:

EWA Robidoux:

4 Likes

EWA (2D) resizes are indeed better I need a hand with interpolation

but from what I know from doom9 and avisynth, they kinda slower (at least in case of using cpu not gpu) https://forum.doom9.org/showpost.php?p=1688446&postcount=39

Very cool image, though not sure why the halo-ing is so intense there.

The ranking for how performant an upscaler is would be like this (from faster to slower, not including basic methods):

  1. Bicubic

  2. EWA-Cubics

  3. Windowed Sinc or Jinc filters

So it’s still quite performant and not really a concern with modern devices. If you can run Lanczos, then you’ll run this even faster :slight_smile:

1 Like

maybe because it use the resizer to do x10 of the original size https://forum.doom9.org/showthread.php?p=1929832#post1929832 Edit: more tests here https://forum.doom9.org/showthread.php?p=2027057#post2027057

1 Like

Update now live featuring high precision B & C values. They are now 32 bit float precision (though original values are 64 bit) vs only being 4 decimal places in the first upload.

1 Like

It makes sense now why those first 2 images were so ring-y. They were 4 lobes each (8x8 taps). Notice how the better result in the second comparison at the bottom-right (“userdefined4resize”) only has 1 halo–that’s a 2 lobe (4x4 tap) mode which features much less ringing and is the same that mine uses (though I’m guessing he’s using Jinc EWA which is smoother/blurrier than with EWA Cubics).

Edit: also the Spline16 example there is also really good. You can see it in RA where it gives quite a nice result.

Edit2: btw that explains your concern re performance lol. 4 lobes/64 taps total is much harder to run than 2 lobes/16 taps total!

1 Like

I’ve been enjoying this shader lately as an alternative to my usual sharp pixel look (bandlimit-pixel). It manages to blend pixels nicely without too much blur. Makes gradients look really smooth. And it looks truer to the original pixel art than edge-smoothing shaders do.

2 Likes

That’s great to hear! Thanks! Yes, the shaders in the Pixel Art Scaling folder are monotonic so are missing negative lobes entirely, so they are not well-suited to the task of proper image reconstruction and will tend to either be overly blurry, blurry and aliased, or just very aliased as a result. This, by contrast, is definitely much closer to the artist’s intended look. Yes, the Edge Smoothing ones definitely do not respect the original art.

Later tonight/tomorrow there should be a new shader live that allows the user to freely adjust the blurring of this approach :slight_smile:

2 Likes

New shader now live in this vein: EWA-Custom-B-Blur.

It allows the user to freely adjust the B value while automatically and dynamically adjusting the C value to stay on the Cubic Keys line, from Catrom all the way through to Spline. This reduces from the 2 variable, 10,000 combination version of the usual approach to a single variable, linear 0-100 scale with predictable results.

1 Like

The EWA-Custom-B-Blur shader is now live. Try setting it to 0.22–I bet you’ll love it!

Yeah, that’s nice. Cleans up the blur and the contrast looks better.

Awesome :). Btw if you have the nits (monitor brightness) to spare, then I highly recommend giving my SharpSmooth shader a shot (as the second shader pass after the EWA one). It’s under “CreativeForce” in the CRT folder. It actually applies a technique that doubles the perceived resolution (while not affecting the underlying pixels), making the resulting image simultaneously significantly sharper and smoother.