Fourier-Xform-filtering.pfp
This is a demo of the Fourier Transform and its use in low-pass and high-pass filtering.
In the low-pass example only those frequency components within +/- 7 cps of 0 in both
X and Y are retained.
There are 10 steps in this demo. First we read in the Mona Lisa image. It is
forced into a 256x256 format. It is essential that the width and height be powers
of two, because that is a requirement of the most common implementations of
the Fast Fourier Transform, including the one used in PixelMath.
Second, we convert the image into complex-number form. The "c" in the size
expression sets up the complex format. The formula "Complex(s1(x,y), 0)" then
copies each source pixel to the real part of the corresponding destination pixel.
The imaginary part of each destination pixel is set to zero.
The third step invokes the built-in 2-dimensional Fast Fourier Transform operation,
puting the result into a new complex-number image in window 3.
In Step 4, the transform is translated in x and y by half the width and half the height,
so that the origin (where the DC component of the transform lies) gets centered.
The resulting complex image corresponds to a standard textbook view of the
2D Fourier Transform, with the origin in the middle of the image.
In Step 5, the formula defines a square region in the center of the transform image,
and sets all the pixels outside that square to have value 0. This eliminates all the
high-frequency components of the transform image.
In Step 6, this edited transform is translated back by w/2, h/2 in preparation for the
inverse transform operation. In step 7, the inverse transform is computed.
The result in window 7 is a low-pass filtered version of the Mona Lisa. By changing the
size of the square in step 7, and then reevaluating formulas for that and the remaining
steps, the amount of low-pass filtering can be adjusted easily. The size of the square
is changed by changing the 8 to a larger or smaller value.
Windows 8, 9, and 10 offer a variation on windows 5, 6, and 7, this time reducing the
low-frequency energy and increasing the high-frequency energy.
BEGIN FORMULA BARS
1#|#Mona#|#256,256#|##|#@server:tanimoto:mona-rgb.jpg#|#c#|#Orig#|#0,100
2#|#Complex Mona#|#256,256,c#|#1,*,#|#complex(s1(x,y),0)#|#c#|#Complex version#|#250,100
3#|#FFT#|#256,256,c#|#2,3,#|##fft#|#c#|#Transform#|#500,100
4#|#centered FFT#|#256,256,c#|#3,*,#|#s1((x+w/2) mod w, (y+h/2)mod h)#|#c#|#Transform#|#550,100
5#|#Edited FFT#|#256,256,c#|#4,*#|#if {abs(x-w/2)>8} or {abs(y-h/2)>8} then 0 else S1(x,y)#|#c#|#Edited (low-pass)#|#650,100
6#|#Uncentered Edited FFT#|#256,256,c#|#5,*#|#s1((x+w/2) mod w, (y+h/2)mod h)#|#c#|##|#700,100
7#|#Inverse#|#256,256,c#|#6,*#|##ifft#|#c#|#Filtered (low pass)#|#800,100
8#|#Edited FFT#|#256,256,c#|#4,*#|#if {abs(x-w/2)>20} or {abs(y-h/2)>20} then 10*S1(x,y) else S1(x,y)*0.0#|#c#|#Edited (high-pass)#|#650,350
9#|#Uncentered Edited FFT#|#256,256,c#|#8,*#|#s1((x+w/2) mod w, (y+h/2)mod h)#|#c#|##|#700,350
10#|#Inverse#|#256,256,c#|#9,*#|##ifft#|#c#|#Filtered (high-pass)#|#800,350