CS 143 / Project 1 / Image Filtering and Hybrid Images

Filtering

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

The algorithm for filtering handles edge cases by assuming a black border of a sufficient width around the image. However, in implementing the algorithm I simply used an if statement to check if the pixel we are checking the value of is in the image. If it is not, it will not contribute to the final value of the pixel we are applying to the filter to because we multiply the filter value by the pixel value. Black has a pixel value of 0, so the black border will not add to the value of the edge pixels. This means that filters with dimensions greater than 1 will darken the edges of the image.

To make the filtering faster, I put the loop that iterates over each chanel inside of the if statement so that the if statement only needs to be executed once for each pixel we want to check the value of instead of once per pixel per chanel. I also avoid using a temporary variable to store the sum of the element wise multiplication for each pixel. Instead I use the output as the counter. Before making these two optimizations running proj1_test_filtering.m too several minutes, but now it takes about five seconds.

The results of running proj1_test_filtering.m are shown below.

Original image Identity image Slightly blurred image
More blurred image Sobel image: Shows horizontal gradients Laplacian image: shows high frequencies in the image
High pass image: shows high frequencies by subtracting the low frequencies from the original image

Hybrid Images

To create hybrid images I take the low frequencies of both input images by using a gaussian filter to blur them. I use the same filter for both images. Then I subtract the low frequencies of the second image from itself to get just the high frequencies in that image. Then I sum the values of the low frequency version of the first image with the values of the high frequency version of the second image.

Examples of hybrid images the program created are below.

Cat and Dog, with a standard deviation of gaussian blur of 7

High frequencies from the cat image. Low frequencies from the dog image.
Scaled versions of the hybrid image.

Cat and Dog reversed, with a standard deviation of gaussian blur of 7

High frequencies from the dog image. Low frequencies from the cat image.
Scaled versions of the hybrid image.

Bicycle and Motorcycle, with a standard deviation of gaussian blur of 9. The initial blur of 7 made the bicycle dominate the motorcycle more than I liked.

High frequencies from the motorcycle image. Low frequencies from the bicycle image.
Scaled versions of the hybrid image.

Bicycle and Motorcycle reversed, with a standard deviation of gaussian blur of 5. The initial blur of 7 made the bicycle dominate the motorcycle more than I liked. This one was hard to get right, because the bicycle has a well defined shape that makes the high frequency version of it very well defined as well. So, a lower cuttoff for the blur would disguise it better when we want to see the motorcycle, but the motorcycle is more "blobby", so blurring it too much makes it unrecognizable. It would probably work better to have two different blur values, one for each image.

High frequencies from the bicycle image. Low frequencies from the motorcycle image.
Scaled versions of the hybrid image.

Fish and Submarine, with a standard deviation of gaussian blur of 7.

High frequencies from the submarine image. Low frequencies from the fish image.
Scaled versions of the hybrid image.

Einstein and Marilyn, with a standard deviation of gaussian blur of 7.

High frequencies from the Einstein image. Low frequencies from the Marilyn image.
Scaled versions of the hybrid image.

Einstein and Marilyn reversed, with a standard deviation of gaussian blur of 5. The initial blur of 7 made Einstein less recognizable.

High frequencies from the Marilyn image. Low frequencies from the Einstein image.
Scaled versions of the hybrid image.