In this project we wrote our own version of the linear image filtering function imfilter() and used our implementation to create hybrid images by taking the high-frequency portion of one image and blending it with the low-frequency portion of another image.

Image Filtering

To recreate the imfilter() function, first the image has to be padded with either zeros or reflected image content. The actual imfilter() function pads the image with zeros, and so I also padded the surroundings with zeros. The size of the padding depending on the size of the filter. Since the filter needs to place a given image pixel in its center, to make sure edge cases work, the padding needs to be at least half of the filter's length long.


					pad = (max(size(filter))+1)/2 - 1;
					m = padarray(image, [pad pad]);
				

Then it's just a matter of looping through each color channel (for grayscale images, only one color channel while color images have three) and looping through each pixel in every column in every row and applying the filter on each pixel. Each filtered pixel is then mapped to the corresponding location in the output image matrix. The result is a filtered image.

Hybrid Images

Since a hybrid image is the sum of the low-frequency portion of one image and the high-frequency portion of the another image, all that needs to be done is the pass each image through a blurring filter, remove the low frequencies from one of the images (done by subtracting the blurred version from the original version), and add the two together to create the hybrid image.

Results

Images with more detail seem to do better as the high-frequency image, while images with less detail do better as the low-frequency image when combining.

Separate Filtered Images

Low-frequency photos next to high-frequency photos, combined here

Chocolate-Piano
Low: Hershey's Chocolate Bar
High: Piano Keyboard

Cat-Dog
Low: Dog
High: Cat

Bird-Plane
Low: Bird
High: Plane

Fish-Submarine
Low: Submarine
High: Fish

Final Hybrid Images

Final hybrid image, full-size next to smaller size

Chocolate-Piano
Low: Hershey's Chocolate Bar
High: Piano Keyboard

Cat-Dog
Low: Dog
High: Cat

Bird-Plane
Low: Bird
High: Plane

Fish-Submarine
Low: Submarine
High: Fish