# Changeset 2187Tweet

Ignore:
Timestamp:
Jan 3, 2008, 1:47:48 AM (15 years ago)
Message:
• Greyscale sub-block error diffusion
Location:
www/study
Files:
3 edited

Unmodified
Removed
• ## www/study/index.html

 r2186
• 4.1. Introducing gamma
• 4.2. Gamma correction
• 4.3. Greyscale sub-block error diffusion
• ## www/study/part4.html

 r2181

4.3. Greyscale sub-block error diffusion

Support for greyscale and gamma correction is trivially added to our sub-block error diffusion method. Best-tile choosing is done in contrast space, while error diffusion is done in intensity space.

The first picture uses the full set of possible 2×2 tiles. The second picture only uses the “lines” tiles seen previously.

• ## www/study/study.py

 r2186 for y in range(h): for x in range(w): tmp[y][x] = src.getGray(x, y) tmp[y][x] = Gamma.CtoI(src.getGray(x, y)) dest = Image((w, h)) # Analyse tile list for j in range(ty): for i in range(tx): cur[j][i] = tmp[y * ty + j][x * tx + i] cur[j][i] = Gamma.ItoC(tmp[y * ty + j][x * tx + i]) # Select closest block dist = tx * ty for j in range(ty): for i in range(tx): e = cur[j][i] - tiles[best][j][i] e = Gamma.CtoI(cur[j][i]) - Gamma.CtoI(tiles[best][j][i]) m = propagate[j][i] done = 0. for py in range(len(m)): for px in range(len(m[0])): continue tmp[tmpy][tmpx] += m[py][px] * e done += m[py][px] return dest test42x(grad256bw, ERROR_FSTEIN, True, Gamma.Cto4).save("grad4-2-3.png") test42x(lenna256bw, ERROR_FSTEIN, True, Gamma.Cto4).save("out4-2-3.png") # Output 4.3.1: full 4-colour block error diffusion GREY22 = [] for n in range(4*4*4*4): vals = [0., 0.333, 0.666, 1.] a, b, c, d = n & 3, (n >> 2) & 3, (n >> 4) & 3, (n >> 6) & 3 GREY22.append([[vals[a], vals[b]], [vals[c], vals[d]]]) if chapter(4): test361(grad256bw, GREY22, ERROR_SUBFS22, DIFF_WEIGHED22).save("grad4-3-1.png") test361(lenna256bw, GREY22, ERROR_SUBFS22, DIFF_WEIGHED22).save("out4-3-1.png") # Output 4.3.2: 4-colour block error diffusion with only line tiles GREYLINES22 = [] for n in range(4*4*4*4): vals = [0., 0.333, 0.666, 1.] a, b, c, d = n & 3, (n >> 2) & 3, (n >> 4) & 3, (n >> 6) & 3 if (a != b or c != d) and (a != c or b != d): continue GREYLINES22.append([[vals[a], vals[b]], [vals[c], vals[d]]]) if chapter(4): test361(grad256bw, GREYLINES22, ERROR_SUBFS22, DIFF_WEIGHED22).save("grad4-3-2.png") test361(lenna256bw, GREYLINES22, ERROR_SUBFS22, DIFF_WEIGHED22).save("out4-3-2.png") ##############################################################################
Note: See TracChangeset for help on using the changeset viewer.