Photo application; A simple highpass filter

Suppose you have an image (in our case, Superman) and you apply a highpass filter on it. What do you expect to happen? Well, the outlines are going to get enhanced. Let’s find out why and how can we implement such a filter using MATLAB.

The reason is the rapid variation of the samples in the outer edges of the picture. Take a look at the area near Superman’s cape. It is mostly red or black until, suddenly, it becomes white. This is a high frequency area.

In order to accomplish our goal of exposing the outer edges of this drawing we will use the system y[n]=x[n-1]-x[n]. Let me prove why this is going to work. Taking the Fourier transform we have $\mathcal{F}(y[n])=\mathcal{F}(x[n-1])-\mathcal{F}(x[n])$ which equals to $\mathcal{Y}(\mathrm{e}^{j*\omega})=(\mathrm{e}^{-j*\omega}-1)*\mathcal{X}(\mathrm{e}^{j*\omega})$, so the frequency response of this system is $\mathcal{H}(\mathrm{e}^{j*\omega})=(\mathrm{e}^{-j*\omega}-1)$. Its magnitude (after some easy calculations) is $|\mathcal{H}(\mathrm{e}^{j*\omega})|=\sqrt{2*(1-\cos{\omega})}$. It is obvious that the frequencies ($\omega$) around $\kappa*2*\pi, \kappa \in \mathbb{Z}$, are getting attenuated and the frequencies ($\omega$) around $(2*\kappa+1)*\pi, \kappa \in \mathbb{Z}$ are getting amplified.

Below you can see the MATLAB implementation of the system discussed earlier. Because the equation is of one variable and the image of three (in general, it is a $n*m*3$ matrix) we should make a couple of transforms before we can apply our system. Firstly, we reduce the original matrix from 3 dimensions to 2 with the rgb2gray function. Now, we have a usual 2-D matrix we can work on. Next, we apply our equation in each row. Unfortunately, we are doomed to lose some quality since we always need two columns (the one we are during the second for and the next one) and the last column is ignored.