I want to high-pass filter an image in Fourier space. It works but the retransformed image has an imaginary part, what shouldn't be the case http://math.stackexchange.com/questions/867337/how-to-interpret-the-imaginary-part-of-an-inverse-fourier-transform. I have two questions:

  1. Is that a problem?
  2. How can I fix it?

Here is my code: I work with the IMAGER-Package for loading the image and for the Fourier transform

The original image imLenaGr has dim 512/512 (Image plotted at the end).

Transforming the image to Fourier space

lenaFFT <- FFT(imLenaGr)

Transform to matrix and rotate the image so that low frequencies are in the middle

lenaFFTMa <- matrix(complex(real = lenaFFT$real,imaginary = lenaFFT$imag), nrow = 512, ncol = 512)

lenaRot <- fftshift(lenaFFTMa)

Calculating the amplitude for plotting purposes

ampLena <- lenaRot %>% Mod() %>% log()

Creating the filter

heigthM <- height(lenaRot)
widthM <- width(lenaRot)

# Creat empty filter matrix
filMa <- matrix(nrow = heigthM, ncol = widthM)

# Create matrix with values indicating distance from the midpoint of the matrix
distMa <- filMa

for(x in 1:widthM){
  for(y in 1:heigthM){
distMa[x,y] <-  sqrt((x - (widthM/2 + 0.5))^2 + (y - (heigthM/2 + 0.5))^2)
# I also tried it with sqrt((x - (widthM/2))^2 + (y - (heigthM/2))^2) but it didn't work

# finding the cut-off-distance
cutOff <- max(distMa) * 0.03 #0.03 cut off value

# Creating a butterworth filter
for(x in 1:widthM){
  for(y in 1: heigthM){
filMa[x,y] <-  1 - (1/(1 + (distMa[x,y]/cutOff)^11))

Then I multiplicated the Fourier image with the Filter

lenaFilFftRot <-lenaRot * filMa

Afterwards, I rotated and transformed the image back.

# low freq to the edge
lenaFilFft <- ifftshift(lenaFilFftRot)

# transforming back
lenaFil <- FFT(im.real = Re(lenaFilFft) %>% as.cimg(), im.imag = Im(lenaFilFft) %>% as.cimg(), inverse = TRUE)

My problem is now that I have a not insignificant imaginary part


1 -0.02229874 0.02248397

I tried it without filtering and then there was no problem. So the problem must be the filter. I read that the filtered fft has to be complex conjugate. But as I am not from a technical or mathematical field, I don't know why applying my filter violates this assumption.

Images: 1) Original image, 2) fft with filter, 3) filtered image

Thank you for your help.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.