Foundations
Image Kernels
Each output cell is the sum of the nine pixel–weight products under its window.
Input · Vertical Edge
Vertical Edge. 36 input intensities.
Choose an image in Controls. Each square stores one intensity.
- Input pixel
Still PNG/JPEG, up to 4 MiB, 4096 pixels per side and 8 million pixels. Resampled to a square 6×6 grid, which distorts the aspect ratio. Intensity is the channel mean times alpha over zero, not linear-light luminance. Nothing is uploaded or saved.
What does an edge look like as numbers?
Each square is one intensity between 0 and 1. Switch the image and follow the boundary between low and high values.
Pixel intensity
One number describing the brightness of a sampled image cell. These teaching images use 0 to 1.
Check this stage
Check your understanding
Multiply the nine pixels under a window by nine weights and add them. Every output cell comes from that same small calculation.
Follow one window
An image is a grid of intensities; a kernel is a smaller grid of weights. The filter multiplies corresponding entries of a local patch and the kernel, then adds the products. That sum becomes one output cell. Reusing the same weights across positions produces a feature map.
In The input, switch between Vertical Edge and Horizontal Edge. The boundary changes direction, but the values still mean the same thing: zero is the low end of the intensity scale and one is the high end. The reversed image changes which side is bright; the flat image has intensity 0.5 everywhere.
Move to The kernel. Select Vertical Edge, then inspect output row 0, column 1. The source patch contains [0, 0, 1] in each of its three rows. With weights [−1, 0, 1], each row contributes:
The three contributions sum to 3. This is a response, not a probability or a valid 0–1 image intensity. The kernel is measuring a difference across columns, so it responds to a vertical boundary. The supplied filters are simple directional differences, not Sobel filters.
Drag the diamond below the input or use its left and right arrow keys. You can also choose a row and column in Controls. Step moves to the next inspected cell; Play makes one finite scan to the end. The complete map is calculated immediately. Scanning explains its cells; it does not train the weights or gradually improve a score.
Does the kernel flip?
The default operation is cross-correlation: the displayed weights keep their orientation. Choose Convolution to flip the kernel by 180 degrees before taking the dot product. The vertical-edge response in the worked patch changes from 3 to −3. The effective-weight tiles show the orientation actually used.
A symmetric box average gives the same result after flipping. Directional filters need more care. The naming distinction is explicit in OpenCV's filtering reference; the image chapter of Dive into Deep Learning demonstrates the unflipped local operation used by convolutional layers. This lab has one channel, no bias and chosen weights. It does not simulate CNN training.
Change the weights, then check the sum
In The dot product, open Edit weights. Each effective weight is an integer numerator divided by the shared divisor. The Box Blur preset therefore uses nine ones divided by nine, retaining the exact average rather than rounding every weight to 0.11. The calculation tiles expose every pixel, effective weight and product. Under the hood also lists original source coordinates and full numerical values.
Try Sum instead of average. On the flat 0.5 image, nine unit weights return:
Set Weight divisor to 9 and the result becomes 0.5. Use Back to working to restore the complete preceding experiment, including a local image if one was loaded.
The sum of effective weights is the kernel's gain. A constant patch with value returns times that gain. Identity, the box average and sharpen all have gain one, but they do different things near an edge. Sharpen can exceed one or go negative even with gain one. Edge filters commonly have gain zero; they are meant to cancel on constant patches. Dividing every kernel by its weight sum would fail for those filters.
Borders and stride are part of the calculation
In The feature map, change Border and inspect a corner. Valid uses only fully contained windows. One-pixel zero padding supplies zeros outside the image. Replicated padding repeats the nearest real pixel. The outer ring and the inspection table identify assumed samples; they are not extra observations.
On the flat image with Box Blur, the zero-padded corner sees four pixels of 0.5 and five zeros. Its response is , approximately 0.2222. Replicated padding returns 0.5 there. Zero padding can also introduce an artificial intensity boundary that an edge filter detects. This is why a cancellation experiment that works with valid windows need not remain blank after padding.
Stride is the distance in input pixels between windows. For this 3×3 kernel, each output axis has size:
where is input size, is the border width on each side and is stride. A 6×6 input gives a 4×4 valid output at stride one, 2×2 at stride two, and 3×3 with one-pixel padding at stride two. Padding preserves the original size here only when stride is one. A larger stride saves calculations and output space but can skip detail. Padding and Stride derives this sampling trade-off.
Keep the raw response separate from its picture
Signed response uses the largest absolute response to scale fill strength; its cell labels remain raw numbers. It is a contrast encoding, so the same fill strength across two experiments does not guarantee the same raw magnitude. Read the values and signed peak when comparing.
Clipped 0–1 preview clamps negatives to zero and values above one to one. Its fill can make an unnormalised sum look ordinary or hide the reversed edge. It does not alter the raw calculation. The Outside 0–1 readout counts affected responses, and Under the hood shows raw and clipped values side by side. Labels round to four decimal places; the table retains full values. OpenCV's gradient example demonstrates why discarding negative derivatives loses edges.
Try the other direction pairs the horizontal filter with the vertical-edge image. Equal rows cancel, so all 16 valid responses are zero. The original challenge also accepts the transposed pairing. A zero response does not prove no variation: a row [0, 1, 0] varies, yet its left and right samples cancel under [−1, 0, 1]. Different patches can produce the same sum.
Try an image from your device
Choose a still PNG or JPEG in Controls. The lab checks file size and declared dimensions before asking the browser to decode it, then resamples the whole image to a deliberately square 6×6 teaching grid. This loses detail and distorts the aspect ratio. Intensity is the mean of encoded colour channels multiplied by alpha over zero; it is not linear-light luminance. The filtered object is this tiny sampled grid, not your original photograph.
The image and its filename stay out of URLs, storage and network requests. They remain in memory until you replace the input, reset or navigate away. A shared link carries filter settings and a notice to reselect the local input; it shows the Vertical Edge fixture until an image is chosen. Recipients must choose the same file to reproduce that experiment, and decoder resampling can vary between browsers. Reset controls removes the local input and returns to the default fixture. If decoding is unavailable or a file is rejected, choose another image or keep using the presets.
Stage recap
The input
Each square is one intensity between 0 and 1. Switch the image and follow the boundary between low and high values.
The kernel
The window picks a patch. The same nine weights are reused at every location. Cross-correlation keeps their orientation; convolution flips both axes.
The dot product
Read the nine products and their sum. Open Edit weights to change integer numerators and a divisor. Dividing nine unit weights by nine makes an average.
The feature map
Each sum fills one output cell. Change stride or the assumed border, then compare the raw signed view with a clipped 0–1 preview.
Reference
- Local weighted sum
- Multiply the nine sampled pixels by the effective weights and add the products. No clipping occurs in this calculation.
- Cross-correlation and convolution
- Correlation leaves the kernel unflipped. Convolution flips both axes. Symmetric kernels give the same result in either mode.
- Output size
- Per axis: floor((input + 2 × padding − kernel) / stride) + 1, with dilation one. Here padding is zero or one.
- Boundary
- Valid uses only fully contained windows. Zero padding supplies zeros; replicated padding repeats the nearest original pixel.
- Gain
- Sum of effective weights. Unity gain preserves constant patches; it does not prevent edge overshoot or padding artefacts.
- Display
- Signed fill strength is relative to the largest absolute response; labels stay raw. A clipped preview maps negatives to zero and values above one to one.
Break it on purpose
Nine unit weights sum a patch instead of averaging it: a constant 0.5 patch returns 4.5. A clipped preview hides that excess. Separately, a directional filter can cancel on the other edge image; zero response alone does not prove an absence of variation.
Explore next
- Convolution / CNNChange the filter and trace the dot product that builds each cell of the output feature map.
- Pooling (Max & Average)Shift an input feature and trace how crossing a pooling window changes the output.
- Hough TransformEach point votes for possible lines; shared accumulator bins collect evidence for the same hypothesis.