Project 1: Image Filtering and Hybrid Images

For this project, I implemented an image filtering function mimicking the function of Matlab's imfilter. I then used this filtering function to generate a few hybrid images to demonstrate the function of low- and high-frequency signals in images.

Image Filtering

The image filtering portion of this project was fairly straightforward. my_imfilter first determines whether the input image is color or grayscale by measuring the size of the image matrix along its third dimension; a size of 3 indicates an RGB image, with anything else indicating that the image should be treated as grayscale. Then, the function pads the image's width and height by half of the corresponding dimensions of the input filter. If the image is RGB, the function creates a separate padded array for each color channel and treats each as a separate image for the filtering process. This padding is done using padarray with the 'symmetric' setting, making the pad values reflected from the image itself.

After padding the image array, my_imfilter convolves the filter array with the padded image array, or with each padded array if the original image was RGB. This process is completed by first creating one zero-value array with the dimensions of the original image for each padded array. The function then cycles through each index of these zero-value arrays, sets the origin of the filter matrix at the corresponding indeces of the padded array, and sets the entry of the new matrix equal to the partwise product of the padded image array and filter array. Below is a test image and the images my_imfilter created by convolving the image with a box filter and wiht a horizontal Sobel operator.

Hybrid Images

As instructed, hybrid images were created for this project starting with two images with closely-aligned features. One image was blurred with a gaussian filter in order to eliminate high frequency signals, and the other was blurred with the same filter and then subtracted from the original image to leave only high frequency information.

These images were then summed to produce the final hybrid images.




For each of these hybrid images, the image to supply the low-frequency information and the image to supply the high-frequency information was chosen by trial and error to determine which arrangement produced a more "convincing" hybrid image, as was the choice of cutoff-frequency used to create the gaussian filter.