How the Kuwahara filter works
The Kuwahara filter is an edge-preserving smoothing filter: it removes texture and noise from an image but keeps the edges between regions sharp. That's why its output looks painted instead of blurry, and why it shows up in painterly and cartoon camera effects, including the cel-shade and watercolor cameras on this site and the Lightdab iPhone app.
Blur vs. Kuwahara
A blur replaces each pixel with an average of all its neighbors. In a flat area that's fine, but next to an edge the average mixes both sides, so the edge goes soft. The Kuwahara filter also averages, but it chooses which neighbors to average: only the part of the neighborhood that looks most like one uniform region.
The classic filter, step by step
- Take a square window around the pixel, for example 9 Γ 9 pixels for a radius of 4.
- Split it into four overlapping squares, one per corner. Each is (radius + 1) Γ (radius + 1) pixels, and they share the center row and column.
- For each square, compute the average color and the variance, which measures how much the colors in that square differ.
- Output the average of the square with the lowest variance.
Next to an edge, at least one of the four squares usually sits entirely on one side, so it has low variance and its average belongs to that side. The pixel takes that color, and the edge stays where it was. Kuwahara and colleagues described the filter in 1976 for cleaning up medical images of the heart.
Why the classic version looks blocky
Neighboring pixels often pick different squares, and the boundaries between those choices fall on horizontal and vertical lines. The result has rectangular brush marks, a look that's easy to mistake for low resolution. Step 3 of the interactive shows it at a large pixel size.
The generalized Kuwahara filter
Papari, Petkov and Campisi (2007) replaced the four squares with a round window cut into eight overlapping sectors, with smooth weights instead of hard edges, and blended the sector averages instead of picking one. Each sector's weight falls off steeply as its variance grows, so the calmest sectors dominate. Kyprianidis and colleagues (2010) introduced polynomial weighting functions that make the sectors cheap to compute on a GPU. The shader on this page, from the site's camera kit, uses that sector shape with a Gaussian falloff, weighting each sector by 1 / (1 + (8000 ΟΒ²)β΄). It is the isotropic version: the sectors don't rotate to follow the image's structure, as the anisotropic Kuwahara filter does. The squares disappear and the regions come out rounded, more like brush strokes.
Questions
Is the Kuwahara filter a blur? No. It smooths, but it's nonlinear: it picks or weights regions by how uniform they are, so edges survive. A Gaussian blur weights neighbors only by distance.
How is it different from a bilateral or median filter? A bilateral filter weights each neighbor by distance and by how similar its color is to the center pixel. A median filter takes the middle value. The Kuwahara filter compares whole subregions and keeps the most uniform one, which flattens texture into patches and gives it a painted look.
What does the radius do? It sets how far each pixel looks. Bigger radii make bigger, flatter patches and remove more detail.
Is this AI? No. It's a fixed formula that runs per pixel in a shader. Nothing is generated or learned.
Try it
The interactive has five steps: blur vs. paint, one pixel's neighborhood, four squares, eight soft slices compared with squares, and the cartoon look. Related: how a computer finds edges (the ink lines), the Cel Shade Camera, and how these experiments became an app in Chasing Waking Life.
References
- M. Kuwahara, K. Hachimura, S. Eiho, M. Kinoshita. Processing of RI-Angiocardiographic Images. In Digital Processing of Biomedical Images, Springer, 1976.
- G. Papari, N. Petkov, P. Campisi. Artistic Edge and Corner Enhancing Smoothing. IEEE Transactions on Image Processing 16(10), 2449-2462, 2007.
- J. E. Kyprianidis, A. Semmo, H. Kang, J. DΓΆllner. Anisotropic Kuwahara Filtering with Polynomial Weighting Functions. EG UK Theory and Practice of Computer Graphics, 2010.