This is machine translation

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



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



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).


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


B = imrotate(A,angle,method,bbox) rotates image A, where bbox specifies the size of the returned image.


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™.

Code Generation support: Yes.

MATLAB Function Block support: Yes


collapse all

Read image into the workspace.

I = fitsread('solarspectra.fts');

Convert to grayscale.

I = mat2gray(I);

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 original image and the rotated image.

title('Original Image')
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.

Example: J = imrotate(I,-1);

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

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

Example: J = imrotate(I,-1);

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

Interpolation method, specified as one of the following values:




Nearest-neighbor interpolation


Bilinear interpolation


Bicubic interpolation

    Note:   Bicubic interpolation can produce pixel values outside the original range.

Example: [ = imrotate(I,-1,'bilinear');

Data Types: char

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




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


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

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

Data Types: char

Image to be rotated, specified as a gpuArray.

Example: X = gpuArray(imread('pout.tif')); Y = imrotate(X, 37, 'loose', 'bilinear');

Output Arguments

collapse all

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

Rotated image, returned as a gpuArray

More About

collapse all

Code Generation

This function supports the generation of C code using MATLAB® Coder™. Note that if you choose the generic MATLAB Host Computer target platform, the function generates code that uses a precompiled, platform-specific shared library. Use of a shared library preserves performance optimizations but limits the target platforms for which code can be generated. For more information, see Understanding Code Generation with Image Processing Toolbox.

When generating code, note the following:

  • The method and bbox arguments must be compile-time constants.

MATLAB Function Block

You can use this function in the MATLAB Function Block in Simulink.

When using this function with the MATLAB Function Block, the input argument angle must be a compile-time constant.


  • 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.

  • This function might take advantage of hardware optimization for data types uint8, uint16, and single to run faster.

Introduced before R2006a

Was this topic helpful?