Translate
Translate image or video frame
Libraries:
Computer Vision Toolbox /
Geometric Transformations
Description
The Translate block shifts an input image or video frame by the number of pixels in the vertical and horizontal directions specified by a two-element offset vector.
Examples
Translate Image in Vertical and Horizontal Directions
Translate an input image in the vertical and horizontal directions.
Ports
Input
Image — Input image or video
matrix | array
Input image or video, specified as an M-by-N matrix, M-by-N-by-T array, M-by-N-by-C array, or M-by-N-by-C-by-T array. T is the number of frames in a video or image sequence, and C is the number of color channels.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Offset — Translation value
vector
Translation value, specified as a two-element vector of the form
[vertical horizontal]
. The vertical
value in
the vector is the number of pixels to shift the image up or down in the vertical
direction. The horizontal
element is the number of pixels to shift
the image left or right in the horizontal direction. The axes origin is the top-left
corner of the input image.
To translate the image downward, specify positive pixel values to the
vertical
element.To translate the image upward, specify negative pixel values to the
vertical
element.To translate the image to the right, specify positive pixel values to the
horizontal
element.To translate the image to the left, specify negative pixel values to the
horizontal
element.
Dependencies
To enable this port, set the Offset source parameter to
Input port
.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Output
Output — Translated image or video
matrix | array
Translated image or video, returned as a P-by-Q matrix, P-by-Q-by-T array, P-by-Q-by-C array, or P-by-Q-by-C-by-T array. T is the number of frames in a video or image sequence, and C is the number of color channels.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Parameters
Output size after translation — Translated image size
Full
(default) | Same as input image
Specify the size of the translated image as Full
or
Same as input image
.
Full
— The block outputs a matrix that contains the entire translated image.Same as input image
— The block outputs a matrix of the same size as the input image, which contains a portion of the translated image.
Offset source — Source of translation value
Specify via dialog
(default) | Input port
Specify the source of translation value as one of these options:
Specify via dialog
— Specify the translation value using the Offset parameter.Input port
— Specify the translation value using the Offset port.
Offset — Translation value
[1.5 2.3]
(default) | two-element vector
Specify the translation value as a two-element vector of the form [vertical
horizontal
]. The vertical element in the vector is the number of pixels to
shift the image up or down in the vertical direction. The horizontal element is the
number of pixels to shift the image left or right in the horizontal direction. The axes
origin is the top-left corner of the input image.
To translate the image downward, specify positive pixel values to the
vertical
element.To translate the image upward, specify negative pixel values to the
vertical
element.To translate the image to the right, specify positive pixel values to the
horizontal
element.To translate the image to the left, specify negative pixel values to the
horizontal
element.
Dependencies
To enable this parameter, set the Offset source parameter to
Specify via dialog
.
Maximum offset — Translation value limits
[8 10]
(default) | two-element vector
Specify the maximum number of pixels to translate the input image in the vertical
and horizontal directions, as a vector of the form [vertical
horizontal
]. The translate block uses this parameter to determine the size
of the translated image when the Output size after translation
parameter is set to Full
and the Offset
source parameter is set to Input port
. If either
input value to the Offset port is greater than the corresponding
value of the Maximum offset parameter, the translate block reduces
that input translation value to the corresponding maximum translation value.
Dependencies
To enable this parameter, set the Offset source parameter to
Input port
.
Background fill value — Intensity or color of background in translated image
0
(default) | scalar | RGB triplet
Specify the intensity or color of the background of the translated image as a scalar intensity value or an RGB triplet.
Interpolation method — Method for interpolating translated pixel values
Bilinear
(default) | Nearest neighbor
| Bicubic
Specify the method by which to interpolate the pixel values of the translated image as one of these options:
Nearest neighbor
—The Translate block uses the value of the nearest pixel for the interpolated pixel.Bilinear
— The interpolated pixel value is the weighted average of the 4 nearest pixel values.Bicubic
— The interpolated pixel value is the weighted average of the 16 nearest pixel values.
The number of pixels the block considers for interpolation affects the complexity
and accuracy of the computation. The Nearest neighbor
interpolation, which uses the fewest pixels, is the most computationally efficient and
least accurate, while the Bicubic
interpolation is the least
computationally efficient and the most accurate. For more information about
interpolation methods and kernels, see the More About section and
the Create and Compare Resizing Interpolation Kernels example.
Block Characteristics
Data Types |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
More About
Nearest Neighbor Interpolation
For nearest neighbor interpolation, the block uses nearby, translated, pixel values for the output pixel values.
For example, suppose this matrix, represents your input image,
and you want to translate this image 1.7 pixels in the positive horizontal direction using nearest neighbor interpolation. These steps illustrate the nearest neighbor interpolation algorithm followed by the block:
Zero pad the input matrix and translate it 1.7 pixels to the right.
Create the output matrix by replacing each input pixel value with the translated value nearest to it resulting in this matrix:
Note
Despite specifying a value of 1.7 pixels to translate the image, this method translates the image by 2 pixels. Nearest neighbor interpolation is computationally efficient, but not as accurate as the bilinear and bicubic interpolation methods.
Bilinear 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,
and you want to translate this image by 0.5 pixels in the positive horizontal direction using bilinear interpolation. These steps illustrate the bilinear interpolation algorithm followed by the block:
Zero pad the input matrix and translate it 0.5 pixels to the right.
Create the output matrix by replacing each input pixel value with the weighted average of the translated pixel values on either side of the input pixel. The result is this matrix which has one column more than the input matrix.
Bicubic Interpolation
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,
and you want to translate this image by 0.5 pixels in the positive horizontal direction using bicubic interpolation. These steps illustrate the bicubic interpolation algorithm followed by the block:
Zero pad the input matrix and translate it by 0.5 pixels 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 this matrix which has one column more than the input matrix:
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Version History
Introduced before R2006a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)