Ignore:
Timestamp:
Nov 11, 2007, 1:27:43 PM (13 years ago)
Author:
Sam Hocevar
Message:
  • Started error diffusion part. Added Floyd-Steinberg.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • www/study/study.py

    r1930 r1931  
    163163
    164164# Output 7: 4x4 Bayer dithering
     165# Output 8: 4x4 cluster dot
     166# Output 9: 5x3 line dithering
    165167def test4(src, mat, name):
    166168    (w, h) = src.size()
     
    195197test4(lenna256bw, mat, "out009.png")
    196198test4(gradient256bw, mat, "grad009.png")
     199
     200# Output 10: standard Floyd-Steinberg
     201def test5(src, name):
     202    (w, h) = src.size()
     203    dest = Image((w, h))
     204    ep = [0.] * (w + 2)
     205    for y in range(h):
     206        en = [0.] * (w + 2)
     207        #print 'ep:', ep
     208        #print 'en:', en
     209        ex = 0
     210        for x in range(w):
     211            c = src.getGray(x, y) + ex + ep[x + 1]
     212            d = c > 0.5
     213            dest.setGray(x, y, d)
     214            error = c - d
     215            ex = error * 7. / 16.
     216            en[x] += error * 3. / 16.
     217            en[x + 1] += error * 5. / 16.
     218            en[x + 2] += error * 1. / 16.
     219        ep = en
     220    dest.writePng(name)
     221
     222test5(lenna256bw, "out010.png")
     223test5(gradient256bw, "grad010.png")
    197224
    198225##############################################################################
Note: See TracChangeset for help on using the changeset viewer.