Accelerating the pace of engineering and science

isfilterseparable

Determine whether filter coefficients are separable

Syntax

S = isfilterseparable(H)
[S, HCOL, HROW] = isfilterseparable(H)

Description

S = isfilterseparable(H) takes in the filter kernel H and returns 1 (true) when the filter is separable, and 0 (false) otherwise.

[S, HCOL, HROW] = isfilterseparable(H) uses the filter kernel, H, to return its vertical coefficients HCOL and horizontal coefficients HROW when the filter is separable. Otherwise, HCOL and HROW are empty.

Input Arguments

 H H numeric or logical, 2-D, and nonsparse.

Output Arguments

 HCOL HCOL is the same data type as input H when H is either single or double floating point. Otherwise, HCOL becomes double floating point. If S is true, HCOL is a vector of vertical filter coefficients. Otherwise, HCOL is empty. HROW HROW is the same data type as input H when H is either single or double floating point. Otherwise, HROW becomes double floating point. If S is true, HROW is a vector of horizontal filter coefficients. Otherwise, HROW is empty. S Logical variable that is set to true, when the filter is separable, and false, when it is not.

Examples

Determine if the Gaussian filter created using the fspecial function is separable.

```% Create a gaussian filter
two_dimensional_filter = fspecial('gauss');
% Test with isfilterseparable
[isseparable, hcol, hrow] = ...
isfilterseparable(two_dimensional_filter)
```

When you run this example, notice that hcol*hrow equals the two_dimensional_filter. This result is expected for a Gaussian filter.

expand all

Separable two dimensional filters

Separable two-dimensional filters reflect the outer product of two vectors. Separable filters help reduce the number of calculations required.

A two-dimensional convolution calculation requires a number of multiplications equal to the width $×$ height for each output pixel. The general case equation for a two-dimensional convolution is:

$Y\left(m,n\right)=\sum _{k}\sum _{l}H\left(k,l\right)U\left(m-k,n-l\right)$

If the filter H is separable then,

$H\left(k,l\right)={H}_{row}\left(k\right){H}_{col}\left(l\right)$

Shifting the filter instead of the image, the two-dimensional equation becomes:

$Y\left(m,n\right)=\sum _{k}{H}_{row}\left(k\right)\text{ }\sum _{l}{H}_{col}\left(l\right)\text{ }\text{ }U\left(m-k,n-l\right)$

This calculation requires only (width + height) number of multiplications for each pixel.

Algorithms

The isfilterseparable function uses the singular value decomposition svd function to determine the rank of the matrix.