mkFract.m 843 B

123456789101112131415161718192021222324252627282930313233343536
  1. % IM = mkFract(SIZE, FRACT_DIM)
  2. %
  3. % Make a matrix of dimensions SIZE (a [Y X] 2-vector, or a scalar)
  4. % containing fractal (pink) noise with power spectral density of the
  5. % form: 1/f^(5-2*FRACT_DIM). Image variance is normalized to 1.0.
  6. % FRACT_DIM defaults to 1.0
  7. % Eero Simoncelli, 6/96.
  8. %% TODO: Verify that this matches Mandelbrot defn of fractal dimension.
  9. %% Make this more efficient!
  10. function res = mkFract(dims, fract_dim)
  11. if (exist('fract_dim') ~= 1)
  12. fract_dim = 1.0;
  13. end
  14. res = randn(dims);
  15. fres = fft2(res);
  16. sz = size(res);
  17. ctr = ceil((sz+1)./2);
  18. shape = ifftshift(mkR(sz, -(2.5-fract_dim), ctr));
  19. shape(1,1) = 1; %%DC term
  20. fres = shape .* fres;
  21. fres = ifft2(fres);
  22. if (max(max(abs(imag(fres)))) > 1e-10)
  23. error('Symmetry error in creating fractal');
  24. else
  25. res = real(fres);
  26. res = res / sqrt(var2(res));
  27. end