Changeset 2028


Ignore:
Timestamp:
Nov 19, 2007, 1:40:41 AM (13 years ago)
Author:
Sam Hocevar
Message:
  • Wrote a few lines about error minimisation in thresholding methods.
Location:
www/study
Files:
12 added
2 edited

Legend:

Unmodified
Added
Removed
  • www/study/part1.html

    r2027 r2028  
    9696       class="inline" alt="3-colour threshold gradient" />
    9797  <img src="out1-2-2.png" width="256" height="256"
    98        class="inline" alt="4-colour threshold" />
     98       class="inline" alt="5-colour threshold" />
    9999  <img src="grad1-2-2.png" width="32" height="256"
    100        class="inline" alt="4-colour threshold gradient" />
     100       class="inline" alt="5-colour threshold gradient" />
    101101</p>
     102
     103<p> Using this method, shades of gray are evenly used. However, the global
     104error is far from optimal, as the following graphs show: </p>
     105
     106<p style="text-align: center;">
     107  <img src="fig1-2-1.png" width="256" height="256"
     108       alt="mean error 0.138" />
     109  <img src="fig1-2-2.png" width="256" height="256"
     110       alt="mean error 0.075" />
     111</p>
     112
     113<p> The following thresholding method minimises the error, at the cost of
     114underusage of pure black and white colours: </p>
     115
     116<p style="text-align: center;">
     117  <img src="out1-2-3.png" width="256" height="256"
     118       class="inline" alt="3-colour threshold, minimal error" />
     119  <img src="grad1-2-3.png" width="32" height="256"
     120       class="inline" alt="3-colour threshold gradient, minimal error" />
     121  <img src="out1-2-4.png" width="256" height="256"
     122       class="inline" alt="5-colour threshold, minimal error" />
     123  <img src="grad1-2-4.png" width="32" height="256"
     124       class="inline" alt="5-colour threshold gradient, minimal error" />
     125</p>
     126
     127<p style="text-align: center;">
     128  <img src="fig1-2-3.png" width="256" height="256"
     129       alt="mean error 0.125" />
     130  <img src="fig1-2-4.png" width="256" height="256"
     131       alt="mean error 0.0625" />
     132</p>
     133
     134<p> This is a perfect example of a situation where colour accuracy does not
     135help achieving a better result. </p>
    102136
    103137<div style="float: right;">
  • www/study/study.py

    r2013 r2028  
    8484    (w, h) = src.size()
    8585    dest = Image((w, h))
    86     p = -0.0001 + colors
    8786    q = colors - 1
     87    p = -.00001 + colors
    8888    for y in range(h):
    8989        for x in range(w):
     
    9797test12x(gradient256bw, 3).save("grad1-2-1.png")
    9898test12x(gradient256bw, 5).save("grad1-2-2.png")
     99
     100# Output 1.2.3: 3-colour threshold, minimal error
     101# Output 1.2.4: 5-colour threshold, minimal error
     102def test12y(src, colors):
     103    (w, h) = src.size()
     104    dest = Image((w, h))
     105    q = colors - 1
     106    p = -.00001 + colors - 1
     107    for y in range(h):
     108        for x in range(w):
     109            c = src.getGray(x, y)
     110            c = math.floor((c + 0.5 / p) * p) / q
     111            dest.setGray(x, y, c)
     112    return dest
     113
     114test12y(lenna256bw, 3).save("out1-2-3.png")
     115test12y(lenna256bw, 5).save("out1-2-4.png")
     116test12y(gradient256bw, 3).save("grad1-2-3.png")
     117test12y(gradient256bw, 5).save("grad1-2-4.png")
    99118
    100119##############################################################################
     
    270289test242(gradient256bw).save("grad2-4-2.png")
    271290
    272 # Output 2.4.3: 4×4 Bayer dithering with gaussian perturbation
     291# Output 2.4.3: 4x4 Bayer dithering with gaussian perturbation
    273292def test243(src, mat):
    274293    random.seed(0)
Note: See TracChangeset for help on using the changeset viewer.