Function iafloyd

Synopse

Floyd-Steinberg error diffusion.

  • g = iafloyd(f)
    • g: Image.
    • f: Image. input image
01. from numpy import *
02. 
03. def iafloyd(f):
04.     from ianormalize import ianormalize
05. 
06.     f_ = 1.*ianormalize(f, [0,255])
07.     g = zeros(f_.shape)
08.     for i in range(f_.shape[0]):
09.         for j in range(f_.shape[1]):
10.             if f_[i,j] >= 128:
11.                 g[i,j] = 255
12.             erro = f_[i,j] - g[i,j]
13.             if j < f_.shape[1]-1:
14.                 f_[i,j+1] = f_[i,j+1] + 7*erro/16.
15.             if i < f_.shape[0]-1 and j > 0:
16.                 f_[i+1,j-1] = f_[i+1,j-1] + 3*erro/16.
17.             if i < f_.shape[0]-1:
18.                 f_[i+1,j] = f_[i+1,j] + 5*erro/16.
19.             if i < f_.shape[0]-1 and j < f_.shape[1]-1:
20.                 f_[i+1,j+1] = f_[i+1,j+1] + erro/16.
21.     g = g > 0
22.     return g

Description

Floyd-Steinberg error diffusion (1976).

Examples

Example 1

1. from ia636 import iafloyd
2. from ia636 import iaramp
3. 
4. f1 = iaramp([20,150], 256, [0,255])
5. f2 = adreadgray('woodlog.pgm')[:150,:150]
6. f = concatenate((f1, f2))
7. g = iafloyd(f)
8. adshow(f)
9. adshow(g)