Changeset 2193


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

Legend:

Unmodified
Added
Removed
  • www/study/part3.html

    r2190 r2193  
    263263<p> <b>Riemersma dithering</b> parses the image following a plane-filling 
    264264<b>Hilbert curve</b> and only propagates the error of the last <i>q</i> 
    265 pixels, weighing it with an exponential rule. The method is interesting and 
     265pixels, weighting it with an exponential rule. The method is interesting and 
    266266inventive, unfortunately the results are disappointing: structural artifacts 
    267267are worse than with other error diffusion methods (shown here with <i>q = 
     
    492492 
    493493<p> The results on the vertical gradient indicate poor block-choosing. In 
    494 order to improve it, we introduce a modified, weighed intra-block error 
     494order to improve it, we introduce a modified, weighted intra-block error 
    495495distribution matrix, still based on the original Floyd-Steinberg matrix: </p> 
    496496 
     
    500500  × 
    501501  <img src="fig3-5-5b.png" width="81" height="81" 
    502        class="math" alt="weighed 2×2 matrix" /> 
     502       class="math" alt="weighted 2×2 matrix" /> 
    503503  = 
    504504  <img src="fig3-5-5.png" width="241" height="161" 
    505        class="math" alt="weighed 2×2 propagation matrix" /> 
     505       class="math" alt="weighted 2×2 propagation matrix" /> 
    506506</p> 
    507507 
     
    510510<p style="text-align: center;"> 
    511511  <img src="out3-5-5.png" width="256" height="256" 
    512        class="inline" alt="weighed full 2×2 block Floyd-Steinberg" /> 
     512       class="inline" alt="weighted full 2×2 block Floyd-Steinberg" /> 
    513513  <img src="grad3-5-5.png" width="32" height="256" 
    514        class="inline" alt="weighed full 2×2 block Floyd-Steinberg gradient" /> 
     514       class="inline" alt="weighted full 2×2 block Floyd-Steinberg gradient" /> 
    515515</p> 
    516516 
     
    528528  <li> subpixel <b>a</b>’s error is harder to compensate than subpixel 
    529529       <b>d</b>’s because its immediate neighbours are already in the block 
    530        being processed, so we weigh the sub-block matching in order to 
     530       being processed, so we weight the sub-block matching in order to 
    531531       prioritise pixel <b>a</b>’s matching. </li> 
    532532</ul> 
  • www/study/study.py

    r2190 r2193  
    15401540            TILES22, DIFF_EVEN22, True, True).save("out3-5-4.png") 
    15411541 
    1542 DIFF_WEIGHED22 = \ 
     1542DIFF_WEIGHTED22 = \ 
    15431543    [[51./128, 33./128], 
    15441544     [25./128, 19./128]] 
     
    15551555 
    15561556    test351(grad256bw, ERROR_FSTEIN, 
    1557             TILES22, DIFF_WEIGHED22, True, False).save("grad3-5-5.png") 
     1557            TILES22, DIFF_WEIGHTED22, True, False).save("grad3-5-5.png") 
    15581558    test351(lenna256bw, ERROR_FSTEIN, 
    1559             TILES22, DIFF_WEIGHED22, True, False).save("out3-5-5.png") 
     1559            TILES22, DIFF_WEIGHTED22, True, False).save("out3-5-5.png") 
    15601560 
    15611561# Output 3.6.1: sub-block error diffusion 
    1562 def test361(src, tiles, propagate, diff): 
    1563     (w, h) = src.size() 
     1562def test361(src, tiles, propagate, diff, gamma): 
     1563    (w, h) = src.size() 
     1564    # Gamma correction 
     1565    if gamma: 
     1566        ctoi = Gamma.CtoI 
     1567        itoc = Gamma.ItoC 
     1568    else: 
     1569        ctoi = itoc = lambda x : x 
    15641570    # Propagating the error to a temporary buffer is becoming more and 
    15651571    # more complicated. We decide to use an intermediate matrix instead. 
     
    15671573    for y in range(h): 
    15681574        for x in range(w): 
    1569             tmp[y][x] = Gamma.CtoI(src.getGray(x, y)) 
     1575            tmp[y][x] = ctoi(src.getGray(x, y)) 
    15701576    dest = Image((w, h)) 
    15711577    # Analyse tile list 
     
    15811587            for j in range(ty): 
    15821588                for i in range(tx): 
    1583                     cur[j][i] = Gamma.ItoC(tmp[y * ty + j][x * tx + i]) 
     1589                    cur[j][i] = itoc(tmp[y * ty + j][x * tx + i]) 
    15841590            # Select closest block 
    15851591            dist = tx * ty 
     
    16011607            for j in range(ty): 
    16021608                for i in range(tx): 
    1603                     e = Gamma.CtoI(cur[j][i]) - Gamma.CtoI(tiles[best][j][i]) 
     1609                    e = ctoi(cur[j][i]) - ctoi(tiles[best][j][i]) 
    16041610                    m = propagate[j][i] 
    16051611                    for py in range(len(m)): 
     
    16331639if chapter(3): 
    16341640    test361(grad256bw, TILES22, 
    1635             ERROR_SUBFS22, DIFF_WEIGHED22).save("grad3-6-1.png") 
     1641            ERROR_SUBFS22, DIFF_WEIGHTED22, False).save("grad3-6-1.png") 
    16361642    test361(lenna256bw, TILES22, 
    1637             ERROR_SUBFS22, DIFF_WEIGHED22).save("out3-6-1.png") 
     1643            ERROR_SUBFS22, DIFF_WEIGHTED22, False).save("out3-6-1.png") 
    16381644 
    16391645    test361(grad256bw, LINES22, 
    1640             ERROR_SUBFS22, DIFF_WEIGHED22).save("grad3-6-2.png") 
     1646            ERROR_SUBFS22, DIFF_WEIGHTED22, False).save("grad3-6-2.png") 
    16411647    test361(lenna256bw, LINES22, 
    1642             ERROR_SUBFS22, DIFF_WEIGHED22).save("out3-6-2.png") 
     1648            ERROR_SUBFS22, DIFF_WEIGHTED22, False).save("out3-6-2.png") 
    16431649 
    16441650    def colorise(val): 
     
    17141720    TILES33.append(mat) 
    17151721 
    1716 DIFF_WEIGHED33 = \ 
     1722DIFF_WEIGHTED33 = \ 
    17171723    [[15./64, 10./64,  6./64], 
    17181724     [10./64,  6./64,  4./64], 
     
    17211727if chapter(3): 
    17221728    test361(grad256bw, TILES33, 
    1723             ERROR_SUBFS33, DIFF_WEIGHED33).save("grad3-6-3.png") 
     1729            ERROR_SUBFS33, DIFF_WEIGHTED33, False).save("grad3-6-3.png") 
    17241730    test361(lenna256bw, TILES33, 
    1725             ERROR_SUBFS33, DIFF_WEIGHED33).save("out3-6-3.png") 
     1731            ERROR_SUBFS33, DIFF_WEIGHTED33, False).save("out3-6-3.png") 
    17261732    test361(grad256bw, SQUARES33, 
    1727             ERROR_SUBFS33, DIFF_WEIGHED33).save("grad3-6-4.png") 
     1733            ERROR_SUBFS33, DIFF_WEIGHTED33, False).save("grad3-6-4.png") 
    17281734    test361(lenna256bw, SQUARES33, 
    1729             ERROR_SUBFS33, DIFF_WEIGHED33).save("out3-6-4.png") 
     1735            ERROR_SUBFS33, DIFF_WEIGHTED33, False).save("out3-6-4.png") 
    17301736 
    17311737    # XXX: hack, we modify ERROR_SUBFS33 because it's so much more convenient 
     
    20262032if chapter(4): 
    20272033    test361(grad256bw, GREY22, 
    2028             ERROR_SUBFS22, DIFF_WEIGHED22).save("grad4-3-1.png") 
     2034            ERROR_SUBFS22, DIFF_WEIGHTED22, True).save("grad4-3-1.png") 
    20292035    test361(lenna256bw, GREY22, 
    2030             ERROR_SUBFS22, DIFF_WEIGHED22).save("out4-3-1.png") 
     2036            ERROR_SUBFS22, DIFF_WEIGHTED22, True).save("out4-3-1.png") 
    20312037 
    20322038# Output 4.3.2: 4-colour block error diffusion with only line tiles 
     
    20412047if chapter(4): 
    20422048    test361(grad256bw, GREYLINES22, 
    2043             ERROR_SUBFS22, DIFF_WEIGHED22).save("grad4-3-2.png") 
     2049            ERROR_SUBFS22, DIFF_WEIGHTED22, True).save("grad4-3-2.png") 
    20442050    test361(lenna256bw, GREYLINES22, 
    2045             ERROR_SUBFS22, DIFF_WEIGHED22).save("out4-3-2.png") 
     2051            ERROR_SUBFS22, DIFF_WEIGHTED22, True).save("out4-3-2.png") 
    20462052 
    20472053############################################################################## 
Note: See TracChangeset for help on using the changeset viewer.