def iacolormap(type='gray'): from ianormalize import ianormalize from iacolormap import iacolormap if type == 'gray': ct = transpose(resize(arange(256), (3,256))) elif type == 'hsv': h = arange(256)/255. s = ones(256) v = ones(256) ct = ianormalize(reshape(map(colorsys.hsv_to_rgb, h, s, v), (256,3)), [0,255]).astype(uint8) elif type == 'hot': n = int(3./8*256) r = concatenate((arange(1,n+1)/n, ones(256-n)), 1)[:,newaxis] g = concatenate((zeros(n), arange(1,n+1)/n, ones(256-2*n)), 1)[:,newaxis] b = concatenate((zeros(2*n), arange(1,256-2*n+1)/(256-2*n)), 1)[:,newaxis] ct = ianormalize(concatenate((r,g,b), 1), [0,255]).astype(uint8) elif type == 'cool': r = (arange(256)/255.)[:,newaxis] ct = ianormalize(concatenate((r, 1-r, ones((256,1))), 1), [0,255]).astype(uint8) elif type == 'bone': ct = ianormalize((7*iacolormap('gray') + iacolormap('hot')[:,::-1]) / 8., [0,255]).astype(uint8) elif type == 'copper': ct = ianormalize(min(1, dot(iacolormap('gray')/255., [[1.25,0,0],[0,0.7812,0],[0,0,0.4975]])), [0,255]).astype(uint8) elif type == 'pink': ct = ianormalize(sqrt((2*iacolormap('gray') + iacolormap('hot')) / 3), [0,255]).astype(uint8) else: ct = zeros((256,3)) return ct
def iacolormap(type="gray"): from ianormalize import ianormalize from iacolormap import iacolormap if type == "gray": ct = transpose(resize(arange(256), (3, 256))) elif type == "hsv": h = arange(256) / 255.0 s = ones(256) v = ones(256) ct = ianormalize(reshape(map(colorsys.hsv_to_rgb, h, s, v), (256, 3)), [0, 255]).astype(uint8) elif type == "hot": n = int(3.0 / 8 * 256) r = concatenate((arange(1, n + 1) / n, ones(256 - n)), 1)[:, newaxis] g = concatenate((zeros(n), arange(1, n + 1) / n, ones(256 - 2 * n)), 1)[:, newaxis] b = concatenate((zeros(2 * n), arange(1, 256 - 2 * n + 1) / (256 - 2 * n)), 1)[:, newaxis] ct = ianormalize(concatenate((r, g, b), 1), [0, 255]).astype(uint8) elif type == "cool": r = (arange(256) / 255.0)[:, newaxis] ct = ianormalize(concatenate((r, 1 - r, ones((256, 1))), 1), [0, 255]).astype(uint8) elif type == "bone": ct = ianormalize((7 * iacolormap("gray") + iacolormap("hot")[:, ::-1]) / 8.0, [0, 255]).astype(uint8) elif type == "copper": ct = ianormalize( min(1, dot(iacolormap("gray") / 255.0, [[1.25, 0, 0], [0, 0.7812, 0], [0, 0, 0.4975]])), [0, 255] ).astype(uint8) elif type == "pink": ct = ianormalize(sqrt((2 * iacolormap("gray") + iacolormap("hot")) / 3), [0, 255]).astype(uint8) else: ct = zeros((256, 3)) return ct
def iadither(f, n): from ianormalize import ianormalize D = 1. * array([[0, 2], [3, 1]]) d = 1 * D k = log(n / 2.) / log(2.) for i in range(k): u = ones(D.shape) d1 = 4 * D + d[0, 0] * u d2 = 4 * D + d[0, 1] * u d3 = 4 * D + d[1, 0] * u d4 = 4 * D + d[1, 1] * u D = concatenate((concatenate((d1, d2), 1), concatenate((d3, d4), 1))) D = 255 * abs(D / max(ravel(D))) g = tile(D.astype('b'), f.shape) g = ianormalize(f, [0, 255]) >= g return g
def iadither(f, n): from ianormalize import ianormalize D = 1.*array([[0,2],[3,1]]) d = 1*D k = log(n/2.)/log(2.) for i in range(k): u = ones(D.shape) d1 = 4*D + d[0,0]*u d2 = 4*D + d[0,1]*u d3 = 4*D + d[1,0]*u d4 = 4*D + d[1,1]*u D = concatenate((concatenate((d1,d2),1), concatenate((d3,d4),1))) D = 255*abs(D/max(ravel(D))) g = tile(D.astype('b'), f.shape) g = ianormalize(f,[0,255]) >= g return g
def iafloyd(f): from ianormalize import ianormalize f_ = 1.*ianormalize(f, [0,255]) g = zeros(f_.shape) for i in range(f_.shape[0]): for j in range(f_.shape[1]): if f_[i,j] >= 128: g[i,j] = 255 erro = f_[i,j] - g[i,j] if j < f_.shape[1]-1: f_[i,j+1] = f_[i,j+1] + 7*erro/16. if i < f_.shape[0]-1 and j > 0: f_[i+1,j-1] = f_[i+1,j-1] + 3*erro/16. if i < f_.shape[0]-1: f_[i+1,j] = f_[i+1,j] + 5*erro/16. if i < f_.shape[0]-1 and j < f_.shape[1]-1: f_[i+1,j+1] = f_[i+1,j+1] + erro/16. g = g > 0 return g
def iafloyd(f): from ianormalize import ianormalize f_ = 1. * ianormalize(f, [0, 255]) g = zeros(f_.shape) for i in range(f_.shape[0]): for j in range(f_.shape[1]): if f_[i, j] >= 128: g[i, j] = 255 erro = f_[i, j] - g[i, j] if j < f_.shape[1] - 1: f_[i, j + 1] = f_[i, j + 1] + 7 * erro / 16. if i < f_.shape[0] - 1 and j > 0: f_[i + 1, j - 1] = f_[i + 1, j - 1] + 3 * erro / 16. if i < f_.shape[0] - 1: f_[i + 1, j] = f_[i + 1, j] + 5 * erro / 16. if i < f_.shape[0] - 1 and j < f_.shape[1] - 1: f_[i + 1, j + 1] = f_[i + 1, j + 1] + erro / 16. g = g > 0 return g