# Changeset 1932 for wwwTweet

Ignore:
Timestamp:
Nov 11, 2007, 1:27:45 PM (13 years ago)
Message:
• Serpentine Floyd-Steinberg.
Location:
www/study
Files:
2 edited

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

 r1931

The idea behind error diffusion is to compute the error caused by thresholding a given pixel and propagate it to neighbour pixels.

thresholding a given pixel and propagate it to neighbour pixels to compensate for the brightness loss. It is based upon the assumption that a slightly out-of-place pixel is better than a completely missing pixel.

3.1. Floyd-Steinberg error diffusion

class="inline" alt="Floyd-Steinberg error diffusion" />

This is a variant called “serpentine Floyd-Steinberg” that parses every odd line right to left. The results is very close to the original Floyd-Steinberg, but avoids artifacts in some corner cases:

• ## www/study/study.py

 r1931 for y in range(h): en = [0.] * (w + 2) #print 'ep:', ep #print 'en:', en ex = 0 for x in range(w): test5(lenna256bw, "out010.png") test5(gradient256bw, "grad010.png") # Output 11: serpentine Floyd-Steinberg def test6(src, name): (w, h) = src.size() dest = Image((w, h)) ep = [0.] * (w + 2) for z in range(h / 2): en = [0.] * (w + 2) ex = 0 y = z * 2 for x in range(w): c = src.getGray(x, y) + ex + ep[x + 1] d = c > 0.5 dest.setGray(x, y, d) error = c - d ex = error * 7. / 16. en[x] += error * 3. / 16. en[x + 1] += error * 5. / 16. en[x + 2] += error * 1. / 16. ep = en en = [0.] * (w + 2) ex = 0 y = z * 2 + 1 for x in range(w - 1, -1, -1): c = src.getGray(x, y) + ex + ep[x + 1] d = c > 0.5 dest.setGray(x, y, d) error = c - d ex = error * 7. / 16. en[x] += error * 1. / 16. en[x + 1] += error * 5. / 16. en[x + 2] += error * 3. / 16. ep = en dest.writePng(name) test6(lenna256bw, "out011.png") test6(gradient256bw, "grad011.png") ##############################################################################
Note: See TracChangeset for help on using the changeset viewer.