I'd like to generate a 2D image of arbitrary size containing randomly generated pink noise. Wikipedia suggests that the 2D generalization of pink noise will have energy that falls off as 1/f^2. I found some code on the MATLAB File Exchange that computes a 1D pink noise vector. But I don't know how to properly generalize it to two dimensions -- I'm not very familiar with the fft, and my naive attempt below produces complex vectors when I compute the ifft.
function pink = pinkNoiseImage(nrow,ncol)
rnrow = 2.^(ceil(log2(nrow)));
rncol = 2.^(ceil(log2(ncol)));
r = randn(rnrow,rncol);
rf = fft(r);
rnup = rnrow/2+1;
cnup = rncol/2+1;
frf = kron(1./sqrt(1:cnup),1./sqrt(1:rnup)');
rf(1:rnup,1:cnup) = rf(1:rnup,1:cnup).*frf;
rf(rnup+1:rnrow,1:cnup) = real(frf(rnrow/2:-1:2,1:cnup))-1i*imag(frf(rnrow/2:-1:2,1:cnup));
rf(1:rnup,cnup+1:rncol) = real(frf(1:rnup,rncol/2:-1:2))-1i*imag(frf(1:rnup,rncol/2:-1:2));
rf(rnup+1:rnrow,cnup+1:rncol) = real(frf(rnrow/2:-1:2,rncol/2:-1:2))-1i*imag(frf(rnrow/2:-1:2,rncol/2:-1:2));
pink = ifft(rf);
How can I generate a 2D matrix containing pink noise?