078
LVL 03 — MID DEVELOPERSESSION 078DAY 78

ADVANCED FILTERS

🎫 PIXELCRAFT-065
Feature | 🟠 Hard | Priority: 🟠 High

Users want professional-grade filters: sepia, blur, sharpen, vignette, edge detect. Not just CSS filters — real pixel-level image processing using convolution kernels and color matrix transformations.
CONCEPTS.UNLOCKED
🧮
Convolution Kernels
A small matrix that transforms pixels. Slide a 3×3 grid across the image. Each pixel becomes a weighted sum of its neighbors. Different weights = blur, sharpen, edge detect.
🎨
Color Matrix Transformations
Multiply each pixel's RGBA by a matrix. Sepia, grayscale, hue rotation — all are matrix multiplications on color values. Same math as Canvas transforms, applied to color space.
🌑
Vignette Effect
Darken edges, brighten center. Create a radial gradient mask (white center → black edges), then multiply it with the image. Distance from center controls the falloff.
🔍
Edge Detection
Sobel kernel finds boundaries. Horizontal kernel detects vertical edges, vertical kernel detects horizontal edges. Combine both for a full edge map — the foundation of computer vision.
🎛️
Filter Parameters
Intensity, radius, threshold. Every filter needs tuneable parameters. Blur radius controls smoothness. Sharpen amount controls intensity. Expose sliders for each.
🖼️
Filter Preview Thumbnails
Show all filters on a tiny preview. Render the image at 100px, apply each filter, display as clickable thumbnails. Instagram-style picker — users see before they choose.
HANDS-ON.TASKS
01
Convolution Engine
function applyConvolution( imageData, kernel ) { const { data, width, height } = imageData; const output = new Uint8ClampedArray(data); const kSize = Math.sqrt(kernel.length); const half = Math.floor(kSize / 2); for (let y = half; y < height - half; y++) { for (let x = half; x < width - half; x++) { let r = 0, g = 0, b = 0; for (let ky = 0; ky < kSize; ky++) { for (let kx = 0; kx < kSize; kx++) { const px = x + kx - half; const py = y + ky - half; const i = (py * width + px) * 4; const w = kernel[ky * kSize + kx]; r += data[i] * w; g += data[i + 1] * w; b += data[i + 2] * w; } } const i = (y * width + x) * 4; output[i] = r; output[i + 1] = g; output[i + 2] = b; } } return new ImageData( output, width, height); }
02
Blur, Sharpen & Edge Detect Kernels
const KERNELS = { blur: [ 1/9, 1/9, 1/9, 1/9, 1/9, 1/9, 1/9, 1/9, 1/9 ], gaussianBlur: [ 1/16, 2/16, 1/16, 2/16, 4/16, 2/16, 1/16, 2/16, 1/16 ], sharpen: [ 0, -1, 0, -1, 5, -1, 0, -1, 0 ], edgeDetect: [ -1, -1, -1, -1, 8, -1, -1, -1, -1 ], emboss: [ -2, -1, 0, -1, 1, 1, 0, 1, 2 ], };
The blur kernel averages neighbors (equal weights). Sharpen amplifies center, subtracts neighbors. Edge detect finds pixels that differ from their neighbors.
03
Color Matrix: Sepia & Grayscale
function applyColorMatrix( imageData, matrix ) { const d = imageData.data; for (let i = 0; i < d.length; i += 4) { const r = d[i], g = d[i+1], b = d[i+2]; d[i] = r*matrix[0] + g*matrix[1] + b*matrix[2]; d[i+1] = r*matrix[3] + g*matrix[4] + b*matrix[5]; d[i+2] = r*matrix[6] + g*matrix[7] + b*matrix[8]; } return imageData; } const SEPIA_MATRIX = [ 0.393, 0.769, 0.189, 0.349, 0.686, 0.168, 0.272, 0.534, 0.131, ]; const GRAYSCALE_MATRIX = [ 0.299, 0.587, 0.114, 0.299, 0.587, 0.114, 0.299, 0.587, 0.114, ];
04
Vignette Effect
function applyVignette( imageData, intensity = 0.5 ) { const { data, width, height } = imageData; const cx = width / 2; const cy = height / 2; const maxDist = Math.sqrt(cx * cx + cy * cy); for (let y = 0; y < height; y++) { for (let x = 0; x < width; x++) { const dx = x - cx; const dy = y - cy; const dist = Math.sqrt(dx * dx + dy * dy); const factor = 1 - ((dist / maxDist) * intensity); const i = (y * width + x) * 4; data[i] *= factor; data[i + 1] *= factor; data[i + 2] *= factor; } } return imageData; }
05
Filter Preview Thumbnails

Build an Instagram-style filter picker: render a 100px thumbnail, apply each filter to a copy, display all as clickable previews. Show filter name below each. Click to apply to the full image.

06
Close the Ticket
git switch -c feature/PIXELCRAFT-065-advanced-filters git add src/ git commit -m "Add convolution filters + color matrix + vignette (PIXELCRAFT-065)" git push origin feature/PIXELCRAFT-065-advanced-filters # PR → Review → Merge → Close ticket ✅
CS.DEEP-DIVE

Convolution is one of the most important operations in all of computing.

The same operation that blurs your photo is at the heart of Convolutional Neural Networks (CNNs) — the architecture behind modern AI image recognition.

// Convolution across fields:

Image processing
  Blur, sharpen, edge detect
  — you just built these

Computer vision (CNNs)
  Same operation, but the kernel
  values are learned by the network
  AlexNet: 96 learned 11×11 kernels

Audio processing
  Reverb = convolution with an
  impulse response

Signal processing
  Low-pass, high-pass, band-pass
  filters — all convolutions

// One operation. Four fields.
// This is why fundamentals matter.
"Filter Lab"
[A]Combine filters into presets: "Vintage" = sepia + vignette + slight blur. "Dramatic" = high contrast + sharpen + vignette. Let users save their own filter combinations.
[B]Move filter processing to a Web Worker so the UI doesn't freeze. postMessage the ImageData to the worker, apply the filter, send it back. Measure the responsiveness improvement.
[C]Research: how does Photoshop's "Unsharp Mask" work? It's: blur the image, subtract the blur from the original, add the difference back amplified. Implement it.
REF.MATERIAL
ARTICLE
Victor Powell
Interactive visualization of convolution kernels. Drag a kernel across an image and see what happens to each pixel. The best way to understand convolution.
CONVOLUTIONINTERACTIVEESSENTIAL
VIDEO
3Blue1Brown
Beautiful visualization of convolution from first principles. The math connecting image processing to neural networks.
CONVOLUTIONVISUALESSENTIAL
ARTICLE
MDN Web Docs
getImageData, putImageData, and the pixel array. Direct access to every pixel's RGBA values for custom image processing.
CANVASPIXELSOFFICIAL
ARTICLE
Wikipedia
The theory: convolution, common kernels, separable filters, Gaussian blur derivation, and the math foundation of image filtering.
KERNELSTHEORYCS
VIDEO
The Coding Train
Hands-on pixel manipulation: brightness, contrast, threshold, and convolution kernels. Creative coding meets image processing.
CANVASTUTORIAL
// LEAVE EXCITED BECAUSE
You built real image processing from scratch. Not CSS filters — actual pixel-level convolution kernels, color matrices, and radial vignettes. The same math that powers Photoshop and neural networks.