2

I am trying to replicate "Frequency Synthesis of Landscapes" by P. Bourke in Python. I thought it would be a simple

import numpy as np
from scipy.fft import fft2, ifft2

whitenoise = np.random.uniform(0,1,(256,256,3))
fouriertransformed = np.fft.fftshift(fft2(whitenoise))
pinktransformed = np.reciprocal(fouriertransformed)
pinknoise = ifft2(np.fft.ifftshift(pinktransformed)).real

but it seems to be way more complicated. How can I achieve this, and how can I check that the power really falls of by 1/f**2 in the resulting image?

berndibus
  • 95
  • 10

1 Answers1

3

The problem here is that by computing pinktransformed = np.reciprocal(fouriertransformed) you compute the reciprocal of the amplitudes, but what you actually want is scaling these amplitudes by 1/f**2, so you'd have to replace that line with

pinktransformed = fouriertransformed / f**2

where f is an array that contains the frequencies corresponding to each bin of the fourier transform.

flawr
  • 10,814
  • 3
  • 41
  • 71
  • I am not sure I can follow. What do you mean by "array containing the frequencies" in the case of an image? – berndibus Jan 20 '21 at 16:45
  • Your original image takes a spatial position in the image and translates it to an "energy" which is white noise. You are taking a Fourier transform which means that while the value is still energy, the position in the array corresponds to a spatial "frequency" or a 1/wavelength. These are called wave vectors and correspond to plane waves. You need to divide each position by the magnitude of the wave vector at that position. – Matt Miguel Jan 20 '21 at 17:18
  • As @MattMiguel just explained: The FT gives you an array of amplitudes for some range of frequencies. Ever entry of the vector you get from the fourier transform is an *amplitude* for some given *frequency*. If this fundamental property is not clear I recommend reading an introduction to the continuous and discrete fourier transform. – flawr Jan 20 '21 at 20:13