Nearest Neighbor Interpolation in Photoshop

Nearest neighbor resampling in Adobe Photoshop is the simplest digital image scaling algorithm, relying on zero-order mathematical interpolation to resize raster graphics. This article explains the exact mathematical principles governing nearest neighbor resampling, how pixel mapping and rounding functions determine pixel values, and the visual characteristics that distinguish this method from higher-order algorithms.

The Underlying Mathematics: Zero-Order Interpolation

Photoshop’s nearest neighbor algorithm is mathematically classified as zero-order hold (ZOH) or piecewise-constant interpolation. Unlike first-order (bilinear) or third-order (bicubic) interpolation, zero-order interpolation does not calculate weighted averages or generate intermediate values between existing samples.

In signal processing terms, nearest neighbor represents the convolution of discrete input samples with a normalized rectangular box function (a Haar filter) with a width of 1:

\[\Pi(x) = \begin{cases} 1 & \text{if } |x| < 0.5 \\ 0 & \text{if } |x| \ge 0.5 \end{cases}\]

This operation replicates the closest original discrete sample value across an entire unit interval without smoothing or gradual falloff.

Coordinate Transformation and the Rounding Function

When scaling an image, Photoshop maps the target canvas coordinates back into the source image's coordinate space.

Let a source image have dimensions \(W_{s} \times H_{s}\) and a target image have dimensions \(W_{t} \times H_{t}\). For any target pixel coordinate \((x_t, y_t)\), the scale factors are:

\[s_x = \frac{W_s}{W_t}, \quad s_y = \frac{H_s}{H_t}\]

The mapped source continuous coordinates \((u, v)\) are:

\[u = (x_t + 0.5) \cdot s_x - 0.5\] \[v = (y_t + 0.5) \cdot s_y - 0.5\]

The nearest neighbor algorithm applies a rounding function (or standard Euclidean distance minimization) to locate the discrete integer coordinates \((x_s, y_s)\) of the closest pixel center:

\[x_s = \lfloor u + 0.5 \rfloor\] \[y_s = \lfloor v + 0.5 \rfloor\]

The color value assigned to the destination pixel is the exact value of that single closest source pixel:

\[I_{\text{target}}(x_t, y_t) = I_{\text{source}}(x_s, y_s)\]

No color mixing, blending, or anti-aliasing occurs.

Practical Implications

Because nearest neighbor uses a zero-degree polynomial:

  • Palette Preservation: It introduces zero new color values into the image, making it strictly palette-safe.
  • Sharp Transitions: Edge boundaries remain completely hard, which is essential when resizing pixel art, binary masks, or technical maps where intermediate blended colors would corrupt data.
  • Aliasing: When applied to continuous-tone photography, it creates noticeable stair-stepping ("jaggies") and geometric distortion because high-frequency spatial components are neither pre-filtered nor smoothly reconstructed.