FFT removal of periodic noise
<p>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 <strong>negative or positive</strong>. When I mask the peaks corresponding with, say the median, i get, after application of the inverse FFT, an image which is complex. </p>

<p>This seams logical as image != ifft(fft(image)) if image != image, thus it can very well be complex result?</p>

<p>I thus take the absolute value of my image array, and get a nicely cleaned image. But by taking the abs of the image <strong>i have lost the negative values!</strong></p>

<p>My code is complex and uses multiple images to find the correct positions where to mask so I will break down to the essentials:</p>

<pre><code>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)
</code></pre>

<p>The images I have and get after processing look like this:
<a href="https://i.stack.imgur.com/0QJoy.png" rel="nofollow"><img src="https://i.stack.imgur.com/0QJoy.png" alt="enter image description here"></a>
The stripe pattern are the ones I wish to remove</p>

<p><a href="https://i.stack.imgur.com/7RJF8.jpg" rel="nofollow"><img src="https://i.stack.imgur.com/7RJF8.jpg" alt="enter image description here"></a>
These are the masks applied to the FFT</p>

<p><a href="https://i.stack.imgur.com/0J2DG.png" rel="nofollow"><img src="https://i.stack.imgur.com/0J2DG.png" alt="enter image description here"></a>
The stripe pattern is mostly removed, however now the image is purely positive!</p>

<p><strong>You can find the proper solution to the problem in the comments!</strong></p>

<p>You could try two different approaches:
Either you scale your image between the original values first, and rescale later, somewhat like this:</p>

<pre><code>max_val = max(max(A))
min_val = min(min(A))
% normalize to [0,1]
image = norm(image)
% do your stuff here
% then rescale to original values
image = min_val + (max_val - min_val).*image / (max_val - min_val)
</code></pre>

<p>An alternative would be to save which values where negative in first place.
Although I'd recommend to check whether they got changed during your function call to avoid reinstating your noise</p>

python image-processing fft