Changeset 1938 for www


Ignore:
Timestamp:
Nov 11, 2007, 10:16:17 PM (13 years ago)
Author:
Sam Hocevar
Message:
  • Sierra dithering.
  • Atkinson dithering.
Location:
www/study
Files:
8 added
2 edited

Legend:

Unmodified
Added
Removed
  • www/study/index.html

    r1937 r1938  
    360360</p>
    361361
     362<p> <b>Sierra dithering</b> is a variation of Stucki that is slightly faster
     363because it propagates to fewer pixels: </p>
     364
     365<p style="text-align: center;">
     366  <img src="fig3-2-5.png" width="200" height="160"
     367       style="margin-right: 30px;" alt="Sierra" />
     368  <img src="out3-2-5.png" width="256" height="256"
     369       class="inline" alt="Sierra error diffusion" />
     370  <img src="grad3-2-5.png" width="32" height="256"
     371       class="inline" alt="Sierra error diffusion gradient" />
     372</p>
     373
     374<p> <b>Atkinson dithering</b> only propagates 75% of the error, leading to a
     375loss of contrast around black and white areas, but better contrast in the
     376midtones: </p>
     377
     378<p style="text-align: center;">
     379  <img src="fig3-2-6.png" width="160" height="160"
     380       style="margin-right: 30px;" alt="Atkinson" />
     381  <img src="out3-2-6.png" width="256" height="256"
     382       class="inline" alt="Atkinson error diffusion" />
     383  <img src="grad3-2-6.png" width="32" height="256"
     384       class="inline" alt="Atkinson error diffusion gradient" />
     385</p>
     386
    362387<!--
    363388<p> There are countless other error diffusion techniques. However it appears
  • www/study/study.py

    r1937 r1938  
    407407test324(lenna256bw, "out3-2-4.png")
    408408test324(gradient256bw, "grad3-2-4.png")
     409
     410# Output 3-2-5: Sierra
     411# TODO: merge with Jarvis-Judice-Ninke, Stucki etc.
     412def test325(src, name):
     413    (w, h) = src.size()
     414    dest = Image((w, h))
     415    ep = [0.] * (w + 4)
     416    ey = [0.] * (w + 4)
     417    for y in range(h):
     418        ey2 = [0.] * (w + 4)
     419        ex = 0
     420        ex2 = 0
     421        for x in range(w):
     422            c = src.getGray(x, y) + ex + ep[x + 2]
     423            d = c > 0.5
     424            dest.setGray(x, y, d)
     425            error = c - d
     426            ex = ex2 + error * 5. / 32.
     427            ex2 = error * 3. / 32.
     428            ey[x] += error * 2. / 32.
     429            ey[x + 1] += error * 4. / 32.
     430            ey[x + 2] += error * 5. / 32.
     431            ey[x + 3] += error * 4. / 32.
     432            ey[x + 4] += error * 2. / 32.
     433            ey2[x + 1] += error * 2. / 32.
     434            ey2[x + 2] += error * 3. / 32.
     435            ey2[x + 3] += error * 2. / 32.
     436        ep = ey
     437        ey = ey2
     438    dest.writePng(name)
     439
     440test325(lenna256bw, "out3-2-5.png")
     441test325(gradient256bw, "grad3-2-5.png")
     442
     443# Output 3-2-6: Atkinson
     444# TODO: merge with Jarvis-Judice-Ninke, Stucki etc.
     445def test326(src, name):
     446    (w, h) = src.size()
     447    dest = Image((w, h))
     448    ep = [0.] * (w + 2)
     449    ey = [0.] * (w + 2)
     450    for y in range(h):
     451        ey2 = [0.] * (w + 2)
     452        ex = 0
     453        ex2 = 0
     454        for x in range(w):
     455            c = src.getGray(x, y) + ex + ep[x + 1]
     456            d = c > 0.5
     457            dest.setGray(x, y, d)
     458            error = c - d
     459            ex = ex2 + error / 8.
     460            ex2 = error / 8.
     461            ey[x] += error / 8.
     462            ey[x + 1] += error / 8.
     463            ey[x + 2] += error / 8.
     464            ey2[x + 1] += error / 8.
     465        ep = ey
     466        ey = ey2
     467    dest.writePng(name)
     468
     469test326(lenna256bw, "out3-2-6.png")
     470test326(gradient256bw, "grad3-2-6.png")
    409471
    410472##############################################################################
Note: See TracChangeset for help on using the changeset viewer.