Computer Graphics (Hong)
๐ง Kernel and Convolution
Kernal
๐๏ธ Core Concepts
- Kernel (Convolution matrix / Mask): A small matrix used for transformations like blurring, sharpening, embossing, and edge detection.
- Convolution: Mathematical operation where each output pixel is computed using a weighted sum of nearby input pixels using the kernel.
๐ Kernel Operation
- Origin: The conceptual reference point in the kernel that aligns with the output pixel during convolution.
- Symmetric Kernels: Often use the center element as origin.
- Flipping: Non-symmetric kernels must be flipped both horizontally and vertically before applying convolution.
๐ Edge Handling Techniques
Extend
: Repeats border pixels outward.
Wrap
: Uses pixels from opposite edges (like tiling).
Mirror
: Reflects pixels at the image edge.
Crop / Avoid overlap
: Skips edge pixels โ used frequently in machine learning pipelines (e.g., shrinking a 32ร32 image to 23ร23).
Constant
: Fills outside areas with fixed values (black/gray).
๐งฎ Normalization
- Scales kernel values so their sum equals unity (1).
- Maintains overall image brightness post-processing.
โก Optimization โ Separable Convolution
- A 2D convolution (MรN kernel) typically needs MรN multiplications per pixel.
- If the kernel is separable, computation drops to M+N, by applying two 1D convolutions.
๐ฅ๏ธ GPU Implementation Highlights
- GLSL shader code demonstrates how to:
- Extract a 3ร3 region from texture
- Apply convolution with various kernels (
edge0
, sharpen
, gaussian_blur
)
- Process individual color channels (RGB)
- Use functions like
matrixCompMult
for element-wise operations
๐ฏ Interview Questions
๐ง Conceptual Understanding
- What is a convolution kernel, and how is it used in image processing?
- Why is normalization of the kernel important?
๐ Practical Implementation
- Explain how edge handling affects convolution results.
- Whatโs the difference between symmetric and non-symmetric kernels in convolution?
โก Optimization
- What is separable convolution, and how does it reduce computation cost?
๐ฅ๏ธ Applied Techniques
- How would you implement a convolution operation using shaders (GLSL)?
- Describe how youโd perform edge detection using a convolution matrix.
๐ค Machine Learning Relevance
- Why is cropping used in ML convolution layers?
- How do CNNs handle boundary conditions during kernel operations?
Convolution
๐๏ธ Core Concepts
- Convolution: An operation that combines two functions by integrating the product of one function with a shifted and flipped version of the other.
- Notation: \((f * g)(t) \;=\; \int_{-\infty}^{\infty} f(\tau)\,g(t-\tau)\,d\tau\)
- Graphical Meaning: Represents how the shape of one function modifies another.
๐ Properties
- Commutative: $f * g = g * f$
- Associative: $f * (g * h) = (f * g) * h$
- Distributive: $f * (g + h) = f * g + f * h$
- Translation Equivariance: Convolution commutes with shifts in input
๐ Variants
- Discrete Convolution: For integer-indexed sequences (used in signal & image processing).
- Circular Convolution: Convolution over periodic domains or in FFT-based processing.
- Infimal Convolution: Used in convex analysis and optimization.
๐งฎ Mathematical Relations
- Convolution Theorem: Fourier transform of convolution is the product of individual transforms.
- $ \mathcal{F}(f * g) = \mathcal{F}(f) \cdot \mathcal{F}(g) $
- Laplace Transform & Z-transform equivalents
- Convolution with delta function results in the original function
๐ Applications
- Signal & Image Processing: Filtering, edge detection, blurring, sharpening
- Machine Learning / CNNs: Feature extraction via convolution layers
- Probability: Distribution of sum of two independent random variables
- Physics / Spectroscopy: Combining different response functions (e.g. Voigt profile)
โ๏ธ Computational Techniques
- Fast Convolution:
- FFT-based convolution using Circular Convolution Theorem
- Winograd algorithms for faster low-dimensional convolutions
- Overlap-add / overlap-save methods for streaming signals
๐ฏ Interview Questions
- ๐ง Theoretical Concepts
- What is convolution in the context of signal or image processing?
- How does convolution differ from cross-correlation?
- Describe the convolution theorem and its implications in Fourier analysis.
- ๐งฎ Math & Implementation
- How would you implement 2D convolution efficiently for image filtering?
- Why do we flip the kernel in convolution? Is it always necessary?
- How is circular convolution used in FFT-based methods?
- ๐ค Practical Applications
- In CNNs, why is the operation called โconvolutionโ although itโs actually cross-correlation?
- Explain how convolution helps in probability theory for combining distributions.
- Describe a real-world physical phenomenon modeled using convolution (e.g. reverberation, spectroscopy).
- โก Advanced Concepts
- What is separable convolution and why is it computationally advantageous?
- Describe infimal convolution and its role in optimization.
- How does convolution work in function spaces or with distributions?
URLs