Pixels & neighborhoods

Build a Filter

Edit a kernel and see what it does to an image. Inspect one neighborhood to understand every multiply and add.

10 min to exploreComputer Vision
01 / UNDERSTAND

How can nine numbers change the appearance of an image?

A filter combines nearby pixel values. Kernel weights determine the operation, border handling affects edge pixels, and display clipping can hide values outside the visible range.

02 / EXPLORE

Make a prediction.
Then move a control.

Nine numbers. A different image.

Build a filter

Edit a 3 × 3 kernel and follow the arithmetic for one pixel.

Kernel weights

At the edge, repeat the nearest valid pixel. The output stays 32 × 32.

Convention: cross-correlation. The kernel slides without being flipped, as in PyTorch Conv2d. Mathematical convolution flips the kernel first.

Original32 × 32 grayscale pixels
FilteredSame size · clipped to 0–255

Click either image to inspect a pixel. With an image focused, use the arrow keys. The blue box marks the selected output; the outlined neighborhood shows its source pixels.

Weighted sum—
Raw output—
Displayed pixel—

Divide, clip to [0, 255], then round for display.

Inside one output pixel

Pixel (13, 10)

Each cell shows source × weight = contribution. The kernel stays in the order you entered.

Sum the nine contributions, then divide.

An educational experiment with illustrative data. The controls run locally in your browser.

03 / SEE THE CODE

The idea,
in Python.

A compact implementation of the core concept. Open the code when you are ready to connect the visual to the algorithm.

Open the core implementation Python ↗
Standalone example · illustrative valuesDownload .py
import numpy as np

image = np.array([[0., 0., 0.], [0., 255., 0.], [0., 0., 0.]])
kernel = np.ones((3, 3)) / 9
padded = np.pad(image, 1, mode="constant")
raw = np.zeros_like(image)

for row in range(image.shape[0]):
    for col in range(image.shape[1]):
        patch = padded[row:row + 3, col:col + 3]
        raw[row, col] = np.sum(patch * kernel)

# Unflipped kernel: cross-correlation, as used in many CNN APIs.
display = np.clip(raw, 0, 255).astype(np.uint8)
print(raw)
04 / TRY IT

Explain the change.
Test your reasoning.

  1. Compare blur, edge and sharpen kernels on the same image.
  2. Inspect a pixel near an edge and explain its raw filtered value.
  3. Change the border rule. Why do image boundaries behave differently?
← All visual labsNext: Neural Network Parameter Explorer

Find your next idea.

Search across courses, research, projects, and resources.

Ideas, connected.esc to close