To get more training data, the LeNet-5 experiments added randomly distorted copies of the training digits, using planar affine maps: horizontal and vertical translation, scaling, squeezing and horizontal shearing. Implement the distortion of one image for given parameters.
Implement distort(img, tx, ty, scale, squeeze, shear, background).
Coordinates. Pixel of an image sits at , with the centre , ( to the right, downward).
The map. A point of the input image is sent to
with = scale, = squeeze (horizontal factor , vertical factor ), = shear, = tx, = ty.
The output. For every output pixel , find the input point that the map sends there and read the input there by bilinear interpolation between the four surrounding pixels. A neighbour that lies outside the input image counts as background.
Output: float array of shape .