
The magic kernel - wazoox
http://www.johncostella.com/magic/
======
dognotdog
When seen as a [1 3 3 1] (the 4th row of Pascal's Triangle) kernel, it is more
easily revealed as a discrete Gaussian kernel, which is for example used in
scale-space representations in image processing.

~~~
eru
The same applies to {0.05, 0.25, 0.4, 0.25, 0.05} mentioned later: it's
proportional to 1 5 8 5 1, which is two rows down from 1 3 3 1.

~~~
powera
The row is 1 4 6 4 1, but these are the closest 5-cent approximations to the
1/16th that add to 1.

~~~
eru
Thanks for the correction, and additional information.

------
rer0tsaz
Let me share my experience with chroma upsampling and smooth jpeg decoding.

At first, I optimized each channel, then upsampled the chroma channels using
replication. This works terribly as you can see in the article.

So then I changed to linear interpolation. Briefly:

    
    
        +---+---+
        a x b y c
        +---+---+
    

We know the values in a and c but not b. The distance from x to a is half a
pixel and the distance from x to c is one and a half pixel. Then linear
interpolation gives x = a + (c - a) * (1/2 - 0) / (2 - 0) = 3/4 a + 1/4 c.

This worked decently, but it still showed fringes around sharper edges. I
considered using more complicated upsampling methods like Lanczos or Mitchell,
but instead went with optimizing a full size image with constraints on the
downsampled image. By avoiding upsampling I got my optimized high resolution
image for each channel.

But there were still fringes! As it turns out, just because each channel was
optimized seperately doesn't mean that the image as a whole is optimized. So I
switched to optimizing the three YCbCr channels together, not looking at the
differences abs(x_{i+1} - x_i) but looking at the differences sqrt((Y_{i+1} -
Y_i)^2 + (Cb_{i+1} - Cb_i)^2 + (Cr_{i+1} - Cr_i)^2). This actually eliminated
the fringes.

The final result is
[https://github.com/victorvde/jpeg2png](https://github.com/victorvde/jpeg2png)

------
statusreport
Sorry guys, but no magic is involved here:
[http://cbloomrants.blogspot.com/2011/03/03-24-11-image-
filte...](http://cbloomrants.blogspot.com/2011/03/03-24-11-image-filters-and-
gradients.html)

~~~
gus_massa
I mostly agree. But

> _Costella shows that Lanczos and Bicubic create nasty grid artifacts. This
> is not true, he simply has a bug in his upsamplers._

The good and bad part of discussions about image processing is that it's easy
to compare the results. This blog post would be better with the images using
the correct implementation of the filters.

(One problem is that some times just getting the images, configuring the
programs and tiding the results is more time consuming than expected. So "just
add the images" may be a one week project.)

~~~
zokier
For reference I get the following result with my GIMPs "Cubic" scaler:

[http://i.imgur.com/3LLNzv5.png](http://i.imgur.com/3LLNzv5.png)

~~~
wazoox
Notice the long-known bug, Gimp doesn't manage gamma properly, the scaled
picture looks slightly darker.

------
pmjordan
I'll need to try this as an OpenGL (ES) shader in an app I work on regularly.
I've been meaning to replace the default bilinear filtering with something a
bit nicer-looking for ages, and this seems like it fits the bill nicely, as it
avoids the usual ringing and moiré issues. (I don't need to worry about
perspective correction as the app is 2D only)

------
wazoox
My good friend Kyle posted his C++ port here:
[https://github.com/kylegranger/ImageScaling](https://github.com/kylegranger/ImageScaling)

------
jevinskie
This brings back high school memories of performing Gaussian blurring of 2-bit
grayscale hand drawn sprites drawn on graphing paper. Yes, I got bored in
class! I did use a calculator for assistance. :) I never knew there was such a
remarkably simple kernel that provides good scaling!

~~~
twsted
The fact that you were studying Gaussian blurring in high school amazes me.
Which kind of school, if I may ask? Is a standard program?

~~~
infofarmer
The "Yes, I got bored" part suggests that it wasn't in the program and he was
studying it on his own.

------
detrino
If you prefer blurry images such as the author seems to, you can use
parameters to your cubic filter to add more blur than the (probably mitchell
or catrom) parameters that gimp is using. I'd bet most people would find the
result superior to this filter.

~~~
leni536
A good article on cubic filters:
[http://entropymine.com/imageworsener/bicubic/](http://entropymine.com/imageworsener/bicubic/)

I think you mean the "B-spline" filter.

~~~
detrino
Ya, B-spline, as the article defines it: Cubic(1, 0), is an example of a very
blurry cubic filter.

------
krakensden
What's the popular JPEG library that this is from? Why the refusal to mention
it?

~~~
Twirrim
It's libjpeg.
[http://libjpeg.sourceforge.net/](http://libjpeg.sourceforge.net/)

------
torpet
Finally all those haters who think low-pixel images cannot be zoomed in on are
proven wrong...
[https://www.youtube.com/watch?v=I_8ZH1Ggjk0](https://www.youtube.com/watch?v=I_8ZH1Ggjk0)

Now someone only has to find a way interpolate reflections in sunglasses, then
I can die a happy man.

