FFT: Compute the Discrete Fourier Transform of an image

Description Usage Arguments Value Author(s) Examples

View source: R/utils.R

Description

This function is equivalent to R's builtin fft, up to normalisation (R's version is unnormalised, this one is). It calls CImg's implementation. Important note: FFT will compute a multidimensional Fast Fourier Transform, using as many dimensions as you have in the image, meaning that if you have a colour video, it will perform a 4D FFT. If you want to compute separate FFTs across channels, use imsplit.

Usage

1
FFT(im.real, im.imag, inverse = FALSE)

Arguments

im.real

The real part of the input (an image)

im.imag

The imaginary part (also an image. If missing, assume the signal is real).

inverse

If true compute the inverse FFT (default: FALSE)

Value

a list with components "real" (an image) and "imag" (an image), corresponding to the real and imaginary parts of the transform

Author(s)

Simon Barthelme

Examples

1
2
3
4
5
6
7
8
im <- as.cimg(function(x,y) sin(x/5)+cos(x/4)*sin(y/2),128,128)
ff <- FFT(im)
plot(ff$real,main="Real part of the transform")
plot(ff$imag,main="Imaginary part of the transform")
sqrt(ff$real^2+ff$imag^2) %>% plot(main="Power spectrum")
#Check that we do get our image back
check <- FFT(ff$real,ff$imag,inverse=TRUE)$real #Should be the same as original
mean((check-im)^2)

imager documentation built on May 29, 2017, 8:46 p.m.