KFOURIER

By Antonio Larrosa Jimenez
Index

NOTE: I've not included the bitmaps in the source package because it would make it grow up to 1.5 Mb , so it will appear some broken links through this file, if you want to have also the images, go to kfourier's homepage and download the images from there, where you will find them in a separate package. Sorry for the inconveniences.

0. How to install the program and where to find it
Once installed the KDE libs, you just have to decompress the file kfourier-1.1.tgz and execute in the newly created directory :
"configure", "make" and "make install" (the last one as root)
You can now run kfourier !
You can download the latest version of kfourier from its homepage, at http://www.arrakis.es/~rlarrosa/kfourier.html

1. How to load images

To load an image you can use 3 methods:
    1. Press 'Open ...' from the 'File' menu
    2. Press the 'Open file' button in the toolbar ()
    3. Take a file from the kfm and drag it to kfourier's window (doing Drag&Drop)

You can open files in xpm,gif and bmp formats
When you load an image, it should appear a column with 4 images , the first one (upper) is the loaded image, and the other 3 are the decomposition in RGB or HSV following the choosed color option
 

1.1 How to save an image

To save an image to the disk, you just have to choose the option "Save(BMP) ..." or "Save (XPM)..." from the 'File" menu, once done that, just click
with the mouse on the image you wish to save, then it will appear a window where you can write the name of the new file

If you decide not to save an image just before clicking over any, but you have already selected the "Save ..." menu, you can press on it again to deselect it

You can choose to save in XPM or BMP formats by selecting the 'Save (XPM)...' or 'Save (BMP)...' options in the menu. It's not possible to save an image in gif format because I would need a licence from Compuserve who has a patent over the gif format.

2. Doing the Fourier transform of an image

When doing the Fourier transform of an image the result will appear in a second row just next to the first. The Fourier transform is made to the 3 decomposed planes of the original image and then they are joint to make the Fourier transform (upper)

After doing the Fourier transform, you can do the inverse Fourier transform that generates new images that appear on a third row in which it appear again a general image and their decomposition (or perhaps it would be better to say that appear three images that are joint to make a general image)

There are two methods to do the Fourier transform :

2.1. Original transform

This method uses the definition of the Fourier transform to calculate it. Due to the lot of sins, cosins, and additions that are required for each point, this method is EXTREMELY SLOW.
You can choose the menu option "Transform | Forward F.T." or from the toolbar, the button

To calculate the inverse, you just have to choose "Transform | Inverse F.T." or from the toolbar, the button
 

2.2. Fast transform

The more often used method is the fast Fourier transform (or FFT)
It's millions and millions faster than the original, and with the same precision.
I found the one-dimensional FFT algorith in Dr Dobbs Journal of February from 1995 and then I change it a little to use the data type that I needed and to clarify it a little. Also, the algorithm was one-dimensional and I needed to do a two-dimensional FFT, so I had to divide a two dimensional F.T. in many one-dimensional in different directions to use this algorithm
You can choose the "Transform | Forward FFT" option in the menu, or in the toolbar, the button , or just the space key from the keyboard
To do the inverse FFT, you can choose "Transform | Inverse FFT", the button  in the toolbar or the backspace key
To realize a FFT it's needed for the dimensions of the image to be a power of 2 (32, 64, 128 , etc.) that's why if you load an image with other dimensions (i.e. 55x81) instead of rejecting it, kfourier first expands the image (in the example, to 64x128), doing black all the created frame and then it calculates the FFT. To do the inverse, the image that is shown in the screen is cropped so that the black frame is not showed.

3. Some filters

You have to choose from the Filters menu, the filter you want to use
Once choosed, you can use it by pressing with the left mouse button over an image of the central column (Fourier transforms). Some filters require two parameter, so they also use the right button.
The filters can be used on the three channels or just on only one of them, by pressing on the upper image, or in the three others.

3.1. Low pass filters

The low pass filters remove the high frequencies of an image, thus leaving a soften image.
Pressing with the left button over a point of the transform, you select the limit radius, so that higher frequencies will be removed
Example:

3.2. High pass filters

The high pass filters remove the low frequencies, so the result image has increased the edges contrast
It's used just as the low pass filter
Example:
 

3.3. Band pass filters

Tha band pass filters, remove the frequencies that are lower than a specified one and higher that another specified one
For that you must define a circular crown, you can do that, by pressing with the right button on the bigger radius, and then with the left button on the smallest one.
Example:
 

3.4. Band stop filters

The band stop filters remove a range of frequencies. They work as the band pass filters.
Example:

3.5. Linear interpolation filters

This filter is similar to the Butterworth one, but while a Butterworth filter uses a function like this :

The linear interpolation uses one like that :

I have made this in that way because I though that it might be more useful to have a filter with two parameters thus defining a range of frequencies where the filter works (so it's used as a band pass or band stop filter)

Example:

 

4. Filter options

The filters are highly configurables, so they are some options that change the way of working of any of them.

4.1. Pass and stop value change

When a value of the transform can pass or not, it's really multiplied by a pass or stop value.
By default, the pass value is 1 (leaving the value just as it is) and the stop value is 0 (multiplying by 0, the value is made 0)
But this values are configurable, so it's possible that a low pass filter multiply the low frequencies by 2 and make 0 the high freqs. or soft them a little, multiplying them by 0.3
It's also possible (but not too interesting) to use a low pass filter achieve the same result than a high pass filter, just by making 0 the pass value and 1 the stop value
Example:
By setting both the pass and stop value to -1 you can obtaing with any filter the same result :

This is obviously the negative of the image, because the Fourier transform is a linear transform

4.2. Activating/Desactivating cuadrants

To understand better the workings of a Fourier transform, it's possible to see what happens if you make the filter work only over one or selected cuadrants instead of all the transform.
In the Filters menu, Cuadrants submenu, you can activate and desactivate the 4 cuadrants
This are the results of removing the 3 cuadrants and leaving only ...
...the first cuadrant, the second :

... the third cuadrant, and the fourth:

4.3. Changing center of filters

By default the center of filters is set to the center of the image (void value of the frequencies), but, what about removing one of the following "stars" ?

This is possible by changing the center of the filters, so if you then choose a high pass filter, you can remove that point of accumulation of frequencies
Once choosen the option, the center of the filters will be set on the point where you press the left button. If once choosen, you decide not to change the center, you can desactivate it by choosing it again from the menu

5. Color options

In the 'Options' menu, you can change the decomposition method of the images:

5.1. RGB

If you choose RGB, the images will be decomposed in the Red, Green and Blue channels:

 
 

5.2. HSV
 
If you choose HSV, the images will be decomposed in the Hue, Saturation and Value channels:

6. Examples

To finish, I will give two examples:
Placing the center of the filters in the middle of the second cuadrant and using a linear filter closing it each time , you can get the following sequence of Fourier transforms and images:



 

And an example on how to use the Fourier transform to remove noise of an image, the original image and it transform are:

If we use a band stop filter the transform and the image are left this way:

and the noise has been removed from the original image !