Painting · real-time post-process

Kuwahara filter

◂ renderKuwahara filter ▸

Drag the line: left of it, the shader's render; right of it, the same frame after the filter.

Kuwahara filter · Kuwahara et al. 1976

Each pixel takes the average of its calmest quarter

Move the pixel across the rim: the calmest quarter flips sides, so the filtered rim stays sharp.

// window radius r: four // (r+1)^2 quarters sharing // the middle row, column for (int k = 0; k < 4; k++) { // average vec3 m = M[k] / n; vec3 d = S[k] / n - m * m; // spread float v = d.r + d.g + d.b; if (v < best) { best = v; col = m; // the pixel } }

Box blur · Kuwahara filter

The box blur softens the rim; the Kuwahara filter keeps it sharp

◂ box blur: the whole window averagedKuwahara: the calmest quarter ▸

Drag the line across the rim, then grow the window both filters share.

Window radius

A wider window paints bigger, flatter patches

Slide it up: the speckle merges into patches, and the colony outlines hold.

Generalised Kuwahara filter · Papari, Petkov, Campisi 2007

Eight soft sectors round off the square quarters' blocks

Flip the window shape and watch the teal rim's patches.

// each sector k: weighted average m, // spread v; calm sectors weigh most float w = 1. / (1. + pow(1000. * v, .5 * q)); o += m * w; ws += w; // ... col = o / ws; // q, the sharpness: low blends every // sector, high keeps the calmest

Layer added: sectors

The dish, painted with your radius and window shape

◂ renderpainted ▸

Drag the line to compare with the render; switch a layer off to see what it adds.

Anisotropic Kuwahara filter · Kyprianidis, Kang, Döllner 2009

Stretched along the edges, the strokes follow the form

each ellipse: the window one pixel uses

Show the windows: long along rims and rings, round on flat agar.

// E, G, F: the structure tensor, // blurred gx*gx, gy*gy, gx*gy // l1, l2: its eigenvalues, l1 >= l2 vec2 t = vec2(l1 - E, -F); // along float A = (l1 - l2) / (l1 + l2); // A: 0 on flat agar, 1 on a rim float a = r * (1. + A); // long float b = r / (1. + A); // short

Layer added: direction

The dish, painted with your radius, shape and direction

◂ renderpainted ▸

Drag the line to compare with the render; switch a layer off to see what it adds.

Recap

What the dish showed