Project 1: Image Filtering and Hybrid Images

Hybrid output example.

This first assignment had the simple requirement of creating a program that can create hybrid images. the program first uses a filter to filter out the high frequences in one image and the low frequencies in another image, then combines the two. The main area of implementation was implementing the function to convolve a filter over an image.

Implementaion

To implement a convolving filter, the filter must be applied to every pixel and it's neighboring pixels. Using a pixel as a starting point, a matrix is created by selecting neighboring pixels around the center until the matrix is the same size as the filter. Once this matrix is created each entry is multiplied by its corresponding entry in the filter. After the multiplication is done all of the results are added together. This value becomes the value of the center pixel in the output image.

The biggest issue with convolving are the pixels on and near the border. Since the center pixel is missing neighbors, then substitue values must be used. I used the most common method, padding the original image with zeros. This solution produces an artifact of very dark borders in the resulting image. A better solution would be to reflect the pixels around the border in to the padding, as discussed in class.

The main math is shown in the code below

				
	% Get neighborhood pixels array
	sub_image = padded_image([i-row_pad_size:i+row_pad_size],[j-col_pad_size:j+col_pad_size]);

	% Multiply/add sub_image and filter and write to out_matrix
	out_matrix(i-row_pad_size,j-col_pad_size,channel_num) = sum(sum(filter.*sub_image));
				
			

The variables i and j are iterations over the number of rows and columns respectively. The variables row_pad_size and col_pad_size are the amounts of padding on the orignal image. This code first creates a sub matrix the same size as the filter around the pixel at i,j. Then multiplies and adds the sub matrix and the filter. This becomes the pixel value at i,j in the output image. This is done for all pixels in the padded original image.

Separate Frequency Images

Low frequencies only for bird picture

High frequencies only for jet picture.

The picture on the left is the result of blurring the original bird image. By convolving a Gaussian filter over the image the high frequencies are removed. The image on the right is the image of the jet with the low frequencies removed. To remove the low frequencies the high frequencies must be removed then the resulting image is subtracted from the orignal image. Below is the code to generate each image then combine them.

				
	low_frequencies = my_imfilter(image1, filter);
	high_frequencies = imsubtract(image2, my_imfilter(image2, filter));
	hybrid_image = imadd(low_frequencies, high_frequencies);
				
			

Results

Low Frequency Image High Frequency Image Hybrid