The purpose of this assignment was to write an image filtering function and use it to create hybrid images. Hybrid images are essentially the high frequencies of one image added to the low frequencies of another image, resulting in an image that looks different depending on viewing distance.
The algorithm I used to filter an image is simply taking a weighted average (using the filter as the weights) of the pixels in the source image to get the pixel value of the final image. The source image is padded with zeros to handle the case of pixels in the final image that are near the edge.
I used matlab array slicing to make my code simpler and more efficient. I looped over every element in the filter, and summed the final image array with the padded source image subarray that was correctly offset (based on the offset of the filter element) and multiplied by the filter element value.
For creating hybrid images the algorithm was simple: simply add the low frequencies of one image with the high frequencies of another. To get the low frequencies, we blur the image. To get the high frequencies, we blur the image (get the low frequencies) and subtract that blurred image from the original image (leaving the high frequencies).
function filter(img, filter)
final_img is same dimensions as img but all zeroes
pad img with zeroes
for i in filter width
for j in filter height
final_img = final_img + img(offset window)*filter(i,j)
Some example hybid images created using my filter and hybrid image functions:
|
|
|
|
|
|