Project 1: Image Filtering and Hybrid Images

Introduction

This report discusses the implementation and results of the hybrid images assignment for CS6476. Hybrid images are images in which the low-frequency and high-frequency components of two different images are combined. This amalgamation produces an image that appears to change, to the human eye, when viewed at short or long distances. To create a hybrid image, one uses convolved filters to remove low- and high-frequency components from two images, respectively, then combines the two filtered images. In particular, this paper describes the proposed algorithm, presents implementation details, and displays the resulting hybrid images from the algorithm.

Implentation of 2-D convolution

This section discusses the implentation of the required 2-D convolution algorithm and the results achieved with the given testing code.

Image Filtering Implementation

Our 2-D image filter algorithm has two steps:

  1. Padding
  2. Convolution

To appropriately pad the given image, we took advantage of the built in MATLAB function padarray(), which allowed for the padding of the image. As discussed in class, we utilized the symmetric keyword for this function to mirror the image along the edges, preventing large sections of zeros. The MATLAB implementation is shown below.

	
		% image -- the provided image
		% filter_n -- height of filter
		% filter_m -- width of filter

		padding_n = (filter_n - 1)/2
		paddimg_m = (filter_m - 1)/2
		padded_image = padarray(image, [filter_n filter_m], 'symmetric')
	

Convolution Implementation

We implemented our convolution in the following way:

	

		% output -- the output image

		k = (-padding_n):padding_n;
		l = (-padding_m):padding_m;

		for channel = 1:3
		    for n_ = (1 + padding_n):(n + padding_n)
		        for m_ = (1 + padding_m):(m + padding_m)
		            output(n_ - padding_n, m_ - padding_m, channel) = sum(sum(filter .* padded_image(n_ + k, m_ + l, channel), 2));
		        end
		    end
		end
	

This method takes advantage of MATLAB's vectorization and built-in functions, making the test files run relatively quickly. In particular, we vectorize the inner array indexing by preallocating an n x m size array, based on the filter's size. Then, we utilize MATLAB's quick, built-in sum function in order to efficiently execute the convolution sum across the red, green, and blue color channels. Utilizing these optimizations, the test file ran in 15 s, on average.

Test Results

Table 1 shows the results of the provided testing file. All images were filtered as expected. Additionally, the use of symmetric padding improved the quality of the image filter under larger images. For comparison, Figure 1 shows a large, blurring filter convolved over a zero-padded image. Conversly, Table 1 displays the same image with symmetric padding. Visually, the image in Table 1 appears to be blurred more uniformly and lacks the dark regions present in Figure 1.

Figure 1: Large, blurred image with zero-padding

Table 1: Picture results of developed convolution algorithm on provided test file with zero padding

Hybrid Image Creation

Having completed the image filtering function in MATLAB, we moved onto the implementation of the hybrid image algorithm. In particular, this algorithm involves filtering the low- and high-frequency components of two separate images, respectively; then, the algorithm combines the two images. This result yields an image that appears to be the high-frequency image from afar and the low-frequency image, when viewed closely.

Low- and High-frequency Filtering

Initially, we tested the high- and low-pass filtering of an image. In particular, we utilized the provided cat and dog images as the high- and low-frequency images, respectively. That is, the high-pass filter operated on the cat image, and the low-pass filter operated on the dog image. Figures 2,3 show the results of this filering process.

Figure 2: Low-frequency dog image created from a low-pass filter operation and convolution alorithm

Figure 2 shows the effect of a low-pass filter on an image of a dog. This filter is convolved with the image and produces a bluring effect. Figure 3 displays the effects of a high-pass filter on an image of a cat. This filter removes blur, leaving sharp edges (i.e., high frequencies).

Figure 3: Effect of a high-pass filter on image of a cat

Both Figure 2 and Figure 3 were created using the following cuttoff value for the Gaussian blur:

	
		cuttoff_frequency = 5
	

Combining the high- and low-frequency images resulted in the hybrid image displayed in Figure 4

Figure 4: Hybrid image created from a combination of low- and high-frequency images

Figure 5 displays the full effect of the hybrid image combination. Images to the left in Figure 5 closely resemble a cat, while those to the right more closely resemble a dog. Figures 5, 6 show additional hybrid images.

Figure 4: Cat/Dog hybrid image created from a combination of low- and high-frequency images

Figure 5: Fish/submarine hybrid image created from a combination of low- and high-frequency images

Figure 6: Motorcycle/biycle hybrid image created from a combination of low- and high-frequency images

Conclusions

In this project, we implemented a convolution algorithm for the purposes of producing hybrid images. In particular, these images are created by combining low- and high-frequency images together to form a so-called hybrid image. This new image appears to be the low-frequency image from afar and the high-frequency image when viewed nearby. By developing an efficient convolution, we successfully fulfilled the given test cases and successfully created several hybrid images.