Nov 16, 2007, 2:34:25 AM (13 years ago)
Sam Hocevar
  • More about gamma correction. Fixed graphs.
1 edited


  • www/study/part4.html

    r1956 r1972  
    3333<h2> 4. Grayscale dithering </h2>
    35 <p> Generalising dithering to more than two colours is straightforward in the
    36 grayscale palette. Here are the results with 4×4 Bayer ordered dithering and
    37 with Floyd-Steinberg error diffusion: </p>
     35<p> At first sight, generalising dithering to three gray scales seems pretty
     36straightforward: just add gray 0.5 in the middle of the palette and dither
     37pixels in the [0, 0.5] range with black and gray, and pixels in the [0.5, 1]
     38range with gray and white. Here are two different results with 4×4 Bayer
     39ordered dithering and with Floyd-Steinberg error diffusion: </p>
    3941<p style="text-align: center;">
    50 <p> Unfortunately the result is not as good as expected. The white pattern
    51 on Lenna’s cheeks is visually disturbing, and the whole image looks darker
    52 than with pure black-and-white dithering. But then, the previous dithering
    53 results looked a lot brighter than the original image. This is due to the
    54 output media’s <b>gamma</b>. </p>
     52<p> These are pretty much the images that imaging software such as The Gimp
     53would give (using “positioned” and “Floyd-Steinberg” dithering modes). </p>
     55<p> Unfortunately the result is not as good as expected: the white pattern
     56on Lenna’s cheeks is visually disturbing, and there is a lot of 0.5 gray in
     57the image. Also, the whole image looks darker than with pure black-and-white
     58dithering, but these previous dithering results looked a lot brighter than
     59the original image anyway. </p>
     61<p> All these issues have to do with the output media’s <b>gamma</b>. </p>
    5663<h3> 4.1. Introducing gamma </h3>
    7077<i>I = v<small><sup>γ</sup></small></i> where <i>v</i> is the coded colour
    7178value (between 0 and 1), <i>I</i> is the perceived colour intensity (between
    72 0 and 1) and <i>γ</i> is the gamma. Most modern computer systems use the
    73 sRGB gamma model close to the law with <i>γ = 2.2</i>. As can be seen, it is
    74 highly non-linear: </p>
     790% and 100%) and <i>γ</i> is the gamma. A pattern made of even-numbered
     800%-intensity pixels and 100%-intensity pixels has an intensity of 50% by
     81definition. But the corresponding grayscale</p>
     83<p> Most modern computer systems use the sRGB gamma model close to the law
     84with <i>γ = 2.2</i>. As can be seen, it is highly non-linear: </p>
    7686<p style="text-align: center;">
    77   <img src="fig4-1-1.png" width="300" height="240" alt="introducing gamma" />
     87  <img src="fig4-1-1.png" width="460" height="256" alt="introducing gamma" />
    8191pretty comprehensive essay</a> about why on a computer screen a 50% black and
    8292white pattern should be scaled down to a gray value of 0.73 instead of 0.5 and
    83 how major computer graphics software totally misses the point. </p>
     93how major computer graphics software totally misses the point. Conversely, it
     94clearly means that a gray value of 0.5 should not be emulated with a 50%
     95dither pattern. </p>
    85 <p> Conversely, it clearly means that a gray value of 0.5 should not be
    86 emulated with a 50% dither pattern. </p>
     97<p> The following figure shows the gamma curve for the naïve three-colour
     98grayscale gradient we saw above (red) compared to the two-colour gradient
     99(blue). Two major observations can be made: the new curve is far closer to
     100a perfect, linear gradient, and there is a singularity in the middle of
     101the curve, meaning a break in the gradient’s smoothness. </p>
     103<p style="text-align: center;">
     104  <img src="fig4-1-2.png" width="460" height="256" alt="3-colour gamma" />
     107<p> There are three possible ways to reduce the singularity and make the
     108gradient smoother and/or closer to the original colours: </p>
     111  <li> Choose a different middle gray value, for instance choosing gray 0.73
     112       will cancel the singularity and match the two-colour gradients we have
     113       been using so far. This is not always possible if the output palette
     114       is fixed. </li>
     115  <li> Don’t place the gray value at the middle of the gradient, for instance
     116       putting it around 25% itensity will again match the previous two-colour
     117       gradients. </li>
     118  <li> <b>Gamma-correct</b> input pixels before assigning them an output
     119       value. This ensures that the resulting gradient is perfectly linear.
     120       </li>
     123<h3> 4.2. Gamma correction </h3>
     125<p> These are the results of gamma-correcting input pixels before doing
     126any computation on them, then using Floyd-Steinberg error diffusion: </p>
     128<p style="text-align: center;">
     129  <img src="out4-2-1.png" width="256" height="256"
     130       class="inline" alt="Floyd-Steinberg, 2 colours, gamma-corrected" />
     131  <img src="grad4-2-1.png" width="32" height="256"
     132       class="inline" alt="Floyd-Steinberg, 2 colours, gamma-corrected gradient" />
     133  <img src="out4-2-2.png" width="256" height="256"
     134       class="inline" alt="Floyd-Steinberg, 3 colours, gamma-corrected" />
     135  <img src="grad4-2-2.png" width="32" height="256"
     136       class="inline" alt="Floyd-Steinberg, 3 colours, gamma-corrected gradient" />
Note: See TracChangeset for help on using the changeset viewer.