The magic kernel
johncostella.com
johncostella.com
1. It has no negative coefficients (hence the output will always be a valid color value.)
2. It is circular symmetric, yet separable (X and Y may be filtered independently) -- a property which simplifies the implementation considerably.
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
> 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.)
I think you mean the "B-spline" filter.
Now someone only has to find a way interpolate reflections in sunglasses, then I can die a happy man.