# Rotation with FFT

Via shear it is possible to rotate an image. Since we also implemented a shear algorithm, rotation can be implemented as well. For details look at this webpage.

## Examples

For full interactivity, have a look at this Pluto notebook.

using Revise, FourierTools, Plots, TestImages, PlutoUI, ImageShow

begin
img = Float32.(testimage("fabio_512_gray"))
z = zeros(Float32, (768, 768))
FourierTools.center_set!(z, img)
end

Gray.(FourierTools.rotate(z, 26))

# Function references

FourierTools.rotateFunction
rotate(arr, θ, rotation_plane=(1,2), adapt_size=true, keep_new_size=false)

Rotate an arr in the plane rotation_plane with an angle θ in rad around the center pixel. Note that, in contrast to ImageTransformations.imrotate, the rotation is done around the Fourier-center pixel (size()÷2+1) and not the geometric mid point.

Arguments:

• arr: the array to rotate
• Θ: the angle (in rad) to rotate by
• rotation_plane: two dimensions selecting the 2D plane in which a multidimensional dataset is rotated
• adapt_size: if true (default), the three shears, which make up the rotation, will be allowed to enlarge the size of the array. This is slower but avoids wrap-around artefacts If false, the in-place version of rotate is used with all its problems. Only recommended for very small angles!
• keep_new_size: if true, the enlarged sizes (only for adapt_size=true) will also be returned. Otherwise the resulting data will be cut down to the original size
• pad_value: specifies the value that areas outside the visible range (in the source) should be assigend to. A smart choice can reduce edge artefacts.

rotate! is also available.

FourierTools.rotate!Function
rotate!(arr, θ, rotation_plane=(1,2))

In-place rotate an arr in the plane spanned by the two dimensions in the tuple rotation_plane with an angle θ in rad around the center pixel. Note that, in contrast to ImageTransformations.imrotate, the rotation is done around the Fourier-center pixel (size()÷2+1) and not the geometric mid point. Note also that due to the operation being performed by successive cyclic shear operations in-place, pixels near the corner will be experiencing a massive wrap-around problem. Use the out-of-place version rotate to avoid this. Note also that this version generates very bad results with the angle approaching π. To fix this, use the out-of-place version of rotate.

Arguments:

• arr: the array to rotate
• Θ: the angle (in rad) to rotate by
• rotation_plane: two dimensions selecting the 2D plane in which a multidimensional dataset is rotated