Translate an Image using imtranslate Function
This example shows how to perform a translation operation on an image using the imtranslate function. A translation operation shifts an image by a specified number of pixels in either the x- or y-direction, or both.
Read an image into the workspace.
I = imread('cameraman.tif');
Display the image. The size of the image is 256-by-256 pixels. By default, imshow displays the image with the upper right corner at (0,0).
figure
imshow(I)
title('Original Image')
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5CN4ETO0QTNiFzY1gDMkJTZ1U2YyAjMkZWO1EWYykzYy8CX0JXZ252bj91Ztl2Lc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
Translate the image, shifting the image by 15 pixels in the x-direction and 25 pixels in the y-direction. Note that, by default, imtranslate displays the translated image within the boundaries (or limits) of the original 256-by-256 image. This results in some of the translated image being clipped.
J = imtranslate(I,[15, 25]);
Display the translated image. The size of the image is 256-by-256 pixels.
figure
imshow(J)
title('Translated Image')
Use the 'OutputView' parameter set to 'full' to prevent clipping the translated image. The size of the new image is 281-by-271 pixels.
K = imtranslate(I,[15, 25],'OutputView','full');
Display the translated image.
figure
imshow(K)
title('Translated Image, Unclipped')