B = imrotate(A,angle)
B = imrotate(A,angle,method)
B = imrotate(A,angle,method,bbox)
gpuarrayB = imrotate(gpuarrayA,method)
B = imrotate(
angle degrees in
a counterclockwise direction around its center point. To rotate the
image clockwise, specify a negative value for
the output image
B large enough to contain the
entire rotated image.
imrotate uses nearest neighbor
interpolation, setting the values of pixels in
are outside the rotated image to
B = imrotate(
the size of the output image. If you specify
the output image the same size as the input image. If you specify
the output image large enough to include the entirety of the rotated
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.
figure imshow(I) title('Original Image')
figure imshow(J) title('Rotated Image')
Read image into a
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.
A— Image to be rotated
Image to be rotated, specified as a real, nonsparse, numeric, or logical array.
angle— Amount of rotation in degrees
Amount of rotation in degrees, specified as a numeric scalar.
method— Interpolation method
Interpolation method, specified as one of the following values:
Nearest-neighbor interpolation; the output pixel is assigned the value of the pixel that the point falls within. No other pixels are considered.
Bilinear interpolation; the output pixel value is a weighted average of pixels in the nearest 2-by-2 neighborhood
Bicubic interpolation; the output pixel value is a weighted average of pixels in the nearest 4-by-4 neighborhood
bbox— Bounding box defining size of output image
Bounding box that defines the size of output image, specified as either of the following values:
Make output image
Make output image
gpuarrayA— Image to be rotated
Image to be rotated, specified as a gpuArray.
B— Rotated image
Rotated image, returned as a real, nonsparse, numeric, or logical array.
gpuarrayB— Rotated image
Rotated image, returned as a gpuArray
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
In some instances, this function takes advantage of
hardware optimization for data types
double to run faster.
Usage notes and limitations:
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.
must be compile-time constants.