Image Convolution
Slide a kernel over every pixel, multiplying and summing neighbors to produce a new image. This single operation underlies blur, sharpen, edge detection, and much of computer vision.
How it works
Convolution is the fundamental operation of image processing. For each pixel in the output image, you place the kernel (a small matrix of weights) centered on the corresponding input pixel. You multiply each kernel value by the overlapping pixel value, sum them all up, and that sum becomes the output pixel.
Different kernels extract different features. An identity kernel (all zeros with a 1 in the center) leaves the image unchanged. A box blur averages neighboring pixels equally, producing a soft blur. Gaussian blur weights the center more heavily, creating a more natural smoothness. Sharpen amplifies the center pixel and subtracts neighbors, enhancing local contrast.
Edge detection kernels like Sobel and Laplacian respond to rapid changes in intensity. The Sobel X kernel detects vertical edges (horizontal gradients), while Sobel Y detects horizontal edges. The Laplacian detects edges in all directions by computing the second derivative of the image. Emboss creates a relief effect by combining an edge detector with a slight offset.
These same convolution operations form the foundation of convolutional neural networks (CNNs). In deep learning, instead of hand-designing kernels, the network learns optimal kernel values from data. The first layers typically learn edge detectors similar to Sobel, while deeper layers learn increasingly abstract features — all through the same sliding-window, multiply-and-sum operation you see here.