Introducing Kernels Using MATLAB

Опубликовано: 09 Январь 2025
на канале: buckmasterinstitute
980
5

Created and recorded by Yiming Cai, October 2021


Music: Usina (https://lmms.io/lsp/?action=show&file...) by Yure16 (https://lmms.io/lsp/?action=browse&us...) License: Creative Commons

Script:

In previous videos, I mentioned “kernel” when applying Gaussian blur. In this video, I will talk about what a kernel is, and how they are useful for graphics processing.

So let's begin with a quick introduction to the idea of kernel. In this graph, you can see on the left side, we get a 2-d plane with red dots and purple dots. The orange circle in the middle of the graph can separate red dots and purple dots. Now we apply a method, φ((a, b)) = (a, b, a^2 + b^2), the result will be the graph on the right side here. The function φ((a, b)) performed a transformation from R2 → R3. After the transformation of φ((a, b)), we can use a linear method to separate red and purple dots with a 2-d plane.

This method, we call it kernel trick. The idea of kernel trick is to perform a transformation such as φ:X → V. It's not necessary that kernel must change the dimension of input, we can apply any kind of kernels based on what we need. In graphic processing, kernel usually performs a transformation between 2D plane.

(switch to code)

Take the Gaussian kernel I used as an example, by using the SURF function of MATLAB, we can see the shape of the Gaussian kernel. After applying the Gaussian kernel by using imfilter of MATLAB, it performs Gaussian blur to the original image. In graphic processing, once you defined a kernel, which is usually a matrix, and apply convolution to the matrix for the original image, a new image will be built based on the result of the convolution that just applied.

In order to reach the result you expect, you may use different methods to apply different kernels in MATLAB. For example, imfilter is a method that is already built-in MATLAB. You can also use conv2() function directly. Here are examples from the previous video, apply Gaussian kernel and box kernel. Convolution

In this video, we explained what kernel trick is, also the application of kernel in MATLAB. By using kernel function to transform data into the required form of data, you can easily solve problems with easier methods. Hope this video is helpful.