What is a separable filter?
A two-dimensional filter kernel is separable if it can be expressed as the outer product of two vectors. For example, let's look at a Sobel kernel.
s = [-1 0 1; -2 0 2; -1 0 1]
s =
-1 0 1
-2 0 2
-1 0 1
This kernel can be written as a matrix product of a column and a row vector.
v = [1; 2; 1]
v =
1
2
1
h = [-1 0 1]
h =
-1 0 1
v * h
ans =
-1 0 1
-2 0 2
-1 0 1
Associativity of convolution
As it turns out, the matrix product of a column vector and a row vector is equivalent to the two-dimensional convolution of the two vectors.
conv2(v, h)
ans =
-1 0 1
-2 0 2
-1 0 1
This matters because convolution is associative. That is,
(I've used the asterix here to mean convolution.) So if a filter s is separable:
then you can filter with s by filtering first with v, and then filtering the result with h.
Computational advantage of separable convolution
Why would you want to filter this way? Because you can do it faster. Filtering an M-by-N image with a P-by-Q filter kernel requires roughly MNPQ multiplies and adds (assuming we aren't using an implementation based on the FFT). If the kernel is separable, you can filter in two steps. The first step requires about MNP multiplies and adds. The second requires about MNQ multiplies and adds, for a total of MN(P + Q).
The computational advantage of separable convolution versus nonseparable convolution is therefore:
For a 9-by-9 filter kernel, that's a theoretical speed-up of 4.5.
That's enough for now. Next time, I'll write about how to determine whether a filter kernel is separable, and what MATLAB and toolbox functions test automatically for separability.
本文介绍了何为分离滤波器及其在二维滤波中的应用,通过实例展示了如何将一个二维滤波核分解为两个一维向量的外积,并讨论了分离卷积在计算上的优势。

4761

被折叠的 条评论
为什么被折叠?



