Changeset 2187


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

Legend:

Unmodified
Added
Removed
  • www/study/index.html

    r2186 r2187  
    112112      <li> 4.1. Introducing gamma </li>
    113113      <li> 4.2. Gamma correction </li>
     114      <li> 4.3. Greyscale sub-block error diffusion </li>
    114115    </ul>
    115116  </li>
  • www/study/part4.html

    r2181 r2187  
    168168</p>
    169169
     170<h3> 4.3. Greyscale sub-block error diffusion </h3>
     171
     172<p> Support for greyscale and gamma correction is trivially added to our
     173sub-block error diffusion method. Best-tile choosing is done in contrast
     174space, while error diffusion is done in intensity space. </p>
     175
     176<p> The first picture uses the full set of possible 2×2 tiles. The second
     177picture only uses the “lines” tiles seen previously. </p>
     178
     179<p style="text-align: center;">
     180  <img src="out4-3-1.png" width="256" height="256"
     181       class="inline" alt="sub-block FS, full 4-gray tiles" />
     182  <img src="grad4-3-1.png" width="32" height="256"
     183       class="inline" alt="sub-block FS, full 4-gray tiles gradient" />
     184  <img src="out4-3-2.png" width="256" height="256"
     185       class="inline" alt="sub-block FS, lines 4-gray tiles" />
     186  <img src="grad4-3-2.png" width="32" height="256"
     187       class="inline" alt="sub-block FS, lines 4-gray tiles gradient" />
     188</p>
     189
    170190<div style="float: left;">
    171191   <a href="part3.html">Error diffusion &lt;&lt;&lt;</a>
  • www/study/study.py

    r2186 r2187  
    15671567    for y in range(h):
    15681568        for x in range(w):
    1569             tmp[y][x] = src.getGray(x, y)
     1569            tmp[y][x] = Gamma.CtoI(src.getGray(x, y))
    15701570    dest = Image((w, h))
    15711571    # Analyse tile list
     
    15811581            for j in range(ty):
    15821582                for i in range(tx):
    1583                     cur[j][i] = tmp[y * ty + j][x * tx + i]
     1583                    cur[j][i] = Gamma.ItoC(tmp[y * ty + j][x * tx + i])
    15841584            # Select closest block
    15851585            dist = tx * ty
     
    16011601            for j in range(ty):
    16021602                for i in range(tx):
    1603                     e = cur[j][i] - tiles[best][j][i]
     1603                    e = Gamma.CtoI(cur[j][i]) - Gamma.CtoI(tiles[best][j][i])
    16041604                    m = propagate[j][i]
    1605                     done = 0.
    16061605                    for py in range(len(m)):
    16071606                        for px in range(len(m[0])):
     
    16161615                                continue
    16171616                            tmp[tmpy][tmpx] += m[py][px] * e
    1618                             done += m[py][px]
    16191617    return dest
    16201618
     
    18811879    test42x(grad256bw, ERROR_FSTEIN, True, Gamma.Cto4).save("grad4-2-3.png")
    18821880    test42x(lenna256bw, ERROR_FSTEIN, True, Gamma.Cto4).save("out4-2-3.png")
     1881
     1882# Output 4.3.1: full 4-colour block error diffusion
     1883GREY22 = []
     1884for n in range(4*4*4*4):
     1885    vals = [0., 0.333, 0.666, 1.]
     1886    a, b, c, d = n & 3, (n >> 2) & 3, (n >> 4) & 3, (n >> 6) & 3
     1887    GREY22.append([[vals[a], vals[b]], [vals[c], vals[d]]])
     1888
     1889if chapter(4):
     1890    test361(grad256bw, GREY22,
     1891            ERROR_SUBFS22, DIFF_WEIGHED22).save("grad4-3-1.png")
     1892    test361(lenna256bw, GREY22,
     1893            ERROR_SUBFS22, DIFF_WEIGHED22).save("out4-3-1.png")
     1894
     1895# Output 4.3.2: 4-colour block error diffusion with only line tiles
     1896GREYLINES22 = []
     1897for n in range(4*4*4*4):
     1898    vals = [0., 0.333, 0.666, 1.]
     1899    a, b, c, d = n & 3, (n >> 2) & 3, (n >> 4) & 3, (n >> 6) & 3
     1900    if (a != b or c != d) and (a != c or b != d):
     1901        continue
     1902    GREYLINES22.append([[vals[a], vals[b]], [vals[c], vals[d]]])
     1903
     1904if chapter(4):
     1905    test361(grad256bw, GREYLINES22,
     1906            ERROR_SUBFS22, DIFF_WEIGHED22).save("grad4-3-2.png")
     1907    test361(lenna256bw, GREYLINES22,
     1908            ERROR_SUBFS22, DIFF_WEIGHED22).save("out4-3-2.png")
    18831909
    18841910##############################################################################
Note: See TracChangeset for help on using the changeset viewer.