# Changeset 1979 for wwwTweet

Ignore:
Timestamp:
Nov 16, 2007, 4:11:14 PM (13 years ago)
Message:
• Colour dithering: separate-space dithering.
Location:
www/study
Files:
2 edited

Unmodified
Removed
• ## www/study/part5.html

 r1976

5. Colour dithering

Coming soon.

Dithering colour images means dithering three-dimensional elements (RGB pixels) instead of one-dimensional gray values. It is very complex and depends on the output media even more than grayscale dithering.

Separate-space dithering

In some cases it is possible to perform three one-dimensional dithering operations instead of one three-dimensional one. Consider for instance the following palette:

It is made of the eight possible red/green/blue combinations made of 0.0 and 1.0 values. So one way of dithering an image using this palette is to convert the image into three grayscale images (separating the red, green and blue channels), dither each subimage to two colours separately and recombine the images into three channels.

Here are the results with Floyd-Steinberg dithering applied to each channel. On the left, no colour correction, as The Gimp or Photoshop would do; on the right, gamma-corrected dithering:

• ## www/study/study.py

 r1978 test42x(gradient256bw, ERROR_FSTEIN, threshold_3).writePng("grad4-2-2.png") # Pattern 5.0.1: 8-colour palette dest = Image((512, 64)) for x in range(512): d = x / 64 r = (d & 2) >> 1 g = (d & 4) >> 2 b = d & 1 for y in range(64): dest.setRgb(x, y, r, g, b) dest.writePng("pat5-1-1.png") # Load the 256x256 colour Lenna image lenna256 = Image("lenna256.png") # Output 5.0.1: RGB dithering def test501(src, mat, func): (w, h) = src.size() dest = Image((w, h)) tmp = [Image((w, h)), Image((w, h)), Image((w, h))] for y in range(h): for x in range(w): rgb = src.getRgb(x, y) for i in range(3): tmp[i].setGray(x, y, rgb[i]) for i in range(3): tmp[i] = func(tmp[i], mat, threshold_2) for y in range(h): for x in range(w): (r, g, b) = [tmp[i].getGray(x, y) for i in range(3)] dest.setRgb(x, y, r, g, b) return dest test501(lenna256, ERROR_FSTEIN, test3xx).writePng("out5-1-1.png") test501(lenna256, ERROR_FSTEIN, test42x).writePng("out5-1-2.png") ############################################################################## # Place temporary cruft below this
Note: See TracChangeset for help on using the changeset viewer.