Project 1: Image Filtering and Hybrid Images

Part 1: Image Filtering

The first part of this assignment required coding a method which applied a linear filter with odd dimensons to a provided image. For each of the color channels in each of the image's pixels, a dot product was calculated for the entire neighborhood of the pixel that had the same dimensions as the filter. The result would be varying processes performed on the image.

A test case file was used to test the method with various different filters. The first filter was an identity filter which produced an image identical to the one provided to the function. The next filter applied was a small box filter which induced a small blur and removed some of the image's high frequencies. The next filter applied induced a significantly larger blur. This was performed by applying Gaussian blurs in the x and y directions. Next up, a Sobel filter was used to extract edges which were due to horiontal changes in pixel intensity. Also, a Laplacian filter was used to find edges in an image by measuring gradients in pixel intensity. Finally, a high-pass version of the image was generated by subtracting the light blur image from the original image.

Here's an example below:

Original image:

original


identity

Identity Image

blur

Blur Image

high-blur

High Blur Image

sobel

Sobel Image

laplacian

Laplacian Image

high-pass

High-Pass Image

The process was performed by taking a section of the image that was the same size as the filter and surrounded each pixel. The dot product of this subsection and the filter was calculated for each pixel.

Example:

3x3 section of image

47 123 44
0 14 66
78 24 93

3x3 Sobel filter

-1 0 1
-2 0 2
-1 0 1

The new value for the center pixel of this section would be:

(47 * -1) + (123 * 0) + (44 * 1) + (0 * -2) + (14 * 0) + (66 * 2) + (78 * -1) + (24 * 0) + (93 * 1) = 144

When dealing with a border pixel, it is clear that the pixel's surrounding neighborhood will fall off the edge of the image. In such cases, I chose to pad the border of the image with 0's that would be used in the calculation of the dot product. The hardest part of the assignment was finding out how to do this padding. I ultimately figured that the best way to do this task was to use Matlab's padarray() method to surround the image with zeros for the sake of calculating the dot product. The task of filtering was then performed by cutting out sections of the image corresponding to each pixel and then calculating dot products for each of the three color channels.

Part 2: Creating hybrid images

The second part of the assignment involved using image filters to create hybrid images which have different perceptions from different distances. The process involved removing the low frequencies present in one image and the high frequencies in another and then adding both of the modified images to create the hybrid image. The low-frequency image was created by applying convolutions with a Gaussian filter through the previously coded my_imfilter() function. The second image also had the Gaussian filter applied, and its low-frequency version was subtracted from the original image to yield a high-frequency image. For each pair of images, we had to specify the cutoff frequency, the standard deviation in pixels of the Gaussian blur. This dictated just how much of high frequency was removed by the Gaussian filter. The higher the cutoff, the more blur the filter created in the image. For many of the provided test cases, I found that low standard deviations were needed because the low-frequency images were not too detailed.

Here are some examples below:

Frequency used Image 1 Image 2 Low frequencies of Image 1 High frequencies of Image2 Gradual progression for different perceptions
7 dog cat blurred-dog high-cat pussydog
4 einstein marilyn blurred-einstein high-marilyn marilynstein
3 plane bird blurred-plane high-bird birdplane
2 submarine fish blurred-submarine high-fish fishmarine
3 motorcycle bicycle blurred-motorcycle high-bicycle motorbike
5 bauer tiger blurred-bauer high-tiger tigerbauer
4 bauer tiger blurred-potter high-maul darthpotter

On the whole, I feel that I was successful for the most part in producing the hybrid images. One does need to do some close observation for some hybrid images to notice the difference in perceptions. For some of the hybrid images, I could have adjusted the cutoff frequency slightly better to form an image that looked more clearly hybrid rather than resembling only one of the images involved. As for the test cases for the image filtering file, I felt that the filtering was performed successfully. For the some of the different cases that I used for the first part, the Sobel filter image did not look perfect due to the presence of some bright colors, but this could have to do with the presence of some noise in the images I used. In my opinion, the actual math involved in the filtering was appropriately executed due to the use of zero-padding for the border pixels and the extraction of individual sections for the sake of computing the dot product.