Resizing does more than change an image's dimensions. It places a new sampling grid over the old image and decides what value each new sample should have. The choice affects edges, small objects, and the correspondence between an image and its labels.
Where does an output pixel look?
Consider a one-dimensional row with input width and output width . A common convention maps the center of output pixel to the following input coordinate:
That coordinate is often fractional. Interpolation estimates the value there. The explorer uses this half-pixel convention on both axes and clamps samples at the image boundary. Different coordinate conventions can shift results, so matching the interpolation name alone may not reproduce another pipeline exactly.
Compare the two outputs, then shrink the checkerboard to 4 and 5 pixels. The source stays fixed; only the sampling grid changes.
8 rows, 8 columns. Values range from 0 to 255. Open numeric values to inspect each row and column.
Numeric values
| Row / column | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 255 | 0 | 255 | 0 | 255 | 0 | 255 |
| 1 | 255 | 0 | 255 | 0 | 255 | 0 | 255 | 0 |
| 2 | 0 | 255 | 0 | 255 | 0 | 255 | 0 | 255 |
| 3 | 255 | 0 | 255 | 0 | 255 | 0 | 255 | 0 |
| 4 | 0 | 255 | 0 | 255 | 0 | 255 | 0 | 255 |
| 5 | 255 | 0 | 255 | 0 | 255 | 0 | 255 | 0 |
| 6 | 0 | 255 | 0 | 255 | 0 | 255 | 0 | 255 |
| 7 | 255 | 0 | 255 | 0 | 255 | 0 | 255 | 0 |
12 rows, 12 columns. Values range from 0 to 255. Open numeric values to inspect each row and column.
Numeric values
| Row / column | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 255 | 255 | 0 | 255 | 255 | 0 | 255 | 255 | 0 | 255 | 255 |
| 1 | 255 | 0 | 0 | 255 | 0 | 0 | 255 | 0 | 0 | 255 | 0 | 0 |
| 2 | 255 | 0 | 0 | 255 | 0 | 0 | 255 | 0 | 0 | 255 | 0 | 0 |
| 3 | 0 | 255 | 255 | 0 | 255 | 255 | 0 | 255 | 255 | 0 | 255 | 255 |
| 4 | 255 | 0 | 0 | 255 | 0 | 0 | 255 | 0 | 0 | 255 | 0 | 0 |
| 5 | 255 | 0 | 0 | 255 | 0 | 0 | 255 | 0 | 0 | 255 | 0 | 0 |
| 6 | 0 | 255 | 255 | 0 | 255 | 255 | 0 | 255 | 255 | 0 | 255 | 255 |
| 7 | 255 | 0 | 0 | 255 | 0 | 0 | 255 | 0 | 0 | 255 | 0 | 0 |
| 8 | 255 | 0 | 0 | 255 | 0 | 0 | 255 | 0 | 0 | 255 | 0 | 0 |
| 9 | 0 | 255 | 255 | 0 | 255 | 255 | 0 | 255 | 255 | 0 | 255 | 255 |
| 10 | 255 | 0 | 0 | 255 | 0 | 0 | 255 | 0 | 0 | 255 | 0 | 0 |
| 11 | 255 | 0 | 0 | 255 | 0 | 0 | 255 | 0 | 0 | 255 | 0 | 0 |
12 rows, 12 columns. Values range from 0 to 255. Open numeric values to inspect each row and column.
Numeric values
| Row / column | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 127.5 | 212.5 | 42.5 | 127.5 | 212.5 | 42.5 | 127.5 | 212.5 | 42.5 | 127.5 | 255 |
| 1 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 |
| 2 | 212.5 | 127.5 | 70.8333 | 184.1667 | 127.5 | 70.8333 | 184.1667 | 127.5 | 70.8333 | 184.1667 | 127.5 | 42.5 |
| 3 | 42.5 | 127.5 | 184.1667 | 70.8333 | 127.5 | 184.1667 | 70.8333 | 127.5 | 184.1667 | 70.8333 | 127.5 | 212.5 |
| 4 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 |
| 5 | 212.5 | 127.5 | 70.8333 | 184.1667 | 127.5 | 70.8333 | 184.1667 | 127.5 | 70.8333 | 184.1667 | 127.5 | 42.5 |
| 6 | 42.5 | 127.5 | 184.1667 | 70.8333 | 127.5 | 184.1667 | 70.8333 | 127.5 | 184.1667 | 70.8333 | 127.5 | 212.5 |
| 7 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 |
| 8 | 212.5 | 127.5 | 70.8333 | 184.1667 | 127.5 | 70.8333 | 184.1667 | 127.5 | 70.8333 | 184.1667 | 127.5 | 42.5 |
| 9 | 42.5 | 127.5 | 184.1667 | 70.8333 | 127.5 | 184.1667 | 70.8333 | 127.5 | 184.1667 | 70.8333 | 127.5 | 212.5 |
| 10 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 | 127.5 |
| 11 | 255 | 127.5 | 42.5 | 212.5 | 127.5 | 42.5 | 212.5 | 127.5 | 42.5 | 212.5 | 127.5 | 0 |
Calculated with half-pixel centers and clamped edges, without an antialias prefilter. Try 4 pixels, then 5: the changing pattern exposes aliasing. Enlarging creates samples, not recovered detail.
Nearest and bilinear make different promises
Nearest-neighbor interpolation chooses a source sample. It preserves the set of possible values but creates abrupt steps when enlarged. Bilinear interpolation combines the four neighboring samples using distance-based weights. Within one cell, with fractional offsets and , it computes:
At the center of samples 0, 100, 100, 200, all weights are one quarter, giving 100. This is a calculated estimate between existing samples. It does not establish that the original scene contained that value or recover detail lost before resizing.
Downsampling needs more than smooth-looking edges
A rapidly alternating checkerboard cannot be faithfully represented on an arbitrarily small grid. Sampling it directly can produce stripes, a false pattern, or a constant image depending on alignment. This is aliasing: different high-frequency inputs become indistinguishable after sampling.
An antialias filter reduces frequencies that the smaller grid cannot represent before sampling. The explorer intentionally omits this prefilter so the failure is visible. For practical resizing, make the antialias setting explicit. Torchvision's resize documentation describes supported interpolation modes, size conventions, and antialias behavior. Torchvision Resize
Preserve the geometry that the task needs
Resizing a 640 × 480 image directly to 320 × 320 uses horizontal scale 0.5 and vertical scale about 0.667. A circle becomes an ellipse. Preserving aspect ratio instead gives 320 × 240; padding 40 pixels above and below produces a square canvas without stretching the contents.
For that letterboxed image, a point maps as follows:
Boxes, landmarks, and masks need the same geometric transformation. When mapping a prediction back, first remove the padding, then divide by the scale. Cropping has a different tradeoff: it preserves scale and shape within the retained region but may remove part of an object.
Images and class masks need different interpolation
A class-index mask might contain 0 for background and 2 for a car. Bilinear interpolation between them can create 1, which could mean an entirely unrelated class. Use a label-preserving operation such as nearest-neighbor for discrete masks. Continuous logits or probability maps are different data and may be interpolated before choosing the final class.
Next, filtering and edge detection make local weighted sums explicit. Later, augmentation applies geometric changes to images and labels together.
Related concepts
Transform images and annotations together, inspect crop and flip geometry, and choose augmentation assumptions that preserve the meaning of the task.
Inspect Gaussian smoothing and Sobel filters as local weighted sums, understand signed gradients and Canny edges, and connect fixed filters to CNNs.
Read an image as an array: inspect RGB channels, grayscale and HSV, and understand coordinates, data types and tensor layouts before preprocessing.
Learn visual complexity analysis in deep learning - how neural networks measure entropy, edges, and saliency for adaptive image processing.
Compare anchor-based vs anchor-free object detection: Faster R-CNN and RetinaNet anchors vs FCOS and CenterNet point-based methods.
Learn how DETR assigns unordered object targets to prediction slots, why greedy choices can fail, and how matching differs from training loss and evaluation.
