# Changeset 2193

Ignore:
Timestamp:
01/12/08 23:51:23 (5 years ago)
Message:
• Fixed bilevel sub-block error diffusion example: it was gamma-correcting the image in chapter 3.
Location:
www/study
Files:
2 edited

Unmodified
Added
Removed
• ## www/study/part3.html

 r2190

Riemersma dithering parses the image following a plane-filling Hilbert curve and only propagates the error of the last q pixels, weighing it with an exponential rule. The method is interesting and pixels, weighting it with an exponential rule. The method is interesting and inventive, unfortunately the results are disappointing: structural artifacts are worse than with other error diffusion methods (shown here with q =

The results on the vertical gradient indicate poor block-choosing. In order to improve it, we introduce a modified, weighed intra-block error order to improve it, we introduce a modified, weighted intra-block error distribution matrix, still based on the original Floyd-Steinberg matrix:

× class="math" alt="weighted 2×2 matrix" /> = class="math" alt="weighted 2×2 propagation matrix" />

class="inline" alt="weighted full 2×2 block Floyd-Steinberg" /> class="inline" alt="weighted full 2×2 block Floyd-Steinberg gradient" />

• subpixel a’s error is harder to compensate than subpixel d’s because its immediate neighbours are already in the block being processed, so we weigh the sub-block matching in order to being processed, so we weight the sub-block matching in order to prioritise pixel a’s matching.
• ## www/study/study.py

 r2190 TILES22, DIFF_EVEN22, True, True).save("out3-5-4.png") DIFF_WEIGHED22 = \ DIFF_WEIGHTED22 = \ [[51./128, 33./128], [25./128, 19./128]] test351(grad256bw, ERROR_FSTEIN, TILES22, DIFF_WEIGHED22, True, False).save("grad3-5-5.png") TILES22, DIFF_WEIGHTED22, True, False).save("grad3-5-5.png") test351(lenna256bw, ERROR_FSTEIN, TILES22, DIFF_WEIGHED22, True, False).save("out3-5-5.png") TILES22, DIFF_WEIGHTED22, True, False).save("out3-5-5.png") # Output 3.6.1: sub-block error diffusion def test361(src, tiles, propagate, diff): (w, h) = src.size() def test361(src, tiles, propagate, diff, gamma): (w, h) = src.size() # Gamma correction if gamma: ctoi = Gamma.CtoI itoc = Gamma.ItoC else: ctoi = itoc = lambda x : x # Propagating the error to a temporary buffer is becoming more and # more complicated. We decide to use an intermediate matrix instead. for y in range(h): for x in range(w): tmp[y][x] = Gamma.CtoI(src.getGray(x, y)) tmp[y][x] = 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] = Gamma.ItoC(tmp[y * ty + j][x * tx + i]) cur[j][i] = 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 = Gamma.CtoI(cur[j][i]) - Gamma.CtoI(tiles[best][j][i]) e = ctoi(cur[j][i]) - ctoi(tiles[best][j][i]) m = propagate[j][i] for py in range(len(m)): if chapter(3): test361(grad256bw, TILES22, ERROR_SUBFS22, DIFF_WEIGHED22).save("grad3-6-1.png") ERROR_SUBFS22, DIFF_WEIGHTED22, False).save("grad3-6-1.png") test361(lenna256bw, TILES22, ERROR_SUBFS22, DIFF_WEIGHED22).save("out3-6-1.png") ERROR_SUBFS22, DIFF_WEIGHTED22, False).save("out3-6-1.png") test361(grad256bw, LINES22, ERROR_SUBFS22, DIFF_WEIGHED22).save("grad3-6-2.png") ERROR_SUBFS22, DIFF_WEIGHTED22, False).save("grad3-6-2.png") test361(lenna256bw, LINES22, ERROR_SUBFS22, DIFF_WEIGHED22).save("out3-6-2.png") ERROR_SUBFS22, DIFF_WEIGHTED22, False).save("out3-6-2.png") def colorise(val): TILES33.append(mat) DIFF_WEIGHED33 = \ DIFF_WEIGHTED33 = \ [[15./64, 10./64,  6./64], [10./64,  6./64,  4./64], if chapter(3): test361(grad256bw, TILES33, ERROR_SUBFS33, DIFF_WEIGHED33).save("grad3-6-3.png") ERROR_SUBFS33, DIFF_WEIGHTED33, False).save("grad3-6-3.png") test361(lenna256bw, TILES33, ERROR_SUBFS33, DIFF_WEIGHED33).save("out3-6-3.png") ERROR_SUBFS33, DIFF_WEIGHTED33, False).save("out3-6-3.png") test361(grad256bw, SQUARES33, ERROR_SUBFS33, DIFF_WEIGHED33).save("grad3-6-4.png") ERROR_SUBFS33, DIFF_WEIGHTED33, False).save("grad3-6-4.png") test361(lenna256bw, SQUARES33, ERROR_SUBFS33, DIFF_WEIGHED33).save("out3-6-4.png") ERROR_SUBFS33, DIFF_WEIGHTED33, False).save("out3-6-4.png") # XXX: hack, we modify ERROR_SUBFS33 because it's so much more convenient if chapter(4): test361(grad256bw, GREY22, ERROR_SUBFS22, DIFF_WEIGHED22).save("grad4-3-1.png") ERROR_SUBFS22, DIFF_WEIGHTED22, True).save("grad4-3-1.png") test361(lenna256bw, GREY22, ERROR_SUBFS22, DIFF_WEIGHED22).save("out4-3-1.png") ERROR_SUBFS22, DIFF_WEIGHTED22, True).save("out4-3-1.png") # Output 4.3.2: 4-colour block error diffusion with only line tiles if chapter(4): test361(grad256bw, GREYLINES22, ERROR_SUBFS22, DIFF_WEIGHED22).save("grad4-3-2.png") ERROR_SUBFS22, DIFF_WEIGHTED22, True).save("grad4-3-2.png") test361(lenna256bw, GREYLINES22, ERROR_SUBFS22, DIFF_WEIGHED22).save("out4-3-2.png") ERROR_SUBFS22, DIFF_WEIGHTED22, True).save("out4-3-2.png") ##############################################################################
Note: See TracChangeset for help on using the changeset viewer.