Dithering

初出 1976 · Robert W. Floyd、Louis Steinberg — Floyd–Steinberg error-diffusion dithering (1976). · 年表 ↗

コミュニティ・通称 名称 — 計算機以前からの記述的用語(機械的な dither)。人名を冠した変種は Floyd–Steinberg(1976)。総称は記述的で人名エポニムではない。

ひとことで 限定色パレットで階調を表現するためのパターン化された誤差拡散・順序ディザ。Floyd-Steinberg, Bayer 等。

Dithering · Open in new tab ↗ · Motion begins only when you press Run.

コード

上のデモの実際のスケッチ(サンドボックスで再現可能)。これで全部です。

dithering/index.html
const SEED = Math.floor(Math.random()*1e9);

// Floyd-Steinberg error-diffusion dithering of a smooth noise gradient
// down to a small palette.
const RES = 200;

function setup() {
  noiseSeed(SEED); randomSeed(SEED);
  const s = Math.min(windowWidth, windowHeight);
  pixelDensity(1);
  const cnv = createCanvas(RES, RES);
  cnv.elt.style.width = s + 'px';
  cnv.elt.style.height = s + 'px';

  const PALETTES = [
    [[20,20,30],[40,60,120],[230,90,70],[245,240,225]],
    [[10,10,10],[80,80,80],[170,170,170],[245,245,245]],
    [[18,38,32],[42,120,110],[225,200,90],[245,240,225]],
  ];
  const palette = PALETTES[Math.floor(random(PALETTES.length))];

  // Build a smooth source field (luminance from layered noise).
  const FREQ = 0.012;
  const src = new Float32Array(RES * RES * 3);
  for (let y = 0; y < RES; y++) {
    for (let x = 0; x < RES; x++) {
      const v = noise(x * FREQ, y * FREQ) * 0.7 + noise(x * FREQ * 4, y * FREQ * 4) * 0.3;
      const i = (y * RES + x) * 3;
      // map scalar through the palette endpoints for a tinted gradient
      const lo = palette[0], hi = palette[palette.length - 1];
      src[i]   = lo[0] + (hi[0] - lo[0]) * v;
      src[i+1] = lo[1] + (hi[1] - lo[1]) * v;
      src[i+2] = lo[2] + (hi[2] - lo[2]) * v;
    }
  }

  const nearest = (r, g, b) => {
    let best = palette[0], bd = Infinity;
    for (const c of palette) {
      const d = (r-c[0])**2 + (g-c[1])**2 + (b-c[2])**2;
      if (d < bd) { bd = d; best = c; }
    }
    return best;
  };

  // Floyd-Steinberg
  for (let y = 0; y < RES; y++) {
    for (let x = 0; x < RES; x++) {
      const i = (y * RES + x) * 3;
      const old = [src[i], src[i+1], src[i+2]];
      const nw = nearest(old[0], old[1], old[2]);
      const err = [old[0]-nw[0], old[1]-nw[1], old[2]-nw[2]];
      src[i] = nw[0]; src[i+1] = nw[1]; src[i+2] = nw[2];
      const spread = (dx, dy, f) => {
        const xx = x + dx, yy = y + dy;
        if (xx < 0 || xx >= RES || yy < 0 || yy >= RES) return;
        const j = (yy * RES + xx) * 3;
        src[j]   += err[0] * f;
        src[j+1] += err[1] * f;
        src[j+2] += err[2] * f;
      };
      spread(1, 0, 7/16);
      spread(-1, 1, 3/16);
      spread(0, 1, 5/16);
      spread(1, 1, 1/16);
    }
  }

  loadPixels();
  for (let i = 0; i < RES * RES; i++) {
    pixels[i*4]   = src[i*3];
    pixels[i*4+1] = src[i*3+1];
    pixels[i*4+2] = src[i*3+2];
    pixels[i*4+3] = 255;
  }
  updatePixels();
}

デモのソースを開く ↗

仕組み

主に 2 系統:(1) 誤差拡散(Floyd–Steinberg)=画素を順に走査し、各画素で最近傍パレット色を選び、量子化誤差(元−選択)を計算して未処理の近傍へ固定重みで拡散(例:右 7/16、下に 3/16・5/16・1/16)。誤差が平均化され階調が保たれる。(2) 順序ディザ(Bayer)=各画素値をタイル状の閾値行列と比較し、セル閾値を超えるかで明暗のパレット色を出力。並列処理可能で特有のクロスハッチ/ハーフトーン質感になる。いずれも空間解像度と引き換えに見かけの階調深度を得る — 1bit/レトロ表現の基礎。

パラメータ

系譜

関連
Generative Typography / ASCII

よく組み合わされるアルゴリズム

このアルゴリズムを使う作品 (12)

Assemblage
sab-k2xl
Dot Matrix Gradient Study
jake-rockland
Fell-Cloud
travess-smalley
JPEG
jan-robert-leegte
Maps
john-provencher
New Worlds
robert-whitman
over-time
john-provencher
Pixel Glass
kai
Speckled Summits
jake-rockland
Stipple Sunsets
jake-rockland
Studies in Perception I
ken-knowlton
The Liths of Sisyphus
nonfigurativ

最終更新 2026-07-16