dahtah / imager

R package for image processing
GNU Lesser General Public License v3.0
187 stars 43 forks source link

Fourier transformation with imager #118

Open ajestudillo opened 4 years ago

ajestudillo commented 4 years ago

Hello all,

I recently discovered imager and I am very eager to try. I am running R version 3.6.1.

I want to apply different filters to a set of images. However, I am having problems getting the fourier transformation

FFT(boats)

I obtain the following error:

Error in FFT_realim(im.real, inverse = inverse) : 
  CImgList<double>::FFT(): Specified real and imaginary parts (256,384,1,3) have non 2^N dimension along the Y-axis.

I have tried with other images that I have loaded and I get a similar error:

Error in FFT_realim(im.real, inverse = inverse) : 
cimg::stderr(): Reference to 'stderr' stream not allowed in R mode ('cimg_use_r' is defined).

Any help would be much appreciated

ShotaOchi commented 4 years ago

The error occurs because the height of boats image is not a power of 2. FFT for non power of 2 is possible theoretically but not supported in imager currently.

I use other package such as fftwtools to do FFT for non power of 2. See an example shown below.

library(imager)
g <- grayscale(boats)
tmp <- fftwtools::fftw2d(as.matrix(g)) # complex matrix