In this project, image filtering techniques were utilized to implement a hybrid image.
This project was developed for Computer Vision class Spring 2019.
The dataset is simply 8 images that can be considered as 4 pairs of images as following:
- Dog and Cat
- Motorcycle and Bicycle
- Plane and Bird
- Fish and Submarine
There are 5 different filters used in this part as following:
- Identity filter: which basically output the same image.
- Small blur filter: which removes the high frequency components from the image.
- Large blur filter: which does the same as small blur filter but more aggressively.
- Sobel filter: which is meanly used for edge detection.
- Laplacian filter and high pass filter: which does the opposite function of the blur filter as it passes the high frequencies.
The output of each filter on the cat image is as following:
-
Get the dimensions of the filter and the image.
-
If the reminder of the rows or the columns with 2 is equal to zero, throw an error.
-
Pad the image using padarray function with the size equal to the ceil of both the number of rows/2 and the number of columns/2, in both directions.
-
Assign the last index of both the rows and the columns to be the number of rows of the filter – 1 “row_index_end” and the number of columns – 1 “column_index_end”.
-
convolution_row_index = 1, and the same with columns.
-
For rows = 1: number of rows in the image
- For columns = 1: number of columns in the image
- Make a small image that will be convoluted which has boundaries equal from the number of the current row to number of the current row + last_index_rows, the same with columns, and for all channels (either gray or color image are supported).
- For each channel
- Compute the convoluted image (the output) by using the index of the rows as the convolution_row_index, the same with columns, and loop over the channel.
- The output should be computed by getting the sum both times ( in rows and columns) of the element wise multiplication between the small image and the filter.
- Restart the convolution_column_index to be 1.
- Increment the convolution_row_index by 1.
- For columns = 1: number of columns in the image
-
The output of this nested loop should be the convoluted image.
The following figure compares the output of the built-in MATLAB function with the implemented time-based function and with the FFT-based function.
Hybrid images can be constructed by using 2 images with respectable shapes and using a low pass filter on one image and a high pass image on the other one.
- Use the large blur filter on the first image to get the low frequencies of the first image.
- Use the large blur filter on the second image and subtract it from the second image to get the high frequencies.
- Add the two processed images together to get the hybrid image.