Filter to Smoothen

https://behappy.me/generator


For our third exercise, we were introduced to Convolution Kernels and how it is used for image enhancements. According to the lecture, convolution means determining a pixel value by getting the average of the weighted values of the pixels in its neighborhood. Convolution is done by putting a kernel on top of every pixel. A kernel can also be called a "filter mask" or a "convolution kernel". It's a square matrix of values used in convolution and usually, it is 3x3. 

How will we know the new pixel value given a kernel and an image? In the example below, let the highlighted pixel (which is 8) be the pixel of interest. This pixel will be the one that we will enhance using convolution.

The pixel of interest will be equal to the average of weighted sums of the product of the kernel value and the pixel value in the same location. This is called mean filtering. Thus, the solution will be like this:

sum = 1(4) + 1(3) + 1(8) + 1(6) + 1(8) + 1(4) + 1(5) + 1(12) + 1(7)
sum = 57
sum_kernel_values = 9
average = sum / sum_kernel_values
average = 57 / 9
average = 6.33 = 6


resulting image
Convolution is doing this for all pixels in an image. In the examples, we were presented three kernels. One for the normal blur, the Gaussian blur, and one for sharpening an image. We were also given two sample images, aw.png and test.jpg.


aw.png
test.jpg

When the following kernels were applied on the sample images, the results were the following:

application of the kernels on aw.png
application of the kernels on test.jpg

Based on the results, the first kernel was the normal blur, while the second kernel sharpened the image, while the last kernel was the Gaussian blur. Notice that the Gaussian blur was more blurred than the normal blur and it was caused by the variety of values present in kernel used for Gaussian blur. 

For our exercise, we were tasked to do a median filtering on the following images with the kernel size of 15.

In median filtering, instead of computing for the mean, values of pixels were arranged in an increasing or decreasing manner. And the pixel of interest will be equal to the middle value of the ordered pixel values.

Since ordering of pixel values is needed, a sorting algorithm is used. Particularly, we used insertion sort. Also, we did a swap function to improve modularity of the program. In the exercise, we used a colored image so we passed the specific channel into the filter function and put the pixel values under the kernel in a one dimensional array and then passed the array into the sorting function. After doing the filter per color channel, we assigned it into an output image and printed it.

aw.png and test.jpg before and after using median filtering

In comparison to the three (3) kernels a while ago, median filtering intensely blurred aw.png and test.jpg. Another thing that should be taken into consideration is that median filtering takes a lot of time because it sorts first the values of the pixels concerned so the efficiency of median filtering would be based on the sorting algorithm that will be used. It is said that it would be more effective on gray scale images. Also, I think it would be of more use in noisy images. 



Comments