Changeset 1898 for www


Ignore:
Timestamp:
Nov 6, 2007, 2:33:27 AM (13 years ago)
Author:
Sam Hocevar
Message:
  • First gamma-aware halftoning (with the ugly patterns).
Location:
www/study
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • www/study/index.html

    r1897 r1898  
    169169black and white dither patterns. </p>
    170170
     171<p> So, instead of using 25%, 50% and 75% patterns (which give non-uniform
     172gray values of 0.53, 0.73 and 0.88), let’s try with 6.25%, 25% and 50%
     173patterns (which give the better spread gray values of 0.28, 0.53 and 0.73).
     174As you can see, the result is visually less appealing. But the important
     175part here is that color accuracy is higher:  </p>
     176
     177<p style="text-align: center;">
     178  <img src="out007.png" width="256" height="256"
     179       class="inline" alt="gamma-aware 6.25%, 25% and 50% halftoning" />
     180</p>
     181
    171182<!--
    172183<p> Here is the application to Lenna, using the 0-0.2, 0.2-0.4, 0.4-0.6,
  • www/study/study.py

    r1897 r1898  
    3737(w, h) = src.size()
    3838
    39 # Test 1: 50% threshold
     39# Output 1: 50% threshold
    4040dest = Image((w, h))
    4141for y in range(h):
     
    4646del dest
    4747
    48 # Test 2: 40% threshold
     48# Output 2: 40% threshold
    4949dest = Image((w, h))
    5050for y in range(h):
     
    5555del dest
    5656
    57 # Test 3: 60% threshold
     57# Output 3: 60% threshold
    5858dest = Image((w, h))
    5959for y in range(h):
     
    6464del dest
    6565
    66 # Test 4: 3-colour threshold
     66# Output 4: 3-colour threshold
    6767dest = Image((w, h))
    6868for y in range(h):
     
    7373dest.writePng("out004.png")
    7474
    75 # Test 5: 4-colour threshold
     75# Output 5: 4-colour threshold
    7676dest = Image((w, h))
    7777for y in range(h):
     
    103103dest.writePng("pat002.png")
    104104
    105 # Test 6: 20/40/60/80% threshold with 25/50/75% halftone patterns inbetween:
     105# Output 6: 20/40/60/80% threshold with 25/50/75% halftone patterns inbetween:
    106106dest = Image((w, h))
    107107for y in range(h):
     
    147147dest.writePng("pat004.png")
    148148
     149# Output 6: gamma-aware 20/40/60/80% threshold:
     150dest = Image((w, h))
     151for y in range(h):
     152    for x in range(w):
     153        c = src.getGray(x, y)
     154        if c < 0.2:
     155            c = 0.
     156        elif c < 0.4:
     157            c = (((x + y) & 3) == 1) and ((y & 3) == 1)
     158        elif c < 0.6:
     159            c = ((x + y) & 1) and (y & 1)
     160        elif c < 0.8:
     161            c = (x + y) & 1
     162        else:
     163            c = 1.
     164        dest.setGray(x, y, c)
     165dest.writePng("out007.png")
     166
    149167##############################################################################
    150168# Only temporary cruft below this
     
    152170import sys
    153171sys.exit(0)
    154 
    155 # Test 4: 33/66% threshold with 50% halftone pattern inbetween:
    156 dest = Image((w, h))
    157 for y in range(h):
    158     for x in range(w):
    159         c = src.getGray(x, y)
    160         if c < 0.333:
    161             c = 0.
    162         elif c < 0.666:
    163             c = (x + y) & 1
    164         else:
    165             c = 1.
    166         dest.setGray(x, y, c)
    167 dest.writePng("test4.png")
    168172
    169173# Create a dot-matrix pattern
Note: See TracChangeset for help on using the changeset viewer.