Image Resample

August 19

1. Basics

ItemDescription
PurposeWhen scaling, rotating, or warping images, recompute pixel values for higher quality, suppressing aliasing and blurring.
Sample PointOutput pixels often map to non-integer input coordinates, requiring interpolation.
Frequency ResponseIdeal resampling is low-pass filtering to suppress high-frequency aliasing. Real algorithms balance sharpness, smoothness, and performance.
Color SpaceRecommended to process in linear space; avoid direct sRGB interpolation to prevent color shift.

2. Common Resample Algorithms (Interpolation Kernels)

Algorithm/TypeApproachAdvantagesDisadvantages/Notes
Nearest NeighborUse nearest integer pixel, no interpolation.Fastest, simplest codeBlocky, jagged, lowest quality
BilinearWeighted average of 2x2 neighbors, linear interpolation.Smooth, fastEdge blur, detail loss
Bicubic4x4 neighbors, cubic kernel interpolation.Balanced sharpness/smoothness, good detailMore computation, possible slight ringing
Lanczos (windowed sinc)Larger neighborhood (e.g. 6x6), windowed sinc kernel.Sharp, excellent anti-aliasingHigh cost, possible ringing
Mitchell-NetravaliCubic kernel, tunable parameters, used for high-quality scaling.Good detail/smoothness, suitable for content pipelineModerate complexity
Area/BoxOutput pixel is average of input region, used for downscaling.Good anti-aliasing when shrinking, fastBlurry when upscaling, detail loss
GaussianBlur with Gaussian weights before sampling.Natural smoothness, good anti-aliasingDetail loss, heavier computation
Catmull-RomCubic family, high sharpness, used in content pipelines.Sharp edges, good detailRinging risk, moderate cost

In practice, nonlinear remapping of bilinear interpolation (e.g. smoothstep) can yield excellent results in some scenarios. See [[Bivariate Interpolation with Smoothstep Reparameterization]].

3. Special Handling & Engineering Tips

Type/ScenarioDescription
Color SpacesRGB → linear for processing, interpolate then convert back to sRGB to avoid color shift/darkening.
Alpha/TransparencyPremultiply alpha before interpolation for physically correct transparency.
Normal MapsTransform to unit vector, interpolate then normalize; avoid direct RGB interpolation to prevent distortion.
Multi-channel/ComponentInterpolate channels independently or as vectors; weight if needed (e.g. Z or curvature).
Boundary Handlingwrap/clamp affects edge sampling; ensure seamless tiling and border pixel copy.

4. Algorithm Selection Advice

Real-time Rendering (Games/Interactive)

  • Prefer bilinear for upscaling, area/box for downscaling
  • Important assets: bicubic or Mitchell-Netravali
  • Lanczos for static or high-quality content
  • Normal maps: interpolate unit vectors then normalize

Offline/Content Pipeline

  • Recommend Mitchell-Netravali, Lanczos
  • Strictly process in linear space, ensure color management

Mobile/Embedded

  • Prefer bilinear/box for cost control
  • Use bicubic if high quality needed

5. Common Pitfalls

  • Interpolating in sRGB space: causes color shift/darkening
  • Directly interpolating normal/specular roughness maps: physically incorrect
  • Improper boundary wrap/clamp: visible seams
  • Not premultiplying alpha for transparency: edge artifacts

6. Reference Formulas

  • Bilinear interpolation: C=(1a)(1b)C00+a(1b)C10+(1a)bC01+abC11C = (1-a)(1-b)C_{00} + a(1-b)C_{10} + (1-a)bC_{01} + abC_{11}
  • Bicubic interpolation: C=i=03j=03wiwjCijC = \sum_{i=0}^{3}\sum_{j=0}^{3} w_i w_j C_{ij}
  • Lanczos kernel: L(x)=sinc(x)sinc(x/a)L(x) = \mathrm{sinc}(x) \cdot \mathrm{sinc}(x/a), commonly a=2,3a=2,3

© 2020 - 2026 Ruiyao Luo

26/03/04 15:15

PROD

#764ff88