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.

imrotate

Syntax

B = imrotate(A,angle)
B = imrotate(A,angle,method)
B = imrotate(A,angle,method,bbox)
gpuarrayB = imrotate(gpuarrayA,method)

Description

example

B = imrotate(A,angle) rotates image A by angle degrees in a counterclockwise direction around its center point. To rotate the image clockwise, specify a negative value for angle. imrotate makes the output image B large enough to contain the entire rotated image. imrotate uses nearest neighbor interpolation, setting the values of pixels in B that are outside the rotated image to 0 (zero).

example

B = imrotate(A,angle,method) rotates image A, using the interpolation method specified by method.

example

B = imrotate(A,angle,method,bbox) rotates image A, where bbox specifies the size of the output image. If you specify 'cropped', imrotate makes the output image the same size as the input image. If you specify 'loose', imrotate makes the output image large enough to include the entirety of the rotated image.

example

gpuarrayB = imrotate(gpuarrayA,method) perform operation on a graphics processing unit (GPU), where gpuarrayA is a gpuArray object that contains a grayscale or binary image, and the output image is a gpuArray object. This syntax requires the Parallel Computing Toolbox™.

Examples

collapse all

Read an image into the workspace, and convert it to a grayscale image.

I = fitsread('solarspectra.fts');
I = rescale(I);

Display the original image.

figure
imshow(I)
title('Original Image')

Rotate the image 1 degree clockwise to bring it into better horizontal alignment. The example specified bilinear interpolation and requests that the result be cropped to be the same size as the original image.

J = imrotate(I,-1,'bilinear','crop');

Display the rotated image.

figure
imshow(J)
title('Rotated Image')

Read image into a gpuArray object.

 X = gpuArray(imread('pout.tif'));

Rotate the image, performing the operation on the graphics processing unit (GPU).

Y = imrotate(X, 37, 'loose', 'bilinear');

Display the rotated image.

figure; imshow(Y)

Input Arguments

collapse all

Image to be rotated, specified as a real, nonsparse, numeric, or logical array.

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

Amount of rotation in degrees, specified as a numeric scalar.

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

Interpolation method, specified as one of the following values:

Value

Description

'nearest'

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

'bilinear'

Bilinear interpolation; the output pixel value is a weighted average of pixels in the nearest 2-by-2 neighborhood

'bicubic'

Bicubic interpolation; the output pixel value is a weighted average of pixels in the nearest 4-by-4 neighborhood

Note

Bicubic interpolation can produce pixel values outside the original range.

Data Types: char

Bounding box that defines the size of output image, specified as either of the following values:

Value

Description

'crop'

Make output image B the same size as the input image A, cropping the rotated image to fit

'loose'

Make output image B large enough to contain the entire rotated image. B is larger than A.

Data Types: char

Image to be rotated, specified as a gpuArray.

Output Arguments

collapse all

Rotated image, returned as a real, nonsparse, numeric, or logical array.

Rotated image, returned as a gpuArray

Tips

  • This function changed in version 9.3 (R2015b). Previous versions of the Image Processing Toolbox™ use different spatial conventions. If you need the same results produced by the previous implementation, use the function imrotate_old.

  • In some instances, this function takes advantage of hardware optimization for data types uint8, uint16, single, and double to run faster.

Extended Capabilities

Introduced before R2006a

Was this topic helpful?