CS 143 / Project 1 / Image Filtering and Hybrid Images

Hybrid image 1

The process of making hybrid images was fairly simple. First I wrote the filtering algorithm, which works as follows:

Filtering Algorithm

  1. Check filter size to make sure the filter dimensions are odd (so that a clear center is always present)
  2. Pad the image with zeros so that when I am trying to filter pixels on the edges I don't get array out of bounds exceptions. I padded the floor of the filter x dimension divded by 2 horizontally on each side and the floor of the filter y dimension divided by 2 vertically on each side to accomodate the filter size.
  3. Iterate over the image and calculate the weighted average at each pixel according to the filter and its surrounding pixels. Iteration started at the floor(filter_x/2) and floor(filter_y/2) and ended at image_x + floor(filter_x/2) and image_y + floor(filter_y/2) to account for the padding added earlier and ensure that only pixels in the original image are considered as the center pixel of the filter. Output calculated values to a new image (and when indexing into the new image, subtract the offsets so the new image corresponds with the original image passed in).

Originally I wrote the algorithm without actually padding the original image- I simply checked the pixels the filter was iterating over and made it so that if any were out of bounds I used a pixel with 0 values for colors. However, this was extremely slow in Matlab, so I switched to the above method

The next step was filling in the hybrid image algorithm.

Hybrid Image Algorithm

  1. The image loading and filter creation was already taken care of by the support code.
  2. Create a low frequency image of image1 by applying the filter to image1 with the filtering algo I just described.
  3. Create a high frequency image of image2 by applying the filter to image2 w/ the filtering algo I just described and subtracting that from the original image
  4. Create the hybrid image by combining the results of the last two steps
  5. Display the hybrid image at different scales using the provided support script

I also wrote a small utility function that is basically the same as proj1.m. It takes in two strings representing image locations, a suffix to add to results and intermediates, and a cuttoff frequency and outputs hybrid images and intermediates. Its named hybrid.m.

Results

The following are results of using the above algorithms on several images.

High Frequency Images

Low Frequency Images

Hybrid Images

Hybrid Scaled Images