Created and recorded by Yiming Cai. October 2021
Music by Armin Heller, see https://lmms.io/lsp/?action=show&file..., / twilight-area and https://creativecommons.org/licenses/...
Outline
Introduction to the filter in Matlab
Sharpening filter
Gaussian blur
Box filter
Recap
Script
Today, image filtering is widely used. In many image processing apps, filters such as sharpening and Gaussian blur are very popular. In addition to daily applications, image filtering also plays a big role in information transmission and avoiding redundant information. In this video, I will teach you how to use Matlab to implement sharpening, Gaussian blur and box filter.
Firstly, I want to introduce the Gaussian filter. If you watched the previous video about edge detection, I have used the Gaussian kernel for noise removal. The Gaussian kernel is a kernel with the shape of a Gaussian curve, or you may call it normal distribution. In Matlab, defining a Gaussian kernel is very easy.
gaus = fspecial(‘gaussian’, 37, 8)
37 stands the size of gaussian kernel, while default size is 5, and 8 stands the standard deviation.
The most common way of using Gaussian kernel in Matlab now is to call the function
imgaussfilt(A)
A is a variable for image.
However, I am using this fspecial to show you what Gaussian kernel actually looks like.
Now let’s use surf function
surf(gaus)
And this is how our Gaussian kernel looks like.
Let’s import our image now.
image = imread(‘image.png’)
image = im2double (image)
imshow(image)
And apply the Gaussian kernel
imgaus = imfilter(image, gaus)
imshow(imgaus)
This is how the image looks like after applying the Gaussian kernel.
We can change the results by changing the size or standard deviation of Gaussian kernel, but noticed that it’s better to keep the size in odd number.
Let’s look at the sharpening now.
First thing before sharpening is
imshow(abs(image-imgaus))
So we can see, the picture looks like edge of our original picture. And the idea of sharpening I want to use is to emphasize the edge.
imsharp = image + (image-imgaus)
You can also multiply the (image-imgaus) by 2, and then the image will be more “sharp”
Let's see what the image looks like now
imshow(imsharp)
Last kernel I want to introduce is the box kernel. If you define it by using matrix, you will notice that it’s very funny:
box = ones(31)
An N * N matrix filled by 1’s is what the box kernel actually looks like.
And let’s normalize the kernel
box = box / sum(box(:))
Since the box kernel is a two dimensional matrix, here we only use the gray image
imbox = conv2(rgb2gray(image), box)
imshow(imbox)
This is our image after applying box kernel.
In this video, we talked about how to use the Gaussian kernel to perform blur and sharpening, also we briefly introduced the box kernel. They are very useful when you want to filter an image, and are also commonly used in real life. Hope this video is helpful.