Rotate images with automatic cropping
When an image is rotated, using imrotate() for example, blank triangles appear in the corners of the output unless it is reduced in size. The triangles are the parts of the output image that correspond to regions outside the boundary of the input image. This function rotates an image about its centre using imrotate(), then crops the result sufficiently to remove the triangles. Of course, some data in the corners of the original image is lost.
By default the output has the maximum possible area (i,e,. number of pixels) and the crop is symmetrical, so the centre of the output is at the centre of the input image. In this case the function takes the same arguments as imrotate().
Optionally, the aspect ratio of the output may be set to a given value, or to be the same as that of the input. It may also be set so that the corners of the output all lie on the rotated sides of the input, though this is not always possible. In general, if the aspect ratio is set the cropped image will not have the maximum possible area.
When the position of the output is not fully constrained it may optionally be adjusted by a single parameter which sets the position of the centre of the output on the long axis of the rotated input.
Note that if you are using a version of MATLAB older than R2013b you will need to replace any calls to the addParameter method of the input parser with addParamValue.
Cite As
David Young (2024). Rotate images with automatic cropping (https://www.mathworks.com/matlabcentral/fileexchange/48624-rotate-images-with-automatic-cropping), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- Image Processing and Computer Vision > Image Processing Toolbox > Geometric Transformation and Image Registration >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0 |
|