Changeset 1897 for www


Ignore:
Timestamp:
Nov 6, 2007, 2:33:26 AM (13 years ago)
Author:
Sam Hocevar
Message:
  • Updated result images from the new original Lenna images.
Location:
www/study
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • www/study/index.html

    r1894 r1897  
    5151the <tt><a href="study.py">study.py</a></tt> Python program. Just install
    5252the <tt>python-gd</tt> package on your favourite operating system and
    53 run the script. </p>
     53run the script. The original Lenna images were generated with the
     54<tt><a href="lenna.py">lenna.py</a></tt> program from the original colour
     55512×512 image. </p>
    5456
    5557<h2> 1. Colour quantisation </h2>
     
    152154
    153155<p> But more importantly, if you are reading this document on a computer
    154 screen, you may have noticed that the above 50% pattern was closer to a 0.7
     156screen, you may have noticed that the above 50% pattern was closer to a 0.73
    155157grayscale (left) than to the expected 0.5 value (right). If you are reading
    156158a printed copy, it might be a different matter. </p>
     
    160162       class="inline" alt="introducing gamma" />
    161163</p>
     164
     165<p> Éric Brasseur wrote <a href="http://www.4p8.com/eric.brasseur/gamma.html">a
     166pretty comprehensive essay</a> about why on a computer screen a 50% black and
     167white pattern is equivalent to a gray value of 0.73 instead of 0.5. Conversely,
     168it clearly means that a gray value of 0.5 should not be approached with a 50%
     169black and white dither patterns. </p>
    162170
    163171<!--
  • www/study/study.py

    r1894 r1897  
    55# Tiny image class to make examples short and readable
    66class Image(gd.image):
    7     def __init__(self, args):
     7    def __new__(args, truecolor = False):
    88        gd.gdMaxColors = 256 * 256 * 256
    9         gd.image.__init__(self, args)
     9        if truecolor:
     10            return gd.image.__new__(args, True)
     11        else:
     12            return gd.image.__new__(args)
    1013    def getGray(self, x, y):
    1114        p = self.getPixel((x, y))
    1215        c = self.colorComponents(p)[0] / 255.0
    1316        return c
     17    def getRgb(self, x, y):
     18        p = self.getPixel((x, y))
     19        rgb = self.colorComponents(p)
     20        return [rgb[0] / 255.0, rgb[1] / 255.0, rgb[2] / 255.0]
    1421    def setGray(self, x, y, t):
    1522        p = (int)(t * 255.999)
    1623        c = self.colorResolve((p, p, p))
    1724        self.setPixel((x, y), c)
     25    def setRgb(self, x, y, r, g, b):
     26        r = (int)(r * 255.999)
     27        g = (int)(g * 255.999)
     28        b = (int)(b * 255.999)
     29        c = self.colorResolve((r, g, b))
     30        self.setPixel((x, y), c)
     31
     32# Set our gamma value
     33ga = 2.2
    1834
    1935# Load the 256x256 grayscale Lenna image
     
    123139for y in range(80):
    124140    for x in range(80):
    125         dest.setGray(x, y, math.pow(0.5, 1 / 2.2))
     141        dest.setGray(x, y, math.pow(0.5, 1 / ga))
    126142    for x in range(80, 160):
    127143        c = (x + y) & 1
Note: See TracChangeset for help on using the changeset viewer.