User:Tigran Asatryan





Lanczos resampling is an interpolation method used to compute new values for sampled data. It is often used in multivariate interpolation, for example for image scaling (to resize digital images), but can be used for any other digital signal. The Lanczos kernel indicates which samples in the original data, and in what proportion, make up each sample of the final data.

The filter is named after Cornelius Lanczos, because he showed how to use Fourier series and Chebyshev polynomials for various problems where they had not been used before.

Application
The Lanczos filter is a windowed form of the sinc filter (a theoretically optimal "brick-wall" low-pass filter). The sinc function is infinite in extent, and thus not directly usable in practice. Instead, one uses approximations, called windowed forms of the filter, as discussed in window functions: filter design, and the Lanczos filter is one such windowing. The windows vanish outside of a range, and using larger ranges allows one to improve accuracy in exchange for more computation.

Some have compared the Lanczos filter favorably with simpler filters or other windowings of sinc, finding it the "best compromise" among filters considered.

Definition




The Lanczos filter impulse response is the normalized sinc function, $sinc(x)$, windowed by the Lanczos window. The Lanczos window is the central lobe of a horizontally-stretched sinc, $sinc(x/a)$ for $&minus;a ≤ x ≤ a$. Due to its form, the Lanczos window is also called the sinc window.

Thus the Lanczos filter, on its interval, is a product of two sinc functions. The resulting function is then used as a convolution kernel to resample the input field. In one dimension, its formula is given by:


 * $$ L(x) = \begin{cases} \operatorname{sinc}(x)\, \operatorname{sinc}(x/a) & -a < x < a\\ 0 & \text{otherwise} \end{cases} $$

with $a$ a positive integer, typically 2 or 3, controlling the size of the kernel. The parameter $a$ corresponds to the number of lobes of sinc, as the normalized sinc has zeros at integers; thus $a &#61; 1$ corresponds to just the (positive) central lobe, while $a &#61; 2$ has the central lobe and the second lobe on each side, which are negative.

For any positive value of $a$, the Lanczos window and Lanczos filter are continuous and differentiable even at the ends where they to go zero. In the case of positive integer values of $a$, both sinc functions go to zero at the edge, so the edge of the Lanczos filter is zero to second order, which means its derivative is also continuous, and it is differentiable to second order. Thus integer values yield a smoother cutoff, with no corner, which is why integers are generally used.

In the above, we can expand the sinc terms (for nonzero $x$ in the specified range):


 * $$\operatorname{sinc}(x)\, \operatorname{sinc}(x/a) = \frac{a \sin(\pi x) \sin(\pi x/a)}{\pi^2 x^2}.$$

Lanczos filter's kernel in two dimensions is simply the product of two one-dimensional kernels:


 * $$L(x, y) = L(x) \cdot L(y).$$

Interpolation formulas
Given a one-dimensional function I(x) defined at integer points, an interpolated value at an arbitrary point x0 is given by a convolution with the Lanczos kernel:
 * $$\hat I(x_0) = \sum_{n=\lfloor x_0 \rfloor - a + 1}^{\lfloor x_0 \rfloor + a} L(x_0 - n) I(n),$$

where a is the size of the filter. The bounds of this sum are such that the kernel is zero outside of them.

Given a two-dimension function I(x, y) defined at integer points (e.g. intensities of pixels in a digital image), the corresponding interpolation formula is:
 * $$\hat I(x_0, y_0) =

\sum_{i=\lfloor x_0 \rfloor - a + 1}^{\lfloor x_0 \rfloor + a}    \sum_{j=\lfloor y_0 \rfloor - a + 1}^{\lfloor y_0 \rfloor + a}     I(i, j) L(x_0 - i) L(y_0 - j).$$

Evaluation


The Lanczos filter has been compared with other filters, particularly other windowing of the sinc filter. Some have found the Lanczos (with a = 2) the "best compromise in terms of reduction of aliasing, sharpness, and minimal ringing", compared with truncated sinc and the Barlett, cosine, and Hann windowed sinc, for decimation and interpolation of 2-dimensional image data.

It has also been recommended by Jim Blinn for graphics purposes, with a = 3, saying that it "keeps low frequencies and rejects high frequencies better than any (achievable) filter we've seen so far;" Blinn characterizes himself and others who prefer such filters as "negative lobists" for their preference for such filters more optimized for frequency response than for ringing.

It is a popular filter for "upscaling" videos in various media utilities, such as AviSynth and FFmpeg.

Limitations
Because the kernel assumes negative values for a > 1, output values can be negative even with non-negative input. Negative values are out of bounds for image signals and cause clipping artifacts. Negative lobes also induce ringing artifacts. In some applications, the clipping artifacts can be overcome by transforming the data to a logarithmic domain prior to filtering. In this case the low pass filter will compute a geometric mean, rather than an arithmetic mean.

However, both undershoot and ringing are reduced compared to the (non-windowed) sinc filter, due to the windowing; the ringing is particularly small, as the positive side lobe size demonstrates, especially for a = 2.

In visual processing
A common misconception is that the sinc filter should be the best possible image filter, because of its ideal frequency response. This is only true for bandlimited signals which were sampled after an antialiasing filter, which is not typically the case for images. The human eye does not detect frequency directly (unlike the ear). However, vision utilizes specialized receptor patterns that detect things like localization, edge contrast and contour. The special role of edge contrast in vision is why the negative lobe of the Lanczos filter helps increase perceived sharpness even though the halo it creates is an artifact; this is form of edge enhancement.

As spatial localization and frequency localization are inversely related, visual filters require a trade-off. Good frequency filtering limits aliasing; good localization provides strong edges.