Image downscaling
algorithm
image processing
computer graphics
digital imaging

Image downscaling algorithms compared (nearest neighbor, bilinear, bicubic)

Codemia Knowledge Hub ·

The three standard image downscaling algorithms trade speed for quality. Nearest neighbor copies the closest source pixel and is the fastest but looks pixelated. Bilinear interpolation averages the 4 nearest pixels for smoother results. Bicubic interpolation weighs a 4x4 neighborhood of 16 pixels and gives the highest quality at the highest computational cost. Pick nearest neighbor for real-time work, bilinear for quick display resizing, and bicubic when quality matters most.

Why images get downscaled

Downscaling reduces an image's dimensions while keeping as much of the original quality as possible. Common reasons:

  • Performance: smaller images need less computation to process.
  • Bandwidth: smaller images load faster over the internet.
  • Device fit: some screens need images scaled to their size.
  • Preprocessing: machine learning models often expect smaller inputs.

Nearest neighbor

Nearest neighbor is the simplest method. For each pixel in the downscaled image, it maps back to the corresponding position in the original and takes that pixel's value, with no interpolation:

xorig=round(xnew⋅WorigWnew)x_{orig} = round(x_{new} \cdot \dfrac{W_{orig}}{W_{new}})
yorig=round(ynew⋅HorigHnew)y_{orig} = round(y_{new} \cdot \dfrac{H_{orig}}{H_{new}})

Here WnewW_{new} and HnewH_{new} are the new image's dimensions, and WorigW_{orig} and HorigH_{orig} are the original's.

  • Pros: fast and easy to implement.
  • Cons: can look pixelated, especially with large reductions.

Bilinear interpolation

Bilinear interpolation computes each new pixel as a weighted average of the four surrounding source pixels, which gives smoother transitions:

p(x,y)=(1−α)⋅(1−β)⋅p(x1,y1)+α⋅(1−β)⋅p(x2,y1)+(1−α)⋅β⋅p(x1,y2)+α⋅β⋅p(x2,y2)p(x, y) = (1 - \alpha) \cdot (1 - \beta) \cdot p(x1, y1) + \alpha \cdot (1 - \beta) \cdot p(x2, y1) + (1 - \alpha) \cdot \beta \cdot p(x1, y2) + \alpha \cdot \beta \cdot p(x2, y2)

Here (α,β)(\alpha, \beta) are the fractional parts of the pixel position.

  • Pros: smoother than nearest neighbor.
  • Cons: more expensive to compute and can blur fine detail.

Bicubic interpolation

Bicubic interpolation uses the nearest 4x4 neighborhood and cubic polynomials, producing even smoother results than bilinear:

p(x,y)=∑i=03∑j=03cij⋅xi⋅yjp(x, y) = \sum_{i=0}^{3}\sum_{j=0}^{3}c_{ij} \cdot x^i \cdot y^j

The coefficients cijc_{ij} are derived from the values of the adjacent pixels.

  • Pros: high-quality scaling with improved smoothness.
  • Cons: the most demanding in computation and time.

Choosing an algorithm

  • Quality: bicubic gives the best result at the highest cost.
  • Processing power: low-power devices may do best with nearest neighbor or bilinear.
  • Context: real-time applications may favor speed (nearest neighbor) over quality.

Machine learning based methods are also emerging to downscale with minimal quality loss.

AlgorithmHow it worksQualityPerformanceUse cases
Nearest NeighborSelects nearest pixelLow (pixelated)High (fast)Real-time rendering
BilinearWeighted average of 4 nearest pixelsModerate (smooth)ModerateQuick resizing for displays
BicubicWeighted average of 16 nearest pixelsHigh (very smooth)Low (slow)High-quality image processing

Course
Intermediate
27 lessons
15 hours
DSA Fundamentals

Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.

View the course
ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design