# How to Classify Image Filter as Low Pass Filter (LPF) or High Pass Filter (HPF)?

I am currently reading on the topics of image filtering and convolution kernels. While the process of convolution is clear to me, I do not understand, how one arrives at the statement, that a certain filter is a low or a high pass?

How can one derive that? For example, if one averages the value of a pixel respecting its surrounding pixels, does that for all pixels, then each pixel would have a value between the minimum and the maximum value of the previous image. It treads low values and high values equally, however literate often states, that it is a low pass filter.

For that specific case I found this question here. Reading it, however didn't help me, as I seem to lack something to see how these arguments are correct and intuitive. Thus I hope, that a more mathematical approach (can be a general one), would benefit me.

• You might find this question useful as well. How familiar are you with digital filters in the time domain (i.e. Simple, one dimensional filters)? – A_A Sep 3 '18 at 12:53
• @A_A, not too familiar, I am afraid. I have a maths/computer science background, so a lot of material that is very basic to for example to electrical engineers is fairly new/strange to me at the moment :/ – Imago Sep 3 '18 at 14:08
• @Imago You might find this helpful as well. – datageist Sep 3 '18 at 17:30

Welcome to DSP Community.

## General

We assume 2 types of filters: LPF or HPF.

## Classifying Filter Type

Usually, if it is a well planned LPF and well Planned HPF a simple test will do.
Calculate the sum of all coefficients.
The sum of the coefficients is the first element of the DFT of the signal.
It means it is the DC gain and well behaved LPF has gain of 1 and well behaved HPF have DC gain of 0.

So sum the coefficients and:

• If the sum is $1$ then this is an LPF.
• If the sum is $0$ then this is an HPF.

Pay attention that those method can't differentiate between HPF and Band Pass or between LPF and Band Stop.

The more general method is to look on its DFT Spectrum to see its behavior.

## Converting Filter Type

There is very intuitive formula - ALL_PASS_FILTER = LPF_FILTER + HPF_FILTER.
It's not accurate but this is the idea.

Be more accurate in the Frequency Domain All Pass Filter is a filter which has value of 1 for any frequency.
Assuming we have LPF Filter then HPF_FILTER = ALL_PASS_FILTER - LPF_FILTER.
In the spatial domain it means $h \left[ n \right] = \delta \left[ n \right] - l \left[ n \right]$.

Where $\delta \left[ n \right]$ is the filter with 1 in its origin and $0$ anywhere else.

In your case $\delta \left[ n \right] = [0, 0, 0, 0, 1, 0, 0, 0, 0]$.
So the HPF Filter becomes $h \left[ n \right] = \delta \left[ n \right] - l \left[ n \right] = [-1/9, -1/9, -1/9, -1/9, 8/9, -1/9, -1/9, -1/9, -1/9]$.

The decision whether a 2D LTI filter is LPF, BPF, HPF or APF is made according to its frequency domain characteristic; i.e., its frequency response $H(\omega_1, \omega_2)$ which is the discrete-time Fourier transform of its impulse response $h[n_1 , n_2]$

$$H(e^{j\omega_1},e^{j\omega_2}) = DTFT \{h[n_1,n_2] \}$$

Here the filter being LTI (linear time invariant) is important because only such filters posses a fixed impulse response of the form $h[n_1,n_2] = \mathcal{T}\{\delta[n_1,n_2]\}$, where $\delta[n_1,n_2]$ is the discrete-time unit impulse.

The very ideal rectangular filters are then defined as: (in all cases $-\pi< \omega < \pi$)

$$h_{LPF}[n_1,n_2] \longleftrightarrow H(e^{j\omega_1},e^{j\omega_2}) = \begin{cases}{1~~~,~~~|\omega_1| < \omega_{c1},|\omega_2| < \omega_{c2}, \\ 0 ~~~,~~~~\text{otherwise} }\end{cases}$$

$$h_{HPF}[n_1,n_2] \longleftrightarrow H(e^{j\omega_1},e^{j\omega_2}) = \begin{cases}{1~~~,~~~|\omega_1| > \omega_{c1},|\omega_2| > \omega_{c2} \\ 0 ~~~,~~~~\text{otherwise} }\end{cases}$$

$$h_{BPF}[n_1,n_2] \longleftrightarrow H(e^{j\omega_1},e^{j\omega_2}) = \begin{cases}{1~,~ \omega_{c1}<|\omega_1| < \omega_{c2},\omega_{d1}<|\omega_1| < \omega_{d2} \\ 0 ~,~\text{otherwise} }\end{cases}$$

These are all defined as zero phase filters. Their impulse responses are non-causal and infinetely long and given by the following inverse discrete-time Fourier transform:

$$h_i[n_1,n_2] = \frac{1}{4\pi^2} \int_{-\pi}^{\pi} \int_{-\pi}^{\pi} H(e^{j\omega_1},e^{j\omega_2}) e^{j\omega_1 n_1} e^{j\omega_2 n_2} d\omega_1 d\omega_2$$

Practical approximations to their magnitudes (including nonzero phases), are obtained from these ideal prototypes in IIR or FIR forms by applying some standard techniques.

FIR approach utilizes windowing or sort of LSE, equiripple approximations in which the final filter impulse response is

$$h[n_1 , n_2] = w[n_1 , n_2] h_i[n_1 , n_2]$$

while the IIR approach can benefit from analog filter design prototypes such as Butterworth, Chebyshev, elliptic designs through bilinear transform etc.

It is important to re-emphasize that the filter is defined (its sepcifications are given) in the frequency domain, then its impulse response is derived in time domain as a consequence.

Exceptions happen, where time domain characteristics of the filter such as rise time, overshoot, derivates etc. are considered in addition to frequency domain specifications. For example a very important class of image filters; edge detectors such as Sobel, Canny, etc, are designed purely in time domain, however note that their ouputs are machine readble as opposed to those frequency shaping filters whose outputs are human readable.

Note that as other answers outlined, there are some properties of the impulse response which can be used to decide whether it's a LPF or HPF in a simple manner but not much else can be inferred without computing the frequency response.

• I'm not sure about the history, yet I feel that Sobel or Prewitt filters were designed out of computation simplicity, more than in frequency – Laurent Duval Sep 3 '18 at 21:33
• well, lets say we are talking about frequency selective LTI filters... You know there are so many different filters for so many different purposes... Sobel is an edge detector and as such it's designed with a time domain Laplacian approach as you state. But its purpose is quite distinct from frequency selective filtering. Yet you can still analyse its frequency response and state that it has a high pass characteristic. So even though you design it in time domain, you shall still use its frequency response to classify it as HP type. (yes you can predict this from its time equation too). – Fat32 Sep 3 '18 at 21:41
• I will also add this to the exception examples, thanks! @LaurentDuval – Fat32 Sep 3 '18 at 21:43

Since the filters are linear, you can check their behavior against some images whose filtered versions are easy to compute. Multiplies are complicated, so images with only $\pm 1$ valued pixels are great (only adds in the convolution). Simple operations cannot tell you exactly what a filter is, they only give you some hints, that ought to be checked in Fourier.

The most low-pass image $L$ is constant, so all pixels are one. The corresponding value is $v_L = \sum_{m,n} h[m,n]$. If $v_L \neq 0$ (some filters can be normalized wrt energy), notably if $v_L =1$, a non-zero constant image remains non-zero. So the filter is not $0$-cut.

The most high-pass images $H$ have alternating $\pm 1$ in a quincunx scheme. The corresponding value is either $v_H = \sum_{m,n} (-1)^{m+n}h[m,n]$ or the opposite. If $v_H \neq 0$, it is not high-cut.

If $|v_L| > |v_H|$, the filter tends to better preserve low-frequencies than high ones (and conversely). If $|v_L| \approx 1$ while $v_H$ is much smaller, this hints at a low-pass behavior, especially if all $h[m,n]$ are positive. If $|v_H| \approx 1$ while $v_L$ is much smaller, this hints at a high-pass behavior, especially if $h[m,n]$ have alternating signs.

You can also check if the filter is low-pass along rows and high-pass along columns (and conversely), typical of horizontal and vertical edge filters. For that, try alternating rows (or columns) of $1$ and $-1$. This amounts to testing values $v_R = \sum_{m,n} (-1)^{n}h[m,n]$ or $v_C = \sum_{m,n} (-1)^{m}h[m,n]$.