For nearest neighbor interpolation, the block uses the value of nearby translated pixel values for the output pixel values.
For example, suppose this matrix,
represents your input image. You want to translate this image 1.7 pixels in the positive horizontal direction using nearest neighbor interpolation. The Translate block's nearest neighbor interpolation algorithm is illustrated by the following steps:
Zero pad the input matrix and translate it by 1.7 pixels to the right.
Create the output matrix by replacing each input pixel value with the translated value nearest to it. The result is the following matrix:
Note
You wanted to translate the image by 1.7 pixels, but this method translated the image by 2 pixels. Nearest neighbor interpolation is computationally efficient but not as accurate as bilinear or bicubic interpolation.
For bilinear interpolation, the block uses the weighted average of two translated pixel values for each output pixel value.
For example, suppose this matrix,
represents your input image. You want to translate this image 0.5 pixel in the positive horizontal direction using bilinear interpolation. The Translate block's bilinear interpolation algorithm is illustrated by the following steps:
Zero pad the input matrix and translate it by 0.5 pixel to the right.
Create the output matrix by replacing each input pixel value with the weighted average of the translated values on either side. The result is the following matrix where the output matrix has one more column than the input matrix:
For bicubic interpolation, the block uses the weighted average of four translated pixel values for each output pixel value.
For example, suppose this matrix,
represents your input image. You want to translate this image 0.5 pixel in the positive horizontal direction using bicubic interpolation. The Translate block's bicubic interpolation algorithm is illustrated by the following steps:
Zero pad the input matrix and translate it by 0.5 pixel to the right.
Create the output matrix by replacing each input pixel value with the weighted average of the two translated values on either side. The result is the following matrix where the output matrix has one more column than the input matrix: