imrotate3_fast

version 1.1.0.0 (312 KB) by
Fast 3D image rotations

Updated 5 Aug 2017

This function performs fast rotation of three-dimensional matrices.
When working with transformation of large three-dimensional data, speed can be critical. The imwarp function, and (released in R2017a) the imrotate3 function (which uses imwarp) in the image processing toolbox perform these rotations orders of magnitude slower than the imrotate function does in two dimensions. The cost is not simply due to the increased complexity of a three-dimensional rotation, but rather is because the imrotate function uses some super-speedy mex code.
Here, I've defined a three dimensional rotation problem in terms of an ordered series of two dimensional rotations, and used the permute function to apply imrotate to the appropriate dimensions. Even with the cost of rearranging the dimensions, this approach produced much quicker results.
imrotate3_fast provides a few other potential speed advantages. 1. Because rotations are computed in series, rotations applied to only one or two of the axes are even faster. 2. Because imwarp seems to work natively with floating points, it becomes much slower with integers, conversely imrotate works faster with integers. So for 3D rotations of volumetric integer data (e.g. microscopy data), the speed differences are enormous, and allow for reduced memory demands.
Note: imrotate3 performs a single rotation around an arbitrary axis (axis-angle), whereas imrotate3_fast takes a series of rotations around the x,y,z axes (Euler angles). It made sense to me to keep the inputs in this format, but I've included convenience functions for converting between Euler and Axis-Angle.
Speed tests were performed on a 64-bit PC with an i7-4790 and 32gb of RAM, running Windows. I included data (separately) collected under conditions where ample free physical memory was available, and where it fell short. The code for these tests is also included.

Cite As

Dave (2022). imrotate3_fast (https://www.mathworks.com/matlabcentral/fileexchange/64002-imrotate3_fast), MATLAB Central File Exchange. Retrieved .

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