CS 143 / Project 1 / Image Filtering and Hybrid Images

Hybrid image of between a cat and dog.

Hybrid images are created by overlaying the high-frequency aspects of one image onto the low-frequency images of another. This requires a means to filter images to extract the high and low frequency features of an image. MATLAB provides a function to do this, imfilter(i, f), which applies a filter f to image i. my_imfilter(i, f) was written to perform the same function.

my_imfilter()

my_imfilter operates by first padding the image (the new pixels are filled by reflecting the original over the boundary), and then looping through every pixel of the unpadded image, applying the filter. To apply the filter, multiply each pixel's intensity value by each value of the filter, elementwise. The filtered image's new pixel value is the result of the sum of this element-wise product. This is done to each RGB value, if in color, or just once, if in grayscale.

Identity filter

Box filter (average)

Box filter (average) on only the red channel

Gaussian filter

High pass filter (1 - blurred)

LaPlacian filter.

Sobel filter

Looping, however, is an unoptimized operation in MATLAB, and runtime could be greatly improved by rewriting the operation in terms of matrices. How this might happen is unknown.

Obtaining the Lower Frequencies of an Image

The lower frequencies of an image are its overarching features, mostly larger regions of color and intensity. To obtain these is relatively simple. Blurring the image will remove the higher-frequency features, leaving the lower-frequency ones behind. The filter applied to the image is a Gaussian filter, the strength of which is determined by its standard deviation, here called sigma.

Graph of the Gaussian Filter

Low Frequencies as obtained by the Gaussian filter.

Obtaining the Higher Frequencies of an Image

The higher frequencies of an image are best understood as its details. To obtain the details, subtract the low-frequency images from the original image.

1 - the Guassian Filter

High Frequencies as obtained by subtracting the Gaussian image. (0.5 intensity added to each pixel to make the image bright enough to display)

Creating Hybrid Images

In order to combine the low and high frequency images, it was as simple a matter as to add them together.

More Examples

The following have been subjected to bilinear downsampling to simulate distance. Each one has its given sigma value for both the high and low frequencies.

Hybrid Cat and Dog: σh=7, σl=7

Hybrid Submarine and Fish: σh=7, σl=2

Hybrid Plane and Bird: σh=8, σl=10

Hybrid Cotton Candy and Quasar: σh=8, σl=10

Hybrid Turtle and Galaxy: σh=5, σl=10