Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

257 rindas
10 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 - 6. Colour dithering" />
  10. <meta name="Keywords" content="libcaca, ASCII, ASCII ART, console, text mode, ncurses, slang, AAlib, dithering, thresholding" />
  11. <title>Libcaca study - 6. Colour 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="part5.html">Greyscale dithering &lt;&lt;&lt;</a>
  23. </div>
  24. <div style="float: right;">
  25. <a href="part7.html">&gt;&gt;&gt; Photographic mosaics</a>
  26. </div>
  27. <div style="text-align: center;">
  28. <a href="index.html">^^^ Index</a>
  29. </div>
  30. <h2> 6. Colour dithering </h2>
  31. <p> Dithering colour images means dithering three-dimensional elements (RGB
  32. pixels) instead of one-dimensional grey values. It is very complex and
  33. depends on the output media even more than greyscale dithering. </p>
  34. <h3> 6.1. Separate-space dithering </h3>
  35. <p> In some cases it is possible to perform three one-dimensional dithering
  36. operations instead of one three-dimensional one. Consider for instance the
  37. following palette:
  38. </p>
  39. <p style="text-align: center;">
  40. <img src="out/pat6-1-1.png" width="512" height="64"
  41. class="inline" alt="8-colour RGB palette" />
  42. </p>
  43. <p> It is made of the eight possible red/green/blue combinations made of 0
  44. and 1 values: </p>
  45. <div style="text-align: center;">
  46. <table style="margin: auto;">
  47. <tr>
  48. <td><b>Red</b></td>
  49. <td>0</td> <td>0</td> <td>1</td> <td>1</td>
  50. <td>0</td> <td>0</td> <td>1</td> <td>1</td>
  51. </tr> <tr>
  52. <td><b>Green</b></td>
  53. <td>0</td> <td>0</td> <td>0</td> <td>0</td>
  54. <td>1</td> <td>1</td> <td>1</td> <td>1</td>
  55. </tr> <tr>
  56. <td><b>Blue</b></td>
  57. <td>0</td> <td>1</td> <td>0</td> <td>1</td>
  58. <td>0</td> <td>1</td> <td>0</td> <td>1</td>
  59. </tr>
  60. </table>
  61. </div>
  62. <p> One way of dithering an image using this palette is to convert the image
  63. into three greyscale images (separating the red, green and blue channels),
  64. dither each subimage to two colours separately and recombine the images into
  65. three channels. For instance, if at a given pixel the red channel is dithered
  66. to 1 and the green and blue channels are dithered to 0, the final pixel will
  67. be [1 0 0] which is the colour red. </p>
  68. <p> Separate-space dithering works by splitting the image into three red,
  69. green and blue channels. Each of this channel is treated as a greyscale image
  70. that is then dithered to black and white using any dithering method seen
  71. previously. The resulting images are then treated again as three red, green
  72. and blue channels and recombined into the final image: </p>
  73. <p style="text-align: center;">
  74. <img src="fig6-1-7.png" width="704" height="560"
  75. class="matrix" alt="separate-space dithering" />
  76. </p>
  77. <p> Here are the results with serpentine Floyd-Steinberg dithering applied to
  78. each channel. On the left, no colour correction, as The Gimp or Photoshop would
  79. do; on the right, gamma-corrected dithering: </p>
  80. <p style="text-align: center;">
  81. <img src="out/lena6-1-1.png" width="256" height="256"
  82. class="inline" alt="serpentine FS, 8 colours" />
  83. <img src="out/grad6-1-1.png" width="64" height="256"
  84. class="inline" alt="serpentine FS, 8 colours gradient" />
  85. <img src="out/lena6-1-2.png" width="256" height="256"
  86. class="inline" alt="serpentine FS, 8 colours, gamma-corrected" />
  87. <img src="out/grad6-1-2.png" width="64" height="256"
  88. class="inline" alt="serpentine FS, 8 colours, gamma-corrected gradient" />
  89. </p>
  90. <h3> 6.2. Accounting for other dimensions </h3>
  91. <p> The previous palette was suitable for separate-space dithering. Such a
  92. palette is called <b>separable</b> or <b>orthogonal</b>. </p>
  93. <p> Here is a palette that cannot be used in the same way: </p>
  94. <p style="text-align: center;">
  95. <img src="out/pat6-2-2.png" width="512" height="128"
  96. class="inline" alt="8-colour RGB palette" />
  97. </p>
  98. <p> As can be seen, it does not have the [0.5 0.5 0.5] grey colour, or the
  99. [1 0.5 0] orange colour, for instance, despite having other combinations of
  100. 0, 0.5 and 1 values: </p>
  101. <div style="text-align: center;">
  102. <table style="margin: auto; border: 1px;">
  103. <tr>
  104. <td><b>Red</b></td>
  105. <td>0</td> <td>0</td> <td>0.5</td> <td>0.5</td>
  106. <td>0</td> <td>0</td> <td>0.5</td> <td>0.7</td>
  107. <td>0.3</td> <td>0</td> <td>1</td> <td>1</td>
  108. <td>0</td> <td>0</td> <td>1</td> <td>1</td>
  109. </tr> <tr>
  110. <td><b>Green</b></td>
  111. <td>0</td> <td>0</td> <td>0</td> <td>0</td>
  112. <td>0.5</td> <td>0.5</td> <td>0.5</td> <td>0.7</td>
  113. <td>0.3</td> <td>0</td> <td>0</td> <td>0</td>
  114. <td>1</td> <td>1</td> <td>1</td> <td>1</td>
  115. </tr> <tr>
  116. <td><b>Blue</b></td>
  117. <td>0</td> <td>0.5</td> <td>0</td> <td>0.5</td>
  118. <td>0</td> <td>0.5</td> <td>0</td> <td>0.7</td>
  119. <td>0.3</td> <td>1</td> <td>0</td> <td>1</td>
  120. <td>0</td> <td>1</td> <td>0</td> <td>1</td>
  121. </tr>
  122. </table>
  123. </div>
  124. <p> It is no longer possible to compute the closest colour in each colourspace
  125. and combine them into an RGB colour, since that colour might not be available
  126. in the palette. So we need to determine what the “closest colour” means when
  127. dealing with the whole colour spectrum. </p>
  128. <p> The following examples show gamma-corrected Floyd-Steinberg using the
  129. above 16-colour palette and two different definitions of distance: the <b>sum
  130. of absolute differences</b> and the <b>euclidian distance</b>. The sum of
  131. absolute differences performs pretty poorly because it does not penalise wide
  132. disparities: </p>
  133. <p style="text-align: center;">
  134. <img src="out/lena6-2-1.png" width="256" height="256"
  135. class="inline" alt="Floyd-Steinberg, sum of absolute differences" />
  136. <img src="out/grad6-2-1.png" width="64" height="256"
  137. class="inline" alt="Floyd-Steinberg, sum of absolute differences gradient" />
  138. <img src="out/lena6-2-2.png" width="256" height="256"
  139. class="inline" alt="Floyd-Steinberg, euclidian distance" />
  140. <img src="out/grad6-2-2.png" width="64" height="256"
  141. class="inline" alt="Floyd-Steinberg, euclidian distance gradient" />
  142. </p>
  143. <p> Distances can be computed in another space. For instance, the <b>HSV
  144. space</b> allows to give colour variations a smaller influence than brightness
  145. variations simply by changing the HSV cone’s height. On the left is spatial
  146. Floyd-Steinberg using the euclidian distance in an HSV cone of height 1 and
  147. base radius 1. On the right is the same distance within a cone of height 3 and
  148. base radius 1: </p>
  149. <p style="text-align: center;">
  150. <img src="out/lena6-2-3.png" width="256" height="256"
  151. class="inline" alt="Floyd-Steinberg, 1×1 HSV cone" />
  152. <img src="out/grad6-2-3.png" width="64" height="256"
  153. class="inline" alt="Floyd-Steinberg, 1×1 HSV cone gradient" />
  154. <img src="out/lena6-2-4.png" width="256" height="256"
  155. class="inline" alt="Floyd-Steinberg, 3×1 HSV cone" />
  156. <img src="out/grad6-2-4.png" width="64" height="256"
  157. class="inline" alt="Floyd-Steinberg, 3×1 HSV cone gradient" />
  158. </p>
  159. <h3> 6.3. Reducing visual artifacts </h3>
  160. <p> The following patterns show four ways to dither the same colour using
  161. our 8-colour palette: </p>
  162. <ul>
  163. <li> 1/2 black, 3/8 blue, 1/8 white </li>
  164. <li> 1/2 blue, 3/8 black, 1/8 yellow </li>
  165. <li> 3/8 black, 3/8 blue, 1/8 red, 1/8 cyan </li>
  166. <li> 1/2 blue, 1/4 black, 1/8 red, 1/8 green </li>
  167. </ul>
  168. <p> All patterns visually blend to the same shade, but the last one is
  169. the most visually appealing: </p>
  170. <p style="text-align: center;">
  171. <img src="out/pat6-2-1.png" width="320" height="160"
  172. class="inline" alt="3 ways to dither the same colour" />
  173. </p>
  174. <p> Shaked, Arad, Fitzhugh and Sobel introduce the <b>minimum brightness
  175. variation criterion</b> (MBVC), stating that in order to reduce halftone noise,
  176. the halftone set which should be used to render the desired colour should be
  177. the one whose brightness variation is minimal [25]. Similarly, Klassen <i>et
  178. al.</i> suggest the selection of low-contrast colour combiation wherever
  179. possible [24]. </p>
  180. <h3> 6.4. Colour sub-block error diffusion </h3>
  181. <p> Adapting sub-block error diffusion to colour images is almost
  182. straightforward. The major problem is proper weighting in the block-choosing
  183. step. It is a crucial part of the algorithm, and we have yet to find an
  184. efficient method to perform it. </p>
  185. <p> The images below shows the result using our now well-known “lines” tile
  186. list, using respectively the 8-colour palette and the 16-colour palette: </p>
  187. <p style="text-align: center;">
  188. <img src="out/lena6-4-1.png" width="256" height="256"
  189. class="inline" alt="8-colour sub-block error diffusion" />
  190. <img src="out/grad6-4-1.png" width="64" height="256"
  191. class="inline" alt="8-colour sub-block error diffusion gradient" />
  192. <img src="out/lena6-4-2.png" width="256" height="256"
  193. class="inline" alt="16-colour sub-block error diffusion" />
  194. <img src="out/grad6-4-2.png" width="64" height="256"
  195. class="inline" alt="16-colour sub-block error diffusion gradient" />
  196. </p>
  197. <p> Speed is starting to become a problematic issue. A 16-colour palette can
  198. generate 65,536 unique 2×2 blocks. Exhaustive search to determine the best
  199. tile is no longer realistic, and we need to find better ways to find the
  200. best matching block. </p>
  201. <div style="float: left;">
  202. <a href="part5.html">Greyscale dithering &lt;&lt;&lt;</a>
  203. </div>
  204. <div style="float: right;">
  205. <a href="part7.html">&gt;&gt;&gt; Photographic mosaics</a>
  206. </div>
  207. <div style="text-align: center;">
  208. <a href="index.html">^^^ Index</a>
  209. </div>
  210. <?php $rev = '$Id$';
  211. include($_SERVER['DOCUMENT_ROOT'].'/footer.inc'); ?>
  212. </body>
  213. </html>