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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.