No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

215 líneas
9.2 KiB

  1. <?php header("Content-Type: text/html; charset=utf-8"); ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <meta name="GENERATOR" content="vim" />
  8. <meta name="Author" content="sam@zoy.org (Sam Hocevar)" />
  9. <meta name="Description" content="Libcaca study - 5. Greyscale dithering" />
  10. <meta name="Keywords" content="libcaca, ASCII, ASCII ART, console, text mode, ncurses, slang, AAlib, dithering, thresholding" />
  11. <title>Libcaca study - 5. Greyscale dithering</title>
  12. <link rel="icon" type="image/x-icon" href="/favicon.ico" />
  13. <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
  14. <link rel="stylesheet" type="text/css" href="/main.css" />
  15. </head>
  16. <body>
  17. <?php include($_SERVER["DOCUMENT_ROOT"]."/header.inc"); ?>
  18. <p> <span style="color: #aa0000; font-weight: bold;">Warning</span>: this
  19. document is still work in progress. Feel free to send comments but do not
  20. consider it final material. </p>
  21. <div style="float: left;">
  22. <a href="part4.html">Model-based dithering &lt;&lt;&lt;</a>
  23. </div>
  24. <div style="float: right;">
  25. <a href="part6.html">&gt;&gt;&gt; Colour dithering</a>
  26. </div>
  27. <div style="text-align: center;">
  28. <a href="index.html">^^^ Index</a>
  29. </div>
  30. <h2> 5. Greyscale dithering </h2>
  31. <p> At first sight, generalising dithering to three grey scales seems pretty
  32. straightforward: just add grey 0.5 in the middle of the palette and dither
  33. pixels in the [0, 0.5] range with black and grey, and pixels in the [0.5, 1]
  34. range with grey and white. Here are two different results with 8×8 Bayer
  35. ordered dithering and with serpentine Floyd-Steinberg error diffusion: </p>
  36. <p style="text-align: center;">
  37. <img src="out/lena5-0-1.png" width="256" height="256"
  38. class="inline" alt="8×8 Bayer ordered dithering, 3 colours" />
  39. <img src="out/grad5-0-1.png" width="32" height="256"
  40. class="inline" alt="8×8 Bayer ordered dithering gradient, 3 colours" />
  41. <img src="out/lena5-0-2.png" width="256" height="256"
  42. class="inline" alt="serpentine FS error diffusion, 3 colours" />
  43. <img src="out/grad5-0-2.png" width="32" height="256"
  44. class="inline" alt="serpentine FS error diffusion gradient, 3 colours" />
  45. </p>
  46. <p> These are pretty much the images that imaging software such as The Gimp
  47. would give (using “positioned” and “Floyd-Steinberg” dithering modes). </p>
  48. <p> Unfortunately the result is not as good as expected: the white pattern
  49. on Lena’s cheeks is visually disturbing, and there is a lot of 0.5 grey in
  50. the image. Also, the whole image looks darker than with pure black-and-white
  51. dithering, but these previous dithering results looked a lot brighter than
  52. the original image anyway. </p>
  53. <p> All these issues have to do with the output media’s <b>gamma</b>. </p>
  54. <h3> 5.1. Introducing gamma </h3>
  55. <p> If you are reading this document on a computer screen, you may have
  56. noticed that the black and white 50% pattern was closer to a 0.73 greyscale
  57. (left) than to the intuitively expected 0.5 value (right). If you are reading
  58. a printed copy, it might be a different matter. </p>
  59. <p style="text-align: center;">
  60. <img src="out/pat5-1-1.png" width="240" height="80"
  61. class="inline" alt="introducing gamma" />
  62. </p>
  63. <p> The mapping linking greyscale steps to intensities is called <b>gamma
  64. correction</b>. An approximate law for gamma correction is given as
  65. <i>I = v<small><sup>γ</sup></small></i> where <i>v</i> is the coded colour
  66. value (between 0 and 1), <i>I</i> is the perceived colour intensity (between
  67. 0% and 100%) and <i>γ</i> is the gamma. A pattern made of even-numbered
  68. 0%-intensity pixels and 100%-intensity pixels has an intensity of 50% by
  69. definition. But the corresponding greyscale depends on the gamma value. </p>
  70. <p> Most modern computer systems use the sRGB gamma model close to the law
  71. with <i>γ = 2.2</i>. As can be seen, it is highly non-linear: </p>
  72. <p style="text-align: center;">
  73. <img src="fig5-1-1.png" width="460" height="256" alt="introducing gamma" />
  74. </p>
  75. <p> Éric Brasseur wrote <a
  76. href="http://www.4p8.com/eric.brasseur/gamma.html">a pretty comprehensive
  77. essay</a> [16] about why on a computer screen a 50% black and white pattern
  78. should be scaled down to a grey value of 0.73 instead of 0.5 and how major
  79. computer graphics software totally misses the point. Conversely, it clearly
  80. means that a grey value of 0.5 should not be emulated with a 50% dither
  81. pattern. </p>
  82. <p> The following figure shows the gamma curve for the naïve three-colour
  83. greyscale gradient we saw above (red curve) compared to the two-colour
  84. gradient (blue curve). Two major observations can be made: the new curve is
  85. far closer to a perfect, linear gradient, but there is a singularity in the
  86. middle of the curve, meaning a break in the gradient’s smoothness. </p>
  87. <p style="text-align: center;">
  88. <img src="fig5-1-2.png" width="460" height="256" alt="3-colour gamma" />
  89. </p>
  90. <p> There are three possible ways to reduce the singularity and make the
  91. gradient smoother and/or closer to the original colours: </p>
  92. <ul>
  93. <li> Choose a different middle grey value, for instance choosing grey 0.73
  94. will cancel the singularity and match the two-colour gradients we have
  95. been using so far. This is not always possible if the output palette
  96. is fixed. </li>
  97. <li> Don’t place the grey value at the middle of the gradient, for instance
  98. a value of around 25% intensity will again match the previous two-colour
  99. gradients. </li>
  100. <li> <b>Gamma-correct</b> input pixels before assigning them an output
  101. value. This ensures that the resulting gradient is perfectly linear
  102. and has no singularity.
  103. </li>
  104. </ul>
  105. <h3> 5.2. Gamma correction </h3>
  106. <p> Gamma correction consists in converting pixel values into intensity values
  107. before performing operations on them, then reconverting them to pixel values
  108. before displaying them. The exact same algorithms can be used, they just
  109. operate on slightly different data. </p>
  110. <p style="text-align: center;">
  111. <img src="fig5-1-3.png" width="460" height="256" alt="3-colour gamma coorection" />
  112. </p>
  113. <p> Here are the results of gamma-correcting input pixels before doing
  114. any computation on them, then using serpentine Floyd-Steinberg error
  115. diffusion: </p>
  116. <p style="text-align: center;">
  117. <img src="out/lena5-2-1.png" width="256" height="256"
  118. class="inline" alt="serpentine FS, 2 colours, gamma-corrected" />
  119. <img src="out/grad5-2-1.png" width="32" height="256"
  120. class="inline" alt="serpentine FS, 2 colours, gamma-corrected gradient" />
  121. <img src="out/lena5-2-2.png" width="256" height="256"
  122. class="inline" alt="serpentine FS, 3 colours, gamma-corrected" />
  123. <img src="out/grad5-2-2.png" width="32" height="256"
  124. class="inline" alt="serpentine FS, 3 colours, gamma-corrected gradient" />
  125. </p>
  126. <p> Two-colour dithering is not visually satisfying: dark areas lack much
  127. detail because the gamma curve is very flat at low intensities. However,
  128. the result itself is far more accurate that previously. The problem, while
  129. still visible, is even less important with three-colour dithering: the image
  130. on the right is superior to what The Gimp or Adobe Photoshop are able to
  131. come up with. </p>
  132. <p> Finally, this is gamma-corrected 4-colour dithering: </p>
  133. <p style="text-align: center;">
  134. <img src="out/lena5-2-3.png" width="256" height="256"
  135. class="inline" alt="serpentine FS, 4 colours, gamma-corrected" />
  136. <img src="out/grad5-2-3.png" width="32" height="256"
  137. class="inline" alt="serpentine FS, 4 colours, gamma-corrected gradient" />
  138. </p>
  139. <h3> 5.3. Greyscale sub-block error diffusion </h3>
  140. <p> Support for greyscale and gamma correction is trivially added to our
  141. sub-block error diffusion method. Best-tile choosing is done in contrast
  142. space, while error diffusion is done in intensity space. </p>
  143. <p> The following picture uses all possible 4-greyscale 2×2 tiles. The
  144. output quality is very close to what standard, pixel-per-pixel error diffusion
  145. achieves: </p>
  146. <p style="text-align: center;">
  147. <img src="out/lena5-3-1.png" width="256" height="256"
  148. class="inline" alt="sub-block FS, full 4-grey tiles" />
  149. <img src="out/grad5-3-1.png" width="32" height="256"
  150. class="inline" alt="sub-block FS, full 4-grey tiles gradient" />
  151. </p>
  152. <p> And finally, this picture only uses 4-greyscale combinations of the
  153. “lines” tiles seen previously: </p>
  154. <p style="text-align: center;">
  155. <img src="fig5-3-1.png" width="307" height="253"
  156. class="matrix" alt="list of 4-grey 2×2 pixel blocks" />
  157. <img src="out/lena5-3-2.png" width="256" height="256"
  158. class="inline" alt="sub-block FS, lines 4-grey tiles" />
  159. <img src="out/grad5-3-2.png" width="32" height="256"
  160. class="inline" alt="sub-block FS, lines 4-grey tiles gradient" />
  161. </p>
  162. <div style="float: left;">
  163. <a href="part4.html">Model-based dithering &lt;&lt;&lt;</a>
  164. </div>
  165. <div style="float: right;">
  166. <a href="part6.html">&gt;&gt;&gt; Colour dithering</a>
  167. </div>
  168. <div style="text-align: center;">
  169. <a href="index.html">^^^ Index</a>
  170. </div>
  171. <?php $rev = '$Id$';
  172. include($_SERVER['DOCUMENT_ROOT'].'/footer.inc'); ?>
  173. </body>
  174. </html>