Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

imtranslate

Translate image

Syntax

B = imtranslate(A,translation)
[B,RB] = imtranslate(A,RA,translation)
___ = imtranslate(___,method)
___ = imtranslate(___,Name,Value)

Description

example

B = imtranslate(A,translation) translates image A by the translation vector specified in translation. If A has more than two dimensions and translation is a two-element vector, imtranslate applies a 2-D translation to A, one plane at a time.

[B,RB] = imtranslate(A,RA,translation) translates the spatially referenced image A with its associated spatial referencing object RA. The translation vector, translation, is in the world coordinate system. The function returns the translated spatially referenced image B, with its associated spatial referencing object, RB.

___ = imtranslate(___,method) translates image A, using the interpolation method specified by method.

example

___ = imtranslate(___,Name,Value) translates the input image using name-value pairs to control various aspects of the translation.

Examples

collapse all

Read image into the workspace.

I = imread('pout.tif');

Translate the image.

J = imtranslate(I,[25.3, -10.1],'FillValues',255);

Display the original image and the translated image.

figure
imshow(I);
title('Original Image');
set(gca,'Visible','on');

figure
imshow(J);
title('Translated Image');
set(gca,'Visible','on');

Read image into the workspace.

I = imread('pout.tif');

Translate the image. Use the OutputView parameter to specify that you want the entire translated image to be visible.

J = imtranslate(I,[25.3, -10.1],'FillValues',255,'OutputView','full');

Display the original image and the translated image.

figure
imshow(I);
title('Original Image');
set(gca,'Visible','on');

figure
imshow(J);
title('Full Translated Image');
set(gca,'Visible','on');

Load MRI data into the workspace and display it.

s = load('mri');
mriVolume = squeeze(s.D);
sizeIn = size(mriVolume);
hFigOriginal = figure;
hAxOriginal  = axes;
slice(double(mriVolume),sizeIn(2)/2,sizeIn(1)/2,sizeIn(3)/2);
grid on, shading interp, colormap gray

Apply a translation in the X,Y direction.

mriVolumeTranslated = imtranslate(mriVolume,[40,30,0],'OutputView','full');

Visualize the translation by viewing an axial slice plane taken through center of the volume. Note the shift in the X and Y directions.

sliceIndex = round(sizeIn(3)/2);
axialSliceOriginal   = mriVolume(:,:,sliceIndex);
axialSliceTranslated = mriVolumeTranslated(:,:,sliceIndex);

imshow(axialSliceOriginal);

imshow(axialSliceTranslated);

Input Arguments

collapse all

Image to be translated, specified as a nonsparse, numeric array of any class, except uint64 and int64, or a logical array.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | logical

Spatial referencing information associated with the input image A, specified as an imref2d or imref3d spatial referencing object.

Translation vector, specified as a two-element or three-element, nonsparse, real-valued, numeric vector, such as [Tx Ty], for 2-D inputs, and [Tx Ty Tz], for 3-D inputs. Values can be fractional.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32

Interpolation method, specified by one of the following values:

ValueDescription
'cubic'Cubic interpolation.

Note

Cubic interpolation can produce pixel values outside the original range.

'linear'Linear interpolation
'nearest'

Nearest-neighbor interpolation; the output pixel is assigned the value of the pixel that the point falls within. No other pixels are considered.

Data Types: char

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: mriVolumeTranslated = imtranslate(mriVolume,[40,30,0],'OutputView','full');

collapse all

Output world limits, specified as the comma-separated pair consisting of 'OutputView' and one of the following values:

ValueDescription
'same'Output world limits are the same as the input image.
'full'Output world limits are the bounding rectangle that includes both the input image and the translated output image.

Data Types: char

Fill values used for output pixels outside the input image, specified as the comma-separated pair consisting of 'FillValues' and a numeric array containing one or several fill values. imtranslate uses fill values for output pixels when the corresponding inverse transformed location in the input image is completely outside the input image boundaries.

  • If A is 2-D,FillValues must be a scalar.

  • If A is 3-D and translation is a three-element vector, FillValues must be a scalar.

  • If A is N-D and translation is a two-element vector, FillValues can be either scalar or an array whose size matches dimensions 3-to-N of A. For example, if A is a uint8 RGB image that is 200-by-200-by-3, FillValues can be a scalar or a 3-by-1 array.

  • If A is 4-D, FillValues can be a scalar or an array. For example, if A is 200-by-200-by-3-by-10, then FillValues can be a scalar or a 3-by-10 array.

    Some example fill values:

    Fill ValueDescription
    0 Fill with black
    [0;0;0] Fill with black
    255Fill with white
    [255;255;255]Fill with white
    [0;0;255]Fill with blue
    [255;255;0]Fill with yellow

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32

Output Arguments

collapse all

Translated image, returned as a nonsparse, real-valued, numeric array or logical array. The class of B is the same as the class of A.

Spatial referencing information associated with the output image, returned as an imref2d or imref3d spatial referencing object.

Tips

  • imtranslate is optimized for integrally valued translation vectors.

  • When 'OutputView' is 'full' and translation is a fractional number of pixels, imtranslate expands the world limits of the output spatial referencing object to the nearest full pixel increment. imtranslate does this so that it contains both the original and translated images at the same resolution as the input image. The additional image extent in each is added on one side of the image, in the direction that the translation vector points. For example, when translation is fractional and positive in both X and Y, then imtranslate expands the maximum of XWorldLimits and YWorldLimits to enclose the 'full' bounding rectangle at the resolution of the input image.

Extended Capabilities

Introduced in R2014a

Was this topic helpful?