Changeset 1932 for www


Ignore:
Timestamp:
Nov 11, 2007, 1:27:45 PM (13 years ago)
Author:
Sam Hocevar
Message:
  • Serpentine Floyd-Steinberg.
Location:
www/study
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • www/study/index.html

    r1931 r1932  
    248248
    249249<p> The idea behind error diffusion is to compute the error caused by
    250 thresholding a given pixel and propagate it to neighbour pixels. </p>
     250thresholding a given pixel and propagate it to neighbour pixels to
     251compensate for the brightness loss. It is based upon the assumption that
     252a slightly out-of-place pixel is better than a completely missing pixel. </p>
    251253
    252254<h3> 3.1. Floyd-Steinberg error diffusion </h3>
     
    269271       class="inline" alt="Floyd-Steinberg error diffusion" />
    270272  <img src="grad010.png" width="32" height="256"
     273       class="inline" alt="Floyd-Steinberg error diffusion gradient" />
     274</p>
     275
     276<p> This is a variant called “serpentine Floyd-Steinberg” that parses every
     277odd line right to left. The results is very close to the original
     278Floyd-Steinberg, but avoids artifacts in some corner cases: </p>
     279
     280<p style="text-align: center;">
     281  <img src="out011.png" width="256" height="256"
     282       class="inline" alt="Floyd-Steinberg error diffusion" />
     283  <img src="grad011.png" width="32" height="256"
    271284       class="inline" alt="Floyd-Steinberg error diffusion gradient" />
    272285</p>
  • www/study/study.py

    r1931 r1932  
    205205    for y in range(h):
    206206        en = [0.] * (w + 2)
    207         #print 'ep:', ep
    208         #print 'en:', en
    209207        ex = 0
    210208        for x in range(w):
     
    222220test5(lenna256bw, "out010.png")
    223221test5(gradient256bw, "grad010.png")
     222
     223# Output 11: serpentine Floyd-Steinberg
     224def test6(src, name):
     225    (w, h) = src.size()
     226    dest = Image((w, h))
     227    ep = [0.] * (w + 2)
     228    for z in range(h / 2):
     229        en = [0.] * (w + 2)
     230        ex = 0
     231        y = z * 2
     232        for x in range(w):
     233            c = src.getGray(x, y) + ex + ep[x + 1]
     234            d = c > 0.5
     235            dest.setGray(x, y, d)
     236            error = c - d
     237            ex = error * 7. / 16.
     238            en[x] += error * 3. / 16.
     239            en[x + 1] += error * 5. / 16.
     240            en[x + 2] += error * 1. / 16.
     241        ep = en
     242        en = [0.] * (w + 2)
     243        ex = 0
     244        y = z * 2 + 1
     245        for x in range(w - 1, -1, -1):
     246            c = src.getGray(x, y) + ex + ep[x + 1]
     247            d = c > 0.5
     248            dest.setGray(x, y, d)
     249            error = c - d
     250            ex = error * 7. / 16.
     251            en[x] += error * 1. / 16.
     252            en[x + 1] += error * 5. / 16.
     253            en[x + 2] += error * 3. / 16.
     254        ep = en
     255    dest.writePng(name)
     256
     257test6(lenna256bw, "out011.png")
     258test6(gradient256bw, "grad011.png")
    224259
    225260##############################################################################
Note: See TracChangeset for help on using the changeset viewer.