Image Interpolation Methods Compared - Nearest Neighbor, Bilinear, Bicubic, and Lanczos
What is Image Interpolation - Why Interpolation is Necessary
Image interpolation estimates unknown pixel values from known pixel values at non-integer coordinates. It is used in every geometric transformation requiring pixel grid rearrangement: resizing (upscaling/downscaling), rotation, distortion correction, and perspective transformation.
When interpolation is needed: For example, when enlarging a 100x100 image to 200x200, inverse-mapping each output pixel position to the input image yields non-integer coordinates (e.g., x=3.7, y=5.2). Interpolation estimates the pixel value at these fractional coordinates from surrounding known pixels.
Quality evaluation metrics:
- PSNR (Peak Signal-to-Noise Ratio): Numerical difference from original. Higher is better.
- SSIM (Structural Similarity): Perceptually-aligned structural similarity. 1.0 is perfect match.
- Edge preservation: Whether edge sharpness is maintained.
- Artifacts: Visual degradation such as jaggies, ringing, or blurring.
Classification of interpolation methods: Methods are classified by the number of reference pixels (support size). Nearest neighbor uses 1 pixel, bilinear uses 4 pixels (2x2), bicubic uses 16 pixels (4x4), and Lanczos-3 uses 36 pixels (6x6). More reference pixels improve quality but increase computational cost proportionally.
Nearest Neighbor - Fastest but Lowest Quality
Nearest neighbor is the simplest interpolation algorithm, using the pixel value at the closest integer coordinate to the target position. It has minimal computational cost and remains the optimal choice for specific use cases.
Algorithm: For output pixel (x', y'), compute the corresponding input coordinate (x, y) and use the pixel value at round(x), round(y). Only floating-point rounding is needed, requiring just one memory access per pixel.
Advantages:
- Fastest computation (approximately 3-4x faster than bilinear)
- Never generates new color values (outputs only values present in input)
- Optimal for pixel art and indexed color image enlargement
- Essential for segmentation mask and label map transformation
Disadvantages:
- Block-like jaggies (staircase edges) are prominent when enlarging
- Aliasing (moiré) occurs easily when downscaling
- Diagonal edges and curves appear staircase-shaped
- Inappropriate for photographs or gradients
Appropriate use cases: For integer-multiple enlargement (2x, 3x, 4x) of pixel art, nearest neighbor is the only correct choice that preserves pixel crispness. For semantic segmentation masks, nearest neighbor prevents generation of non-existent class values through interpolation. Specified as cv2.INTER_NEAREST in OpenCV.
Measured performance: 1920x1080 → 3840x2160 upscaling takes approximately 2ms (CPU). Under the same conditions, bilinear takes approximately 7ms and bicubic approximately 15ms.
Bilinear Interpolation - Balancing Quality and Speed
Bilinear interpolation estimates values using a weighted average of 4 surrounding pixels (2x2). It offers excellent balance between quality and computational cost, making it the most widely used interpolation method in real-time applications.
Algorithm: To find the value at coordinate (x, y), perform two linear interpolations in the x-direction, then one in the y-direction (3 linear interpolations total). Specifically, from 4 adjacent pixels f(0,0), f(1,0), f(0,1), f(1,1) and fractional parts (dx, dy):
result = f(0,0)(1-dx)(1-dy) + f(1,0)dx(1-dy) + f(0,1)(1-dx)dy + f(1,1)dx*dy
Advantages:
- Dramatically smoother results compared to nearest neighbor
- Low computational cost suitable for real-time processing
- Native GPU hardware support (texture sampling)
- Provides sufficient quality for most applications
Disadvantages:
- Edges become slightly blurred (low-pass filter effect)
- Blurring becomes noticeable with significant enlargement (4x or more)
- Less sharp compared to bicubic or Lanczos
GPU acceleration: Modern GPUs implement bilinear interpolation in hardware texture units at no additional cost. WebGL's gl.LINEAR, CUDA texture memory, and other GPU programming interfaces use bilinear as the default interpolation method.
Specified as cv2.INTER_LINEAR in OpenCV and is the default for cv2.resize(). In Pillow, use Image.BILINEAR (or Image.LINEAR).
Bicubic Interpolation - The Standard for High-Quality Resizing
Bicubic interpolation references 16 pixels (4x4) surrounding the target coordinate, weighting them with a cubic polynomial. It is Photoshop's default interpolation method and widely adopted as the standard for print-quality image processing.
Algorithm: References 4 points in each direction, weighted by a cubic convolution kernel. The kernel function W(t) is:
W(t) = (a+2)|t|³ - (a+3)|t|² + 1 (|t| ≤ 1)
W(t) = a|t|³ - 5a|t|² + 8a|t| - 4a (1 < |t| < 2)
Parameter a is typically -0.5 (Catmull-Rom spline) or -0.75 (Photoshop). a=-0.5 provides theoretically optimal approximation accuracy, while a=-0.75 produces sharper results.
Advantages:
- Noticeably sharper edge preservation than bilinear
- High fidelity reproduction of smooth gradients
- Less blurring during enlargement, maintaining natural appearance
- Sufficient precision for print-quality image processing
Disadvantages:
- Approximately 2-3x computational cost of bilinear
- Slight ringing (overshoot near edges) may occur
- Marginally lower quality compared to Lanczos
Measured comparison (1920x1080 → 3840x2160): PSNR averages 1.5-2.0dB higher than bilinear, SSIM is 0.02-0.03 points better. Processing time is approximately 15ms (CPU), about 2x bilinear. Specified as cv2.INTER_CUBIC in OpenCV and Image.BICUBIC in Pillow.
Lanczos Interpolation - Maximum Quality Resampling
Lanczos interpolation uses a theoretically near-optimal kernel derived from the sinc function windowed by a Lanczos window, achieving the highest quality resampling. Variants include Lanczos-2 (4x4), Lanczos-3 (6x6), and Lanczos-4 (8x8), with Lanczos-3 being most common.
Theoretical background: Ideal interpolation uses sinc function (sin(πx)/(πx)) convolution, but sinc has infinite support making it impractical. The Lanczos kernel truncates sinc with a Lanczos window (sinc(x/a)), providing the closest finite-support approximation to sinc.
L(x) = sinc(x) × sinc(x/a) (|x| < a)
L(x) = 0 (|x| ≥ a)
a=3 (Lanczos-3) is considered the optimal quality-cost balance, referencing 6x6=36 pixels.
Advantages:
- Sharpest edge preservation among all interpolation methods
- Excellent aliasing suppression
- Particularly high quality during downscaling (pre-filtering effect)
- Optimal for high-quality photo resizing
Disadvantages:
- Highest computational cost (approximately 2-3x bicubic)
- Ringing artifacts may be more pronounced than bicubic
- Halos may be visible near high-contrast edges
Measured performance: 1920x1080 → 3840x2160 takes approximately 35ms (CPU). PSNR is 0.3-0.8dB higher than bicubic, with differences most pronounced in downscaling. Specified as cv2.INTER_LANCZOS4 in OpenCV and Image.LANCZOS in Pillow. libvips defaults to Lanczos-3 and is optimized for batch processing.
Image resizing and interpolation books are available on Amazon
Optimal Interpolation Selection Guide by Use Case
Interpolation method selection depends on the use case, quality requirements, and performance constraints. Below are specific recommendations for each scenario.
Web image thumbnail generation: Lanczos-3 recommended. For downscaling, Lanczos's pre-filtering effect is most effective at suppressing moiré and aliasing. Processing time is not a concern for server-side pre-generation. Both ImageMagick and libvips default to Lanczos.
Real-time video processing: Bilinear recommended. GPU hardware support makes it available at no additional cost. For 4K 60fps real-time processing, bicubic and above become too expensive even on GPUs.
Pixel art and retro graphics: Nearest neighbor is the only correct answer. Other methods blur pixel boundaries, destroying the intended sharpness of pixel art. Limit to integer multiples (2x, 3x) and avoid non-integer scaling.
Medical and scientific imaging: Bicubic (a=-0.5) recommended. Lanczos ringing could potentially affect diagnosis, making the lower-ringing bicubic safer. Most DICOM viewers adopt bicubic interpolation.
High-resolution print output: Lanczos-3 recommended. For print, quality takes absolute priority over processing time. At 300dpi and above, interpolation quality differences become visible, warranting the highest quality Lanczos selection.
Machine learning preprocessing: Bilinear or bicubic. Processing speed matters for training data preprocessing where millions of images are processed, and speed differences can amount to hours. Bilinear is sufficient for inference. PyTorch's F.interpolate defaults to bilinear.