tezvyn:

How does filter separability optimize Gaussian blur and its complexity?

Curated by the Tezvyn teamSource: Wikipedia: Gaussian bluradvanced
How does filter separability optimize Gaussian blur and its complexity?

This tests if you know a 2D Gaussian separates into two 1D convolutions. A strong answer gives complexity as O(N^2 K^2) dropping to O(N^2 K) for an N-by-N image and K-by-K kernel. A red flag is claiming all kernels are separable or omitting dimensions.

WHAT THIS TESTS: This tests whether you understand the mathematical structure of the Gaussian kernel and how linear algebra translates into algorithmic speedups in real image processing pipelines. The interviewer cares if you can move beyond memorizing Gaussian blur and explain why it is fast, how separability works, and how to express concrete complexity.

A GOOD ANSWER COVERS: First, state that a 2D Gaussian kernel G of size K by K is separable because it is the outer product of two 1D Gaussian vectors, meaning G of x comma y equals g of x times g of y. Second, explain the optimization: instead of convolving the image with a K-by-K 2D kernel, you perform two sequential 1D convolutions, one horizontal and one vertical, each of length K. Third, quantify the speedup. For an N-by-N image and a K-by-K kernel, the naive 2D convolution requires roughly N squared times K squared multiplications and additions. After decomposition, the cost drops to roughly 2 times N squared times K operations, which is O of N squared K. Fourth, mention practical implications: this is why large Gaussian blurs are feasible in real-time graphics and computer vision, whereas a non-separable large kernel would be prohibitive.

COMMON WRONG ANSWERS: A major red flag is claiming that any kernel can be decomposed this way. Only kernels that are rank-one matrices are separable, and the Gaussian happens to satisfy this because of the multiplicative property of the exponential function. Another red flag is giving complexity only as O of K squared versus O of K without referencing the image size N squared, since complexity must account for every pixel. Some candidates also confuse separability with sliding-window integral image tricks or box filter approximations; those are valid optimizations but they are not the same thing as exact separability.

LIKELY FOLLOW-UPS: The interviewer may ask how you would prove a given kernel is separable. The answer is to check if the kernel matrix has rank one, which you can verify via Singular Value Decomposition and confirming only the first singular value is non-zero. They may also ask about border handling, such as whether zero-padding or edge replication affects the separability proof. It does not; the separability is a property of the kernel weights, independent of padding mode. Another follow-up is how to approximate a non-separable kernel: you can use SVD to keep the top few singular values and apply multiple separable passes, trading accuracy for speed.

ONE CONCRETE EXAMPLE: Consider a 5-by-5 Gaussian kernel with sigma 1. The naive approach performs 25 multiplications and 24 additions per pixel. Using separability, you first convolve each row with a 5-tap 1D Gaussian, then convolve each column of the intermediate result with the same 1D Gaussian. That is 5 multiplications and 4 additions per pixel for the first pass, and another 5 multiplications and 4 additions for the second pass, totaling 10 multiplications and 8 additions. For a 4K image of roughly 8 million pixels, that is the difference between 200 million and 80 million multiplications, a 2.5x speedup that grows linearly with kernel size.

Source: Wikipedia: Gaussian blur

Read the original → Wikipedia: Gaussian blur

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.