function D = bayerMatrix(n) % bayerMatrix(n) % Generates a Bayer dither matrix of size n x n. The % resulting matrix is normalized by the number of matrix % elements. % % Note: only n = 2^i generates meaningful dither matrices. All % non-powers of two will be floored to the next lowest power % two. % % Rick Anthony % 6/23/93 D2 = [0 2; 3 1]; D = D2; k = 4; n = floor(log(n)/log(2)); for i = 2:n, D = [4*D+D2(1,1) 4*D+D2(1,2); 4*D+D2(2,1) 4*D+D2(2,2)]; k = k*4; end D = 1/k*(D+0.5);