Image rotation: forward versus inverse mapping
geometric warping mechanics.
forward mapping sends source pixels to non-integer destinations, leaving holes and overlaps; inverse mapping iterates over output pixels, finds the source location, and interpolates.
WHAT THIS TESTS The interviewer probes whether you grasp that images live on a discrete integer grid, so any non-integer geometric transform requires resampling, and why the direction of mapping matters.
A GOOD ANSWER COVERS A rotation by an arbitrary angle multiplies each pixel coordinate by a rotation matrix, almost always producing fractional destination coordinates. Forward mapping takes each source pixel and computes where it lands in the output. The problem is twofold: those destinations are non-integer, so they do not align with output pixel centers, and the spreading geometry means some output pixels receive no source pixel at all, leaving holes, while others receive several, causing overlaps. Inverse mapping reverses the loop: for every output pixel you apply the inverse rotation to find the exact source coordinate it came from, then sample the source there.
COMMON WRONG ANSWERS Claiming forward mapping fills the output cleanly. Forgetting interpolation entirely and rounding to the nearest source pixel, which causes aliasing. Confusing which transform direction is applied during inverse mapping.
LIKELY FOLLOW-UPS What interpolation schemes exist and how do they trade quality for cost. How do you handle output pixels that map outside the source. Why does nearest-neighbor look blocky.
ONE CONCRETE EXAMPLE To rotate by 30 degrees with inverse mapping, you iterate over each pixel of the destination image. For output pixel at (x, y) you apply the inverse rotation, rotating by minus 30 degrees about the center, and get a source coordinate like (47.3, 88.7). Since that is not an integer location, you take the four surrounding source pixels at (47, 88), (48, 88), (47, 89), (48, 89) and bilinearly interpolate their intensities weighted by the fractional offsets 0.3 and 0.7, producing a smooth value. Every output pixel is therefore guaranteed exactly one value with no holes or overlaps, and interpolation suppresses jagged aliasing. If a source coordinate falls outside the image bounds you assign a fixed border value such as black. This output-driven, inverse approach is the standard way every practical library implements rotation and general affine warps.
Read the original → en.wikipedia.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.