Read and rotate transparent or intransparent image

Read and rotate transparent or intransparent image. Output is the rotated image as RGB data and the transparency data alpha. No toolbox!
1 Download
Updated 31 Mar 2025

View License

Rotateim.m
This function reads an (transparent) image and rotates it by theta degrees.
Features
  • No toolbox required
  • Read and rotate transparent/intransparent image
  • Scale image size up/down
  • Crop
Syntax
[imR,alphaR] = rotim(im,theta,bgColor,crop,scale,interpMethod)
INPUT:
im: a) image file name
b) struct with two fields, im.rgb image and im.alpha
im.rgb: height * width * (1 or 3), either 0-255 uint8 or 0-1 double
im.alpha: height * width, either 0-255 uint8 or 0-1 double
theta: Amount of rotation in degrees
bgColor: Color of the given background.
Optional, place holder: NaN
Default: [128, 128, 128]
Integer numbers in the range 0-255
Example: [255 255 0] for yellow
Color of some pixels at the opaque border of the rotated small image.
Those pixels come up by rotating the small image, especially visible with very small
images.
Perfect result is when S.’bgColor’ is the same RGB color as the background.
crop: crop image. Optional, default: no crop
true: crop transparent areas
false: no crop, default
scale: a scalar factor that scales (shrinks or enlarges) the image. Optional, default=1, no scaling
No antialiasing is invoked by changing the scale
interpMethod:
'nearest' - nearest neighbor interpolation, sometimes better for very small images
'linear' - bilinear interpolation (default), recommended
'cubic' - bicubic interpolation
OUTPUT:
imR: Rotated image as RGB values
alphaR: Rotated transparency
Remark:
To increase speed at multiple calls of rotim, some data is stored as peristent data.
Therefore, when the image content has changed, but not the image name, call
imrot without any argument to reset persistent data.
Example:
imshow(rotim('corn.tif',33))
See also enclosed "readMeRotateIm.pd"'.

Cite As

Peter Seibold (2025). Read and rotate transparent or intransparent image (https://www.mathworks.com/matlabcentral/fileexchange/180599-read-and-rotate-transparent-or-intransparent-image), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2024b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.2

Update of summary.

1.0.1

Updated descriptiom

1.0.0