Sticky

#### [1.3.9.0 (upcoming)] : New filter 'Fourier Transform'

Hi.
Some news about incoming features in next G'MIC release (planed for next wednesday, my birthday date :) )
I have added a new interesting filter 'Fourier Transform' which allows the users to get the frequency magnitude/phase of the current image, modify it (using the usual GIMP tools), and compute back the inverse fourier image.

The nice thing with such a filter is that it allows to remove undesired high frequencies in the image (such as pattern noise for instance).
Let me illustrate how it can be to remove an undesired pattern from this image :

(I took it from this French forum : www.passion-metrique.net/forums/viewtopic.php?f=11&t=..., I hope they don't mind, but the image is very nice to illustrate the problem).

So, in this image, we can clearly see a very important 'pattern noise' that we want to remove. Let us try G'MIC, and its new 'Fourier Transform' filter :)

It is a very simple filter with only one parameter which selects the direct or inverse Fourier transform (applying an inverse Fourier transform on an arbitrary image won't work since there are G'MIC specific informations in Fourier transformed images).

Here is the Fourier transform we obtain :

The important part of this image is located at the up-left portion. It shows the module of the centered image frequencies, and we clearly see that there are high-frequencies located in places other than the center. Those frequencies correspond actually to the pattern noise we are viewing on the original image. So, we just take a brush in black, and remove thes high-frequency patterns (you don't have to be very precise). After some moves, I get this :

You don't have to change the other parts of the Fourier image. They contain useful informations to be able to do the inverse transform, but for us, it is just like garbage data. Just for information, frequency phase is the right part of the image.

Well, we are done, we just have to invert the Fourier transform, here again by using the G'MIC Fourier transform. And we get this :

It's far better ! Most of the structured pattern noise have disappeared, and only some random-like noise is still in place. For this, the application of the 'Anisotropic smoothing' and 'Octave sharpening' steps (again with G'MIC :) ) can be used to get something more clean (perhaps a little bit too clean in my case..).

Here is the final result :

Compared to the original :

Also, I've done another cleaning with the same image, on my home laptop (it took me 3 minutes from scratch), in order to get this before/after image :

Any comment is appreciated.

Regards,

David.
David

You are an absolute star. A Million thank you's for this tool.

Regards

Riaan
Wow !
MOD
Very much looking forward to this one David. I have both FFT and iFFT filters that I use in GIMP, but like the G'MIC interface and might make the flow easier. :)
Very Nice...a new area for me........need to take some appropriate pictures to work on.....
There are very nice possibilities with this new filter, basically because the Fourier Transform has very nice properties for a lot of applications.

Here, I illustrate how to silently 'watermark' your images, using this new filter.

First, take the image you want to watermark (a high resolution is better, but for this example, I show it can work with low resolutions too) :

I compute then the Fourier Transform using G'MIC, and I get this :

Then, I simply put my watermark on the frequency module, using the GIMP paint tools :

And I compute back the image, using the Inverse Fourier Transform :

Do you see any differences ? Probably not at all. Buf if you compute again the Fourier Transform of this 'watermarked' image, you get this :

and your watermark appears (symmetrized due to the complex-valued properties of the Fourier Transform), clearly visible.

That may be a nice way of silently signing your images. Maybe I will add an extra filter in G'MIC that does all this automatically.

David.
Wow!
Another restoration example with the same technique :

MOD
That's a cool idea for water marking. Even if an image has been retouched to a greater extent, but bet this watermark could still be viewable; like a spread spectrum idea. Cool David. :)
MOD
Just downloaded 1.3.9 David. Really like the watermark idea. Not sure if you were the first to come up with this technique, but still extremely cool. :)
MOD
I tried the Fourier transform with the locomotive, and I got a result that was even better than yours, David...
This brings me back to the great regret of my life: why didn't I study maths instead of literature?
The watermark filter is a good idea too, despite I'm not keen on everything connected to the protection of private property: it may help eliminating all those ugly visible watermarks...
Well, I would be very interested to see what you get. I think I will post a message on the forum where I've borrowed the locomotive image, so that they could see what we got to achieve with free softwares :)
(Not that I think this is particularly awesome, but maybe interesting somehow).

I think also that watermarking is generally useless, but as many watermarking techniques are based on spectral analysis and Fourier transform, this may be a way to see at least if an image has been watermarked or not.
MOD
Even better, but not marvelous either. I got nearly the same pattern as yours, but I applied also auto levels and used deconvolution (Tikhonov regularization) instead of Octave sharpening.
You can see it here:
(Good news: Orange is not banned on this forum like on Gimp Users).
Francois....
Why not list the steps you used for dummies like me.....maybe to much math (engineering) and not enough literature........
MOD
I did exactly the same as David:
- G'mic - Spectral handling - Fourier transform - direct
- Edit the top rectangle of the image the same way as David. Keep the central rectangle and mask all other whiter lines and dots in black. Hold Shift for straight lines.
- G'mic - Spectral handling - Fourier transform - inverse. You should get an image nearly without print pattern. If not enough, cancel gmic and fine-tune previous step.
- G'mic - Enhancement - anisotropic smoothing. Default settings.
- Auto levels
- G'mic - Enhancement - Deconvolution - Tikhonov regularization. Add some smoothing, because deconvolution is able to recreate artifacts.
But , as I was asked, how did they get from the gmic Fourier transform direct to some image that is being edited....did we apply as a layer or what???

In effect we are using GMIC twice but what happened between.....this is a different way of using GMIC.....
MOD
The image is transformed by Fourier transform so you can easily access the components of the print pattern and mask them, then reconstructed without the pattern, that has been masked. No layer here. The image image data are still present in the grayish transition state you edit, but distributed in a different way, so that the periodic part of the image is isolated and editable. Try with an image with random noise only (scanned negative with silver grains): you will get only the rectangle with the cross, not the outer rectangles.
As for the exact mathematical detailed process, my high school memories are too old to help me understand the details:
en.wikipedia.org/wiki/Fourier_transform
that is why I complained about not having studied math enough...
(David can correct my mistakes).
So he opens an image...
He then Runs GMIC-Fourier transform direct ....
Which closes GMIC leaving the Gray Image....
He then paints as required.....
He then opens and selects GMIC-Fourier transform inverse.....
Now closes GMIC and has a big Gray blob......

Some where the image got lost.......
MOD
If you get a blob, it means you painted over some important image information. Carefully look at David's sample and don't paint the central rectangle.
Yes, the central rectangle contains the low frequency informations, which *must* be preserved (most of the useful image informations are contained here).
I got it......He was just using too much paint brush......
Thanks very much for this filter and this tutorial!

I'm here because someone sent me 50 scans of important (for me) historical photos from an old printed document. He didn't activate the descreening filter on the scanning s/w, so there are moire patterns everywhere. The original document is no longer available...

I _think_ the filter and the method outlined here can be used for descreening. (That is, I guess, descreening=~"removing pattern noise".) But I cannot find anything specific reference to confirm this.

I did an initial test following the method and, indeed, the moiré patterns were greatly diminished. Excellent!

My questions:

1) Is this filter indeed effective for -- and intended to-- do descreening?

2) Is there anything to be added to the tutorial to make it more specific to descreening?

3) If the idea is to eliminate all the non-central patterns seen in the transformed image, could this be further automated by providing a user selection rectangle to choose the central pattern and then the s/w could automatically "paint-out" the non-central patterns? (Or am I completely misunderstanding the point of modifying the transformed data?)

4) Any advice about when in the workflow of cleaning up old photos it is best to apply descreening? First?

TIA,

henry
I tried this tutorial with 1.4.7.3 using the same image and it didn't work. The transform results in one long image, instead of what is shown above. When editing this image and transforming a second time, the image becomes even longer. Height exceeding width to an extreme, and does not resemble anything that results from the tutorial

UPDATE: Changing the image from grayscale to RGB mode seemed to make a difference for me.

Added a softened PhotoIllustration filter touch to blend. Looks fantastic!
Mahvin:

I tried applying the technique to a series of similar photos. For reasons I have not yet understood, some worked exactly in parallel to the tutorial, but in some cases the transformation resulted in an empty frame. The images are grayscale. I tried both RGB and grayscale mode, but this didn't seem to help in those cases that failed. I compared Image Properties for successful and failing cases, but I couldn't see any fundamental differences. Failing cases could have been a bit larger, but seems unlikely to make a difference.

henry
It's highly possible that by my changing the mode to RGB, it falsely led me to think it was what made the difference in obtaining success. When I installed a fourier plug-in from the GIMP Registry, there was a tutorial in the read me that required the changing of image modes from grayscale to RGB, so when I attempted just that using G'MIC, it worked.

Another thing I should mention is that when using Fourier transform inverse, it gives a "preview not available" warning, which can falsely lead someone into thinking the filter isn't working.
Hmmm, there might be some clues from using maximally verbose output and watching the console. (I'm on a Mac and it is easy to do; if you are on a PC, I'm not sure.) Otherwise, I'm wondering if there are some broad assumptions about GIMP operation that I'm missing. I have slowly come to realize, for example, that an instance of G'MIC is tied to a particular file being edited. It isn't applicable to the front-most file. Or so I'm beginning to believe.

I think it is important to be relaxed about the preview. it's a nice feature that may simply not be available for whatever reason.
i believe the filter suppose your image be RGB or RGBA

Should be possible modify the filter to take care to convert automatically in RGB, if the image is in another mode, but not sure if is worth the effort

You are using the gmic plugin version, and almost all gimp tool and plugin works properly only with RGB, to the point that almost all are automatically disabled (and look greyed out in the menu) if the image is in another mode.

So if was for me, the only fix would be add a note in the filter interface suggesting to convert the image in RGB before running the filter
In G'MIC, either mode of "any" image (RGB or grayscale) would display a "preview not available" message when using Fourier Transform (Inverse). So, I am not sure why that is or if it should always be the case.