Create pink noise image in Matlab

℡╲_俬逩灬. 提交于 2019-12-11 03:58:09

问题


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?


回答1:


First, don't always believe what Wikipedia tells you. Or, read carefully, because the definition of Pink noise is not one to one for 2D. Second, you can use the following FEX file to generate 1/f^beta spatial noise, with a normal error distribution. Read more in the documentation of that file.



来源:https://stackoverflow.com/questions/19367474/create-pink-noise-image-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!