Function iadither

Synopse

Ordered Dither.

  • g = iadither(f, n)
    • g: Image.
    • f: Image. input image
    • n: Image. dimension of the base matrix
01. from numpy import *
02. 
03. def iadither(f, n):
04.     import ia636
05. 
06.     H,W = f.shape
07.     D = 1.*array([[0,2],[3,1]])
08.     d = 1*D
09.     k = int(log(n/2.)/log(2.))
10.     for i in range(k):
11.         u = ones(D.shape)
12.         d1 = 4*D + d[0,0]*u
13.         d2 = 4*D + d[0,1]*u
14.         d3 = 4*D + d[1,0]*u
15.         d4 = 4*D + d[1,1]*u
16.         D = concatenate((concatenate((d1,d2),1), concatenate((d3,d4),1)))
17.     D = (255*abs(D/D.max())).astype('uint8')
18.     g = tile(D, array(f.shape)//array(D.shape) + array([1,1]))[:H,:W]
19.     g = ia636.ianormalize(f,[0,255]) >= g
20.     return g

Description

Ordered dither (Bayer 1973).

Examples

Example 1

01. from ia636 import iadither
02. from ia636 import iaramp
03. from ia636 import iaresize
04. 
05. f1 = iaramp([20,150], 256, [0,255])
06. f2 = adreadgray('woodlog.pgm')[:150,:150]
07. f = concatenate((f1, f2))
08. adshow(f)
09. g_4 = iadither(f, 4)
10. g_32 = iadither(f, 32)
11. adshow(g_4)
12. adshow(g_32)