File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -575,3 +575,51 @@ def pink_noise(size, fract_dim=1):
575575 res = res / np .sqrt (var (res ))
576576
577577 return res
578+
579+
580+ def blue_noise (size , fract_dim = 1 ):
581+ '''make blue noise
582+
583+ Make a matrix of specified size containing blue noise with power
584+ spectral density of the form: f^(5-2*`fract_dim`). Image variance
585+ is normalized to 1.0.
586+
587+ Note that the power spectrum here is the reciprocal of the pink
588+ noises's power spectrum
589+
590+ Arguments
591+ ---------
592+ size : `int` or `tuple`
593+ if an int, we assume the image should be of dimensions `(size,
594+ size)`. if a tuple, must be a 2-tuple of ints specifying the
595+ dimensions
596+ fract_dim : `float`
597+ the fractal dimension of the blue noise
598+
599+ Returns
600+ -------
601+ res : `np.array`
602+ the blue noise
603+
604+ '''
605+ if not hasattr (size , '__iter__' ):
606+ size = (size , size )
607+
608+ res = np .random .randn (size [0 ], size [1 ])
609+ fres = np .fft .fft2 (res )
610+
611+ exp = 2.5 - fract_dim
612+ ctr = np .ceil ((res .shape + np .ones (2 ))/ 2. )
613+ sh = np .fft .ifftshift (polar_radius (size , exp , ctr ))
614+ sh [0 , 0 ] = 1 # DC term
615+
616+ fres = sh * fres
617+ fres = np .fft .ifft2 (fres )
618+
619+ if abs (fres .imag ).max () > 1e-10 :
620+ print ('Symmetry error in creating fractal' )
621+ else :
622+ res = np .real (fres )
623+ res = res / np .sqrt (var (res ))
624+
625+ return res
You can’t perform that action at this time.
0 commit comments