This a much discussed topic, but I happen to have an issue that has not been answered yet. My problem is not the method it self but rather it's applicability: My image's f(x,y) represent physical values that can be negative or positive. When I mask the peaks corresponding with, say the median, i get, after application of the inverse FFT, an image which is complex.
This seams logical as image != ifft(fft(image)) if image != image, thus it can very well be complex result?
I thus take the absolute value of my image array, and get a nicely cleaned image. But by taking the abs of the image i have lost the negative values!
My code is complex and uses multiple images to find the correct positions where to mask so I will break down to the essentials:
def everything(fft,fftImage,sizeOfField,shapeOfFFT):
max_x = []
max_y = []
median = np.median(fft)
threshold = 500
#correctLocalMax() holds several subfunctions that look for the propper max_x and max_y. This works fine and returns 2 lists max_x,max_Y that contain the coordiantes of the max's
max_x,max_y = correctLocalMax(iStart = 0,iStop = 30, jStart =0 , jStop = shapeOfFFT[1],threshold=threshold, max_x = max_x, max_y = max_y)
for i in range(len(max_x)):
for k in range(sizeOfField):
for l in range(sizeOfField):
fftImage[max_x[i]+k][max_y[i]+l] = median
return(fftImage)
image, coverage, stdev = pickleOpener(dataDir,i)
field = getROI(image,area,i0,j0)
fftImage = np.fft.fft2(image)
fftImage = np.fft.fftshift(fftImage)
fft = np.fft.fft2(coverage)
fft = np.fft.fftshift(fft)
fftMod = everything(fft, fftImage, sizeOfField, shapeOfFFT)
imageBack = np.fft.ifft2(fftMod)
imageBack = np.abs(imageBack)
field = getROI(imageBack,area,i0,j0)
The images I have and get after processing look like this:
The stripe pattern are the ones I wish to remove
These are the masks applied to the FFT
The stripe pattern is mostly removed, however now the image is purely positive!
You can find the proper solution to the problem in the comments!