Translate an image spatially by a specified 2D vector.
This function shifts the input image img by the amount specified in translation, using the specified interpolation method. It supports grayscale, RGB images, or even multi-channel images. Image type can int8, uint8, int16, uint16, int32, uint32, single or double.
You can optionally specify spatial referencing objects to define the coordinate system of the input and output images.
Note imtranslate does not support 3D translation of 3D volumes.
Inputs
Input image. Can be:
A numeric 2D vector specifying the translation in pixels. If spatial referencing is used, translation is interpreted in world units.
(Optional) Interpolation method. One of:
"nearest", "linear"/"bilinear", "cubic"/"bicubic".
Default is "linear".
(Optional) An imref2d object specifying the spatial referencing of the input image. This object defines the mapping between pixel coordinates and world coordinates for the input image. Image size in input_ref shoule be the same as the size of img If omitted, a default imref2d object is created for the image size.
(Optional) Name-value pairs:
"FillValues"Scalar or array specifying fill values for pixels outside the input image domain. Default is 0. FillValues can be a scalar, or in the case of MxNXC image a C-dimensional vector
"OutputView"String specifying how to determine the size and limits of the output image.
Options:
"same" Output image is the same size as input.
"full" Output image includes all translated pixels.
Outputs
Translated output image. Same class as input img.
(Optional) An imref2d object specifying the spatial referencing of the output image. This object describes the world limits, pixel extents, and image size of the output image, allowing for accurate mapping between pixel and world coordinates after translation.
Examples
I = phantom(); J = imtranslate(I, [25 10]); imshow(J);
input_ref = imref2d(size(I), [0.5 100.5], [0.5 100.5]); # Define input spatial reference J = imtranslate(I, input_ref, [5 5], "bilinear", "OutputView", "same"); imshow(J);
Algorithm
This function uses imtransform to calculate the translated image
See also: imtransform, imresize, imrotate, imref2d.
Package: image