Changeset 2010


Ignore:
Timestamp:
Nov 17, 2007, 4:02:51 PM (13 years ago)
Author:
Sam Hocevar
Message:
  • Preparing random matrix halftoning.
Location:
www/study
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • www/study/part2.html

    r2006 r2010  
    178178</p>
    179179
     180<!--
     181<p> Blah blah: </p>
     182
     183<p style="text-align: center;">
     184  <img src="out2-4-3.png" width="256" height="256"
     185       class="inline" alt="random Bayer matrix dithering" />
     186  <img src="grad2-4-3.png" width="32" height="256"
     187       class="inline" alt="random Bayer matrix dithering gradient" />
     188</p>
     189-->
     190
    180191<div style="float: left;">
    181192   <a href="part1.html">Colour quantisation &lt;&lt;&lt;</a>
  • www/study/study.py

    r2007 r2010  
    231231test241(gradient256bw).save("grad2-4-1.png")
    232232
    233 # Output 2.4.2: random dithering
     233# Output 2.4.2: gaussian random dithering
    234234def test242(src):
    235235    random.seed(0)
     
    245245test242(lenna256bw).save("out2-4-2.png")
    246246test242(gradient256bw).save("grad2-4-2.png")
     247
     248# Output 2.4.3: random dither matrices
     249def test243(src, mat):
     250    random.seed(0)
     251    (w, h) = src.size()
     252    dest = Image((w, h))
     253    dx = len(mat[0])
     254    dy = len(mat)
     255    randmat = [[(int)(random.random() * 16) for x in range(w / dx)] for y in range(h / dy)]
     256    for y in range(h):
     257        for x in range(w):
     258            c = src.getGray(x, y)
     259            val = (mat[y % dy][x % dx] + randmat[y / dy][x / dx]) % (dx * dy)
     260            threshold = (1. + val) / (dx * dy + 1)
     261            c = c > threshold
     262            dest.setGray(x, y, c)
     263    return dest
     264
     265test243(lenna256bw, DITHER_BAYER44).save("out2-4-3.png")
     266test243(gradient256bw, DITHER_BAYER44).save("grad2-4-3.png")
    247267
    248268##############################################################################
Note: See TracChangeset for help on using the changeset viewer.