问题描述
我想生成包含随机生成的粉红噪声的任意大小的2D图像。 粉红噪声的二维泛化将使能量下降为1 / f ^ 2 。我找到了上的一些代码,用于计算1D粉红噪声向量。但是我不知道如何将它正确地推广到两个维度 - 我对fft不是很熟悉,当我计算ifft时,我下面的天真尝试会产生复杂的向量。
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);
如何生成包含粉红噪声的2D矩阵?
How can I generate a 2D matrix containing pink noise?
推荐答案
首先,不要总是相信维基百科告诉你的内容。或者,仔细阅读,因为粉红噪声的定义不是二维的一对一。
其次,您可以使用以下生成 1 / f ^ beta
空间噪声,具有正常的错误分布。阅读该文件的文档中的更多内容。
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.
这篇关于在Matlab中创建粉红噪声图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!