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 which equals to , so the frequency response of this system is . Its magnitude (after some easy calculations) is . It is obvious that the frequencies () around , are getting attenuated and the frequencies () around 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 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.
A=imread('superman.jpg'); B=rgb2gray(A); C=size(B); for i=1:1:C(1) for j=1:1:C(2)-1 D(i,j)=B(i,j+1)-B(i,j); end end
To see the image just type “image(D)”. Here’s what you should get;