The corner of a resized patch is lighter than its edges
Assumes A resize with a negative weight in it, An average on the stored values and The midpoint is not half.
A resize with a negative weight in it took the guarantee that a blend of stored values is always darker than the blend of the light — the consequence of an encoding that bends — and found where it breaks: beside an edge, where a bicubic or Lanczos kernel’s negative lobes fall, the stored-value result is lighter instead, by up to 12.2 colour differences on skin against its shadow. It measured one edge in one dimension and said what that left out. A real resize works along both axes at once, and where two negative lobes multiply, the weight is positive.
A corner is not two edges
In two dimensions the stored-value error along the middle of an edge is the one-dimensional error exactly, and at a corner it is lighter by more than either edge — while a reduction mostly restores the darker sign, and sharpening removes it altogether.
- Along the middle of an edge a Lanczos magnification of skin against shadow is lighter by 12.19 colour differences, the one-dimensional result to the last digit.
- Within three pixels of a corner it is lighter by 14.53, outside the patch; inside the corner, by 3.11. Bicubic: 6.08 along an edge, 6.90 at a corner.
- Reduced to a quarter instead of magnified, the same patch errs lighter by at most 1.00, and darker by up to 2.75.
- An unsharp mask on stored values is lighter than on the light at every amount on every pair and darker nowhere: 9.7 to 17.3 on skin against shadow, and nothing at all on black against white, where the clip takes the overshoot.
What changes between one dimension and two
Every resampling kernel in ordinary use is separable. Its weight on a source pixel is the one-dimensional weight across times the one-dimensional weight down, so a two-dimensional resize is a one-dimensional resize applied twice. Along the middle of a long straight edge, the second application changes nothing: every row of source pixels above and below is the same, the vertical weights sum to one, and the edge is resampled exactly as it was in one dimension.
That is the result’s first check, and it holds exactly. The largest lighter error along the middle of the magnified edge equals the one-dimensional edge’s largest to within the arithmetic, for bicubic and for Lanczos alike.
A corner is different, because near a corner the rows above and below are not the same. A sample just outside a patch’s corner gathers the patch’s colour through two edges at once, with a weight that is the product of a horizontal and a vertical lobe. Where both lobes are positive the product is positive; where one is negative it is negative; and diagonally, where both are negative, the product of two negative weights is positive — a sample outside a corner takes in some of the patch’s colour from a direction a one-dimensional kernel would have subtracted it from.
The corner, measured
The profile through a corner is easiest to read beside the profile across an edge.
Across the middle of the edge the stored-value result swings to 17.1 units of lightness lighter one pixel outside the patch, 6.7 units darker on the boundary, and 2.0 lighter one pixel inside. Along the diagonal through the corner the swing is different in shape: 7.0 darker at the corner itself and 4.3 lighter one pixel diagonally inside. The worst lighter error of the neighbourhood is on neither line. It is outside the patch and off the diagonal; the likely reading is that it sits where one axis’s lobe is negative while the other still reaches the patch with positive weight round the corner, so the sample gathers the patch’s colour through the edge and the corner together.
That is why the map at the head of this essay matters more than either profile. Within three pixels of the corner, the stored-value result is up to 14.53 colour differences lighter than the light’s, all of it outside the patch; inside the corner the largest lighter error is 3.11. Along the edges the largest is 12.19. The darker errors barely change between the two regions, 7.24 along an edge and 7.29 at a corner.
Three kernels, edges and corners
The convex kernel is the check on the whole construction, and the comparison with two kernels that have lobes shows how the corner scales.
Linear interpolation is never lighter, along an edge or at a corner, and darker by up to 7.29 in both. Its weights are never negative in either direction, their products are never negative, and every stored-value result is a convex combination with the darker sign that an average on the stored values established. Bicubic is lighter by 6.08 along an edge and 6.90 at a corner; Lanczos by 12.19 and 14.53. The corner adds about a seventh to bicubic’s worst and a fifth to Lanczos’s, and Lanczos, whose lobes are larger and reach further, has more to multiply.
The edge between a skin tone and its shadow is the case the lighter error is largest on, and it is not the only one.
On dark text against a page, Lanczos is lighter by 3.74 along an edge and 3.74 at a corner, bicubic by 1.81 and 1.93, and all three kernels are darker by up to twenty-two. Text sits near the bottom of the encoding’s range, where its curve bends hardest, and the convex part of each kernel’s error dominates. On black against white the lobed kernels are never lighter at all: their overshoot pushes a stored value past the end of its range in thousands of samples, and the clip takes it from both sides of the comparison — the same concealment clipped noise does not average away found at the bottom of a sensor’s range, working the other way.
A reduction is mostly an average
Everything above was a magnification, in which each output pixel reads a few source pixels with the kernel at its own size. A reduction to a quarter reads the kernel stretched four times as wide, so each output pixel averages dozens of source pixels, most of them through the kernel’s broad positive core.
Reduced to a quarter, skin against its shadow errs lighter by at most 1.00 and darker by up to 2.75; magnified, 14.53 and 7.29. Foliage against sky is lighter by 2.21 reduced and 2.50 magnified, text by 1.59 and 3.74. On every pair the reduction is lighter by less, and on every pair its darker error is the larger of the two it has. Black against white is never lighter either way.
A reduction’s negative lobes are still there. They are spread over four times as many source pixels, each source pixel’s share of a lobe is a quarter as large, and the patch’s edge falls under the lobes of only a few output pixels. Most of what a reduction does is average, and an average of stored values is darker — which is why a thumbnail made on stored values is reliably a little dark in its mid-tone detail, and a magnification made the same way is sometimes light beside its edges and lighter still at its corners.
Two familiar operations are reductions in this sense, whatever they are called. A video’s chroma subsampling averages two of its three channels over blocks of pixels in the encoded variable, and colour thrown away on purpose found what that averaging costs at an edge of nearly equal luminance; its sign is the reduction’s, because its weights are all positive. And a viewer standing back from a halftone or a fine texture performs a reduction of their own — but in the light, before the eye’s compression, which is why a halftone measured with an aperture and seen with an eye comes out darker to the eye than to the instrument. The eye resizes in linear light and a pipeline usually does not, and the difference between them is the error measured here.
Sharpening is an extrapolation
A resize has negative weights as a side effect of reaching further than its nearest neighbours. An unsharp mask has them on purpose. It takes each pixel, subtracts a blurred copy of the image, and adds a multiple of the difference back — a kernel with a positive spike at the centre and a broad negative ring around it, whose total negative weight is the amount.
That makes the stored-value result an extrapolation: the pixel pushed away from its neighbourhood’s average, beyond it. An encoding that bends the way this one does lies above its own chords between two points, and below the continuation of those chords beyond them. A resize’s convex part sits on a chord between two stored values, below the curve, and lands darker; an extrapolation sits on the chord’s continuation, above the curve, and lands lighter. The midpoint is not half was the first half of that statement, and this is the second.
At an amount of a quarter, the stored-value sharpen of skin against its shadow is lighter by up to 9.7 colour differences; at a half, 16.6; at one, 16.8; at two, 16.4. Foliage against sky is lighter by about two and a half at every amount, text by 2.3 to 5.5. At no amount on any pair is any sample darker. Across the edge at an amount of one, the shadow side one and a half pixels out is 17.8 units of lightness lighter on the stored values — the side a sharpen is meant to darken — and the lit side half a pixel in is 5.9 lighter, so the stored-value sharpen both weakens the dark halo it was supposed to create and brightens the light one.
On black against white, and on the pairs between full primaries, the error is nothing at every amount. The extrapolation pushes every value past the end of its range, and the clip returns both results to the same limit. A sharpen tested on a black-and-white target has been tested on the one kind of edge where its stored-value error cannot appear.
Where it shows
The corner result and the sharpening result are about ordinary pictures, and the places they surface are predictable.
A magnified image with a small bright object on a mid-tone ground — a face in a photograph, a light in a window — is a patch with four corners, and the stored-value result puts the lightest error of the whole resize just outside each corner. At a display magnification of two or four, as a viewer zooms in, those are the pixels that read as a bright halo rather than as the object’s edge.
A sharpened skin edge is the case both a camera and an editor produce most. A grey edge arrives coloured from the mosaic, and the sharpening a converter applies next is on stored values in most pipelines, so the lit halo beside a jaw or a cheek is partly the sharpen’s intended overshoot and partly an encoding error of up to seventeen colour differences that a linear-light sharpen would not have made.
A reduction for a thumbnail or a web page is the safe case, in the sense that its errors all run one way: mid-tone detail comes out a little dark. That is the darker guarantee restored by averaging, and a viewer seeing a reduced image at its intended size is looking at an average anyway — a difference has no size — so the error is also the least visible.
What a pipeline could do
The arithmetic points at three changes, each already available in the software that makes these operations.
Resample and sharpen in linear light. A resize or a sharpen applied to linear values and encoded afterwards has neither the darker nor the lighter error, because the operation acts on the light and the encoding bends only the result. Several image libraries offer a linear-light option; it is rarely the default, because on black-and-white test images the stored-value result looks the same.
Test on mid-tone pairs, not on black and white. Every lighter error here is invisible on a full-scale edge, where the clip swallows it. A test image with skin against shadow, foliage against sky and a coloured patch on a mid grey shows what a black-and-white chart cannot.
Treat magnification and reduction differently if only one can be made linear. A reduction’s stored-value error is small and one-signed; a magnification’s is larger, two-signed and worst at corners. If a pipeline can afford linear light for only one of the two, the arithmetic says it is the magnification — and for sharpening, always.
How the patches were computed
Each image is a square patch of one colour of a pair on a field of the other: sixteen source pixels on a side in a thirty-two-pixel image for a magnification, sixty-four in one hundred and twenty-eight for a reduction, clamped at the borders. The kernels are linear interpolation, bicubic with a = −0.5, and three-lobe Lanczos, applied separably and normalised by the sum of their weights at each output sample. A magnification samples the source at a quarter-pixel pitch with the kernel at unit width; a reduction samples every fourth pixel with the kernel stretched four times.
Each output sample is computed twice: from the stored values, and from the linear values encoded afterwards. The comparison is ΔE₀₀ between the two, with the lightness difference signed; a sample counts as moved if the two differ by more than a twentieth of a colour difference. An edge sample lies within three source pixels of an edge and not of a corner, a corner sample within three of a corner in both directions. The unsharp mask adds its amount times the difference between each pixel and a Gaussian blur of radius 1.5 pixels.
What the patches leave out
The images are two colours with hard edges. A photograph’s edges are soft, and a soft edge has less of its contrast within any kernel’s reach, which shrinks every error here; the ordering of edge and corner, and the sign of each operation, do not depend on the hardness.
The sampling phase is fixed. A magnification by a factor that is not a whole number places samples at every offset against the edges, and the worst lighter error moves with that offset; four times is the case that puts samples at the kernel’s own quarter points.
And the comparison is between two numerical results. Whether the corner’s extra lightness is visible as a halo beyond what the edges already show is a question about viewing, and the patches here are twelve source pixels from their neighbours’ influence, which a detailed photograph rarely is.
The habit: a weight’s sign decides which way a curve lies
An operation that combines values with positive weights interpolates between them, and an operation with negative weights extrapolates beyond them. A bent encoding lies on one side of its chords and on the other side of their continuations, so the same curve makes one kind of operation err dark and the other err light.
The move is to find the signs of the weights before predicting the sign of the error — including the products of weights, in two dimensions, where two negatives make a positive. It is the same question the average surface does not look average asked of a scene: which side of a curve an average is taken on, and whether the average is an average at all or reaches beyond the values it combines.
The failure mode is to certify an operation on the edge where the error cannot appear. A resize or a sharpen that looks right on black and white has been checked where the clip does the checking.
Where these results come from
That resampling and sharpening in gamma-encoded values produce different results from linear light, and that linear-light processing is preferable, is standard advice in image processing and has been demonstrated widely on test images. That separable kernels have positive products of negative lobes at diagonal offsets is a property of the tensor-product construction.
The sizes of the corner’s lighter error against the edge’s, the reduction’s return to the darker sign, and that an unsharp mask on stored values is lighter at every amount and darker nowhere, are computed here on constructed patches.
Still open: whether the corner halo is seen
The corner’s extra lightness is a numerical difference between two resampled images. Whether a viewer zooming into a photograph resampled on stored values sees a halo at the corners of small bright objects that the edges alone do not produce — and at which magnifications, on which displays — is a judgement experiment on real images, and it would say whether the corner is a practical reason to resample in linear light or only a mathematical one.
What this makes readable
Essays that name this one as a prerequisite.
Named alongside this one
Essays reaching for the same objects. Nobody chose these; they are what the index of named objects makes visible.
- One step has no choice clipping · colour management · interpolation · spatial frequency · transfer function
- A mean is not a difference colour management · image difference · interpolation
- The display is an unknown colour management · gamma · transfer function
- The order is not in the documentation clipping · colour management · transfer function
- Two converters and one highlight clipping · colour management · transfer function
- A budget drawn through one hue clipping · colour management
What links here
Every essay whose body links to this one.
The objects this essay names
Each one links to every other essay that touches it.
AliasingClippingColour managementGammaImage differenceInterpolationLinear lightSharpeningSpatial frequencyTransfer function