Changes between Version 1 and Version 2 of libcaca/study/5
- Timestamp:
- 12/22/2009 09:21:17 PM (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
libcaca/study/5
v1 v2 3 3 At first sight, generalising dithering to three grey scales seems pretty straightforward: just add grey 0.5 in the middle of the palette and dither pixels in the [0, 0.5] range with black and grey, and pixels in the [0.5, 1] range with grey and white. Here are two different results with 8×8 Bayer ordered dithering and with serpentine Floyd-Steinberg error diffusion: 4 4 5 [[Image(source:/web/trunk/ static/study/out/lena5-0-1.png,class="inline",alt="8×8 Bayer ordered dithering, 3 colours")]]6 [[Image(source:/web/trunk/ static/study/out/grad5-0-1.png,class="inline",alt="8×8 Bayer ordered dithering gradient, 3 colours")]]7 [[Image(source:/web/trunk/ static/study/out/lena5-0-2.png,class="inline",alt="serpentine FS error diffusion, 3 colours")]]8 [[Image(source:/web/trunk/ static/study/out/grad5-0-2.png,class="inline",alt="serpentine FS error diffusion gradient, 3 colours")]]5 [[Image(source:/web/trunk/www/study/out/lena5-0-1.png,class="inline",alt="8×8 Bayer ordered dithering, 3 colours")]] 6 [[Image(source:/web/trunk/www/study/out/grad5-0-1.png,class="inline",alt="8×8 Bayer ordered dithering gradient, 3 colours")]] 7 [[Image(source:/web/trunk/www/study/out/lena5-0-2.png,class="inline",alt="serpentine FS error diffusion, 3 colours")]] 8 [[Image(source:/web/trunk/www/study/out/grad5-0-2.png,class="inline",alt="serpentine FS error diffusion gradient, 3 colours")]] 9 9 10 10 These are pretty much the images that imaging software such as The Gimp would give (using “positioned” and “Floyd-Steinberg” dithering modes). … … 18 18 If you are reading this document on a computer screen, you may have noticed that the black and white 50% pattern was closer to a 0.73 greyscale (left) than to the intuitively expected 0.5 value (right). If you are reading a printed copy, it might be a different matter. 19 19 20 [[Image(source:/web/trunk/ static/study/out/pat5-1-1.png,class="inline",alt="introducing gamma")]]20 [[Image(source:/web/trunk/www/study/out/pat5-1-1.png,class="inline",alt="introducing gamma")]] 21 21 22 22 The mapping linking greyscale steps to intensities is called '''gamma correction'''. An approximate law for gamma correction is given as ''I = v^γ^'', where ''v'' is the coded colour value (between 0 and 1), ''I'' is the perceived colour intensity (between 0% and 100%) and ''γ'' is the gamma. A pattern made of even-numbered 0%-intensity pixels and 100%-intensity pixels has an intensity of 50% by definition. But the corresponding greyscale depends on the gamma value. … … 24 24 Most modern computer systems use the sRGB gamma model close to the law with ''γ = 2.2''. As can be seen, it is highly non-linear: 25 25 26 [[Image(source:/web/trunk/ static/study/fig5-1-1.png,alt="introducing gamma")]]26 [[Image(source:/web/trunk/www/study/fig5-1-1.png,alt="introducing gamma")]] 27 27 28 28 Éric Brasseur wrote [http://www.4p8.com/eric.brasseur/gamma.html a pretty comprehensive essay] ![16] about why on a computer screen a 50% black and white pattern should be scaled down to a grey value of 0.73 instead of 0.5 and how major computer graphics software totally misses the point. Conversely, it clearly means that a grey value of 0.5 should not be emulated with a 50% dither pattern. … … 30 30 The following figure shows the gamma curve for the naïve three-colour greyscale gradient we saw above (red curve) compared to the two-colour gradient (blue curve). Two major observations can be made: the new curve is far closer to a perfect, linear gradient, but there is a singularity in the middle of the curve, meaning a break in the gradient’s smoothness. 31 31 32 [[Image(source:/web/trunk/ static/study/fig5-1-2.png,alt="3-colour gamma")]]32 [[Image(source:/web/trunk/www/study/fig5-1-2.png,alt="3-colour gamma")]] 33 33 34 34 There are three possible ways to reduce the singularity and make the gradient smoother and/or closer to the original colours: … … 42 42 Gamma correction consists in converting pixel values into intensity values before performing operations on them, then reconverting them to pixel values before displaying them. The exact same algorithms can be used, they just operate on slightly different data. 43 43 44 [[Image(source:/web/trunk/ static/study/fig5-1-3.png,alt="3-colour gamma coorection")]]44 [[Image(source:/web/trunk/www/study/fig5-1-3.png,alt="3-colour gamma coorection")]] 45 45 46 46 Here are the results of gamma-correcting input pixels before doing any computation on them, then using serpentine Floyd-Steinberg error diffusion: 47 47 48 [[Image(source:/web/trunk/ static/study/out/lena5-2-1.png,class="inline",alt="serpentine FS, 2 colours, gamma-corrected")]]49 [[Image(source:/web/trunk/ static/study/out/grad5-2-1.png,class="inline",alt="serpentine FS, 2 colours, gamma-corrected gradient")]]50 [[Image(source:/web/trunk/ static/study/out/lena5-2-2.png,class="inline",alt="serpentine FS, 3 colours, gamma-corrected")]]51 [[Image(source:/web/trunk/ static/study/out/grad5-2-2.png,class="inline",alt="serpentine FS, 3 colours, gamma-corrected gradient")]]48 [[Image(source:/web/trunk/www/study/out/lena5-2-1.png,class="inline",alt="serpentine FS, 2 colours, gamma-corrected")]] 49 [[Image(source:/web/trunk/www/study/out/grad5-2-1.png,class="inline",alt="serpentine FS, 2 colours, gamma-corrected gradient")]] 50 [[Image(source:/web/trunk/www/study/out/lena5-2-2.png,class="inline",alt="serpentine FS, 3 colours, gamma-corrected")]] 51 [[Image(source:/web/trunk/www/study/out/grad5-2-2.png,class="inline",alt="serpentine FS, 3 colours, gamma-corrected gradient")]] 52 52 53 53 Two-colour dithering is not visually satisfying: dark areas lack much detail because the gamma curve is very flat at low intensities. However, the result itself is far more accurate that previously. The problem, while still visible, is even less important with three-colour dithering: the image on the right is superior to what The Gimp or Adobe Photoshop are able to come up with. … … 55 55 Finally, this is gamma-corrected 4-colour dithering: 56 56 57 [[Image(source:/web/trunk/ static/study/out/lena5-2-3.png,class="inline",alt="serpentine FS, 4 colours, gamma-corrected")]]58 [[Image(source:/web/trunk/ static/study/out/grad5-2-3.png,class="inline",alt="serpentine FS, 4 colours, gamma-corrected gradient")]]57 [[Image(source:/web/trunk/www/study/out/lena5-2-3.png,class="inline",alt="serpentine FS, 4 colours, gamma-corrected")]] 58 [[Image(source:/web/trunk/www/study/out/grad5-2-3.png,class="inline",alt="serpentine FS, 4 colours, gamma-corrected gradient")]] 59 59 60 60 == 5.3. Greyscale sub-block error diffusion == … … 64 64 The following picture uses all possible 4-greyscale 2×2 tiles. The output quality is very close to what standard, pixel-per-pixel error diffusion achieves: 65 65 66 [[Image(source:/web/trunk/ static/study/out/lena5-3-1.png,class="inline",alt="sub-block FS, full 4-grey tiles")]]67 [[Image(source:/web/trunk/ static/study/out/grad5-3-1.png,class="inline",alt="sub-block FS, full 4-grey tiles gradient")]]66 [[Image(source:/web/trunk/www/study/out/lena5-3-1.png,class="inline",alt="sub-block FS, full 4-grey tiles")]] 67 [[Image(source:/web/trunk/www/study/out/grad5-3-1.png,class="inline",alt="sub-block FS, full 4-grey tiles gradient")]] 68 68 69 69 And finally, this picture only uses 4-greyscale combinations of the “lines” tiles seen previously: 70 70 71 [[Image(source:/web/trunk/ static/study/fig5-3-1.png,class="matrix",alt="list of 4-grey 2×2 pixel blocks")]]72 [[Image(source:/web/trunk/ static/study/out/lena5-3-2.png,class="inline",alt="sub-block FS, lines 4-grey tiles")]]73 [[Image(source:/web/trunk/ static/study/out/grad5-3-2.png,class="inline",alt="sub-block FS, lines 4-grey tiles gradient")]]71 [[Image(source:/web/trunk/www/study/fig5-3-1.png,class="matrix",alt="list of 4-grey 2×2 pixel blocks")]] 72 [[Image(source:/web/trunk/www/study/out/lena5-3-2.png,class="inline",alt="sub-block FS, lines 4-grey tiles")]] 73 [[Image(source:/web/trunk/www/study/out/grad5-3-2.png,class="inline",alt="sub-block FS, lines 4-grey tiles gradient")]]