User:Tigran Asatryan
Lanczos resampling (Hungarian pronunciation: [ˈlaːntsoʃ]) 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,[1] because he showed how to use Fourier series and Chebyshev polynomials for various problems where they had not been used before.
Application
[edit]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.[2]
Definition
[edit]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 −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:
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 = 1 corresponds to just the (positive) central lobe, while a = 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):
Lanczos filter's kernel in two dimensions is simply the product of two one-dimensional kernels:[3]
Interpolation formulas
[edit]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:[3]
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:
Evaluation
[edit]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.[2]
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.[4]
It is a popular filter for "upscaling" videos in various media utilities, such as AviSynth[5] and FFmpeg[6].
Limitations
[edit]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.[clarification needed] 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
[edit]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.[7] The human eye does not detect frequency directly (unlike the ear).[clarification needed] 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.
See also
[edit]- Bicubic interpolation
- Bilinear interpolation
- Spline interpolation
- Nearest-neighbor interpolation
- Sinc filter
References
[edit]- ^ Claude E. Duchon (1979). "Lanczos Filtering in One and Two Dimensions". Journal of Applied Meteorology. 18 (8): 1016–1022. doi:10.1175/1520-0450(1979)018<1016:LFIOAT>2.0.CO;2.
{{cite journal}}
: Unknown parameter|month=
ignored (help) - ^ a b Ken Turkowski and Steve Gabriel (1990). "Filters for Common Resampling Tasks". In Andrew S. Glassner (ed.). Graphics Gems I. Academic Press. pp. 147–165. CiteSeerX 10.1.1.116.7898. ISBN 978-0-12-286165-9.
- ^ a b Wilhelm Burger, Mark J. Burge (2009). Principles of digital image processing: core algorithms. Springer. pp. 231–232. ISBN 978-1-84800-194-7.
- ^ Jim Blinn's corner: dirty pixels. Morgan Kaufmann. 1998. pp. 26–27. ISBN 978-1-55860-455-1.
- ^ http://avisynth.nl/index.php/Resize#LanczosResize
- ^ http://www.neowin.net/forum/topic/422992-a-how-to-guide-upconverting-video-using-ffdshow
- ^ http://www.ipol.im/pub/algo/g_linear_methods_for_image_interpolation/#index19h1
External links
[edit]- Anti-Grain Geometry examples: image_transforms.cpp shows comparisons of repeatedly resampling an image with various kernels.
- imageresampler: A public domain image resampling class in C++ with support for several windowed Lanczos filter kernels.