# Sampling the Affine Rectangle

The definition for sampling an affine rectangle within an image includes both the definition of an affine rectangle and the number of affine pixels into which it is divided. The affine pixels are set to be the same size as the pixels in the image being sampled.

Affine rectangles which represent aligned orthogonal transformations of the input image client coordinate system can be used to create affine samples without the need to perform complicated processing. If the affine rectangle does not, some kind of sampling must be applied to produce a sampled image. The following figure illustrates this problem:

The problem of determining the pixel values when sampling an affine rectangle that is not aligned to the pixel grid of the input image is solved by sampling the pixel grid to produce the sampled image. The Caliper tool supports bilinear interpolation sampling.

Bilinear interpolation considers the values of the four pixels closest to the center of each affine pixel in the affine sampling rectangle. The distance-weighted average of the values of the four pixels is computed and used for the value of the affine pixel.

The following figure shows how bilinear interpolation is computed.

The value of the interpolated affine pixel is computed using the following formula:

where

a, b, c, and d are the four distances shown in a previous figure, normalized so that the distance between pixel centers is 1. p1, p2, p3, and p4 are the values of the four pixels shown in that figure.

The following figure shows how bilinear interpolation would produce the affine sampled image shown in the first figure. The centers of the affine pixels are shown as grey crosses, and the four pixels used to compute each affine pixel are surrounded by a heavy border.

The computed interpolated pixel values are rounded to the nearest whole integer value.