imrotate
Rotate image by specified angle
Syntax
J = imrotate(I, angle)
J = imrotate(I, angle, method)
J = imrotate(I, angle, method, bbox)
Input argument
I - Input image: 2-D grayscale image or 3-D RGB image of class uint8, uint16, int16, single, or double
angle - Rotation angle in degrees (scalar). Positive values rotate counterclockwise, negative values rotate clockwise
method - Interpolation method (optional, default: 'bilinear'): - 'nearest': Nearest neighbor interpolation - 'bilinear': Bilinear interpolation (default) - 'bicubic': Bicubic interpolation
bbox - Bounding box option (optional, default: 'loose'): - 'loose': Make output large enough to contain entire rotated image - 'crop': Crop output to same size as input image
Output argument
J - Rotated image, same class as input image I
Description
The imrotate function rotates an image by the specified angle around its center point. The rotation is performed using the specified interpolation method.
The function supports various image formats including grayscale and RGB color images. The output image maintains the same data type as the input image.
For angles that are multiples of 90 degrees, the rotation is performed exactly without interpolation to preserve image quality. For other angles, interpolation is used to estimate pixel values at non-integer coordinates.
The bounding box option controls the size of the output image:
'loose': The output image is sized to contain the entire rotated image. This may result in a larger image than the input.
'crop': The output image is cropped to the same size as the input image. Parts of the rotated image may be cut off.
Background pixels (areas not covered by the rotated image) are filled with zeros.
Note:
Performance Note: For exact 90-degree rotations (0°, 90°, 180°, 270°), the function uses optimized algorithms that preserve exact pixel values without interpolation.
Memory Usage: When using 'loose' bounding box with large rotation angles, the output image may be significantly larger than the input. Consider using 'crop' for memory-constrained applications.
Data Type Preservation: The output image maintains the same data type as the input. For floating-point inputs, pixel values may extend beyond the typical [0,1] range after interpolation.
Angle Convention: Positive angles rotate counterclockwise, following standard mathematical convention. This is opposite to some graphics applications that use clockwise positive rotation.
Limitations:
Input image must be 2-D (grayscale) or 3-D (RGB). Other color spaces are not directly supported.
Rotation is always performed around the center of the image. Off-center rotations require additional preprocessing.
For very large angles (>360°), consider using modulo arithmetic to normalize the angle for better performance.
Bicubic interpolation may produce overshoot artifacts near sharp edges in the image.
Examples
Interactive rotation visualization (Part 1)
Interactive rotation visualization (Part 2)
See also
History
1.14.0
initial version
Author
Allan CORNET
Last updated
Was this helpful?