technique

Kernel convolutions

Compute each output pixel as a weighted sum of an input pixel and its neighbors under a small kernel matrix, producing blur, sharpen or edge-detect effects.

Also called: Spatial convolution image filter · convolution matrix · kernel filter · sharpen/blur kernel

What it is

Every output pixel is a weighted sum of an input pixel and its immediate neighbors, with the weights coming from a matrix — the kernel. That’s Daniel Shiffman’s own framing in the Processing tutorial this page draws from: “The process uses a weighted average of an input pixel and its neighbors to calculate an output pixel.” The Book of Shaders names the same operation “Kernel convolutions” too, though what’s captured here from that source is just those two words at the site’s root URL, not a page whose treatment of the idea this page has actually read.

How it works

The only piece of implementation the evidence behind this page contains is the accumulation step itself:

rtotal += (red(img.pixels[loc]) * matrix[i][j]);

Read plainly: the red channel of a neighbor pixel, fetched via some index loc, gets multiplied by the matching kernel weight and added to a running total. That’s as far as the excerpts go. How loc is computed from the kernel’s row and column, whether the same accumulation runs for green and blue, where the loop bounds sit, and how the three totals turn into the output pixel’s color are not in evidence here — read Shiffman’s tutorial at the link below for the rest of the loop before assuming any of it.

Parameters & tuning

The kernel matrix is what the evidence identifies as the source of the weights in that multiply-and-accumulate step — matrix[i][j] is the only tunable quantity the quoted line names. Nothing in the excerpts here gives actual weight values, matrix dimensions, or how a neighborhood that runs off the edge of the image gets handled; those are real open questions the primary source likely answers, but this page’s evidence doesn’t.

Where it’s been used

Both sources behind this page are teaching material, not artworks: Daniel Shiffman’s Processing tutorial, drawn from Learning Processing, and The Book of Shaders. Neither excerpt names a specific piece built with kernel convolution. That’s a gap in this page’s evidence, not a claim that the technique goes unused.

Variants & neighbours

Pixel-sampled point rendering inverts what “neighbor” means here: instead of combining a pixel with its neighborhood, it samples one pixel’s color and draws a shape at that same sampled location, treating the bitmap as a lookup table rather than a source of local averages.

Pixel array 1D indexing formula describes the layer underneath this one: how Processing finds a single pixel at (x, y) by computing the offset x + y*width into a flat array. Whatever the full kernel loop turns out to do, it has to reach into the source image the same way — this technique adds combination on top of that single-pixel lookup, not a replacement for it.

Go deeper

Daniel Shiffman’s Processing tutorial, from Learning Processing, has the accumulation line this page quotes from — read it at processing.org/tutorials/pixels. The Book of Shaders is the only other source behind this page, and the only evidence gathered from it is the two words “Kernel convolutions,” captured from the site’s root URL — enough to say the site names this technique somewhere, not enough to say anything about how it treats it. Read it directly before trusting anything past the accumulation line above.

Connected to

Further reading: The Book of Shaders

Contrast with: Pixel array 1D indexing formula


Revision 4 · 2 sources · Something wrong? Tell us.