- Timestamp:
- Nov 6, 2007, 2:33:26 AM (15 years ago)
- Location:
- www/study
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
www/study/index.html
r1894 r1897 51 51 the <tt><a href="study.py">study.py</a></tt> Python program. Just install 52 52 the <tt>python-gd</tt> package on your favourite operating system and 53 run the script. </p> 53 run 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 55 512×512 image. </p> 54 56 55 57 <h2> 1. Colour quantisation </h2> … … 152 154 153 155 <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 156 screen, you may have noticed that the above 50% pattern was closer to a 0.73 155 157 grayscale (left) than to the expected 0.5 value (right). If you are reading 156 158 a printed copy, it might be a different matter. </p> … … 160 162 class="inline" alt="introducing gamma" /> 161 163 </p> 164 165 <p> Éric Brasseur wrote <a href="http://www.4p8.com/eric.brasseur/gamma.html">a 166 pretty comprehensive essay</a> about why on a computer screen a 50% black and 167 white pattern is equivalent to a gray value of 0.73 instead of 0.5. Conversely, 168 it clearly means that a gray value of 0.5 should not be approached with a 50% 169 black and white dither patterns. </p> 162 170 163 171 <!-- -
www/study/study.py
r1894 r1897 5 5 # Tiny image class to make examples short and readable 6 6 class Image(gd.image): 7 def __ init__(self, args):7 def __new__(args, truecolor = False): 8 8 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) 10 13 def getGray(self, x, y): 11 14 p = self.getPixel((x, y)) 12 15 c = self.colorComponents(p)[0] / 255.0 13 16 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] 14 21 def setGray(self, x, y, t): 15 22 p = (int)(t * 255.999) 16 23 c = self.colorResolve((p, p, p)) 17 24 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 33 ga = 2.2 18 34 19 35 # Load the 256x256 grayscale Lenna image … … 123 139 for y in range(80): 124 140 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)) 126 142 for x in range(80, 160): 127 143 c = (x + y) & 1
Note: See TracChangeset
for help on using the changeset viewer.