Fourier transform improvement - sho

(Morgan Hardwood) #1


The Fourier transform is very useful in dealing with pattern noise, however the way it currently works makes it quite difficult to use on 2018-sized photos - typically 20 to 40 megapixels.

Currently when you run it over an image it produces a long vertical strip. The top part is the useful bit, the other parts are not. A photo 4000x6000 pixels in size ends up being 4000x36000! With 8GB RAM, any subsequent work on this is likely to crash G’MIC, and GIMP operations on it are very slow.


The improvement I suggest is as follows:

  1. The Fourier transform filter in G’MIC gets an “Only foo” checkbox, where “foo” is the proper name of the top part (what are the names for the top part, and for the noisy rest? “top part” is good enough for me). When enabled, the transformed image contains only the top part - 4000x6000.
  2. To inversely transform it back into a photo, the filter requires the original layer. When you start the “inverse” transform, it uses the “top part” the user edited, and does a “direct” transform of the original layer for the remaining info, then merges the two to come up with a photo.

Would that be possible?


The first component is called the magnitude and the second the phase. The magnitude’s log form is called the spectrum, which is what you see here.

The dimensions of the spectrum and phase should be equal to the input image; in your case, 4000x6000 each. I think what G’MIC is doing here is (1) appending the two and (2) representing them in a form that is manageable in the 0-255 range of the earlier versions of GIMP. That is why the phase is so long.

Personally, I would do Image —FFT→ 2 layers → edit spectrum —IFFT→ Modified Image. If we do your suggested method, then there would be two extra operations.

(Michael Turcotte) #3

I was wondering this myself. I was restoring some of my old photobooks and FFT is great for removing the dot pattern (forgot the name if it now) and restoring the details. I would have to scan at 1200 to 2400 dpi to avoid the moire and would end up with huge files. 16G of ram and I would shut everything down and only run GIMP/G’MIC, save the FFT as a tiff just in case, try to do some work, before everything crashed.

Would it be possible to save the phase in a temporary file and then read in only the needed parts during the IFFT?

(Morgan Hardwood) #4

If it would be possible to represent the phase as a separate layer of the same size as the original image, then that would also be a good solution. Better two layers at 24 megapixels than one layer at 144 megapixels.


Definitely. I never use this filter in GIMP for these reasons. Since this is a built-in command, I will ping @David_Tschumperle to make the adjustments.


In the meantime, I have an experimental pattern removal filter as described in this post:

(David Tschumperlé) #7

The FFT transform in G’MIC has been indeed designed for GIMP 2.8, where only 8bits/channels images were managed. As a FFT requires float-valued pixels for the storage, the filter outputs 2x3x8bits images (so 24bits fixed point precision to store floats, both for the phase and magnitude of the FFT) appending those 6 images along the y-axis.

Now that GIMP 2.10 (and Krita) supports 32bits float-valued images, I guess this filter could be recoded to output 2 layers magnitude/phase, in 32bits float-valued mode
(but this won’t work for other modes).

(David Tschumperlé) #8

I’ve done some work this morning to improve the FFT filter in the plug-in.
It will be available for next major version 2.3.0 of G’MIC:

  • Support high-bit depths images (direct/inverse transforms are more precise in 16 or 32bits/channels modes).
  • Use less memory in all cases. Only one instance of the magnitude and phase images are stored, not 4 versions each as before.
  • Allow the user to choose the Magnitude/phase type : single layer (appended along the horizontal/vertical axis), or two layers (one for each).

I guess this should solve all your concerns :slight_smile:

(Morgan Hardwood) #9

Thank you @David_Tschumperle