Example of a hybrid image.
The goal of this project is to make an image filter processing function and use it to create hybrid images by combining two different images by applying low and high frequency filters respectively on each image and adding them together. If this hybrid image is viewed up close, the high frequency image is visible. However, as you move further away, the low frequency image gets clearer. An example of such a picture can be seen to the right. From up close, the cat is prominent but as you move further away the dog becomes more prevalent. The function I coded works with both greyscale and color images. However it only works on filters with odd sized dimensions to avoid ambiguity in selecting the center (most dominant) pixel.
padded_image = zeros(height, width);
for i = 1:image_height
for j = 1:image_width
padded_image(i + middle_height - 1, j + middle_width - 1) = image(i, j, k);
end
end
function filtered = filter_func(i, j)
start_height = i - middle_height;
start_width = j - middle_width;
filtered = 0;
for x = 1:filter_height
for y = 1:filter_width
filtered = filtered + padded_image(x + start_height, y + start_width)*filter(x, y);
end
end
end
for i = 1:image_height
for j = 1:image_width
output(i, j, k) = filter_func(i + middle_height - 1, j + middle_width - 1);
end
end
You can see this function at work with various filters
Original Image | Blur Image | Large Blur Image |
Identity Image | Laplacian Image | Sobel Image |
cutoff_frequency = 7;
filter = fspecial('Gaussian', cutoff_frequency*4+1, cutoff_frequency);
low_frequencies = my_imfilter(image1, filter);
high_frequencies = image2 - my_imfilter(image2, filter);
hybrid_image = low_frequencies + high_frequencies;
Different cutoff frequencies were tried and applied to each set of images in order to get the best possible hybrid image. The results displayed here are the outcomes of this experiment. The cutoff frequencies tried for each set of images were based on guesses made by following intuition. As the cutoff frequency is increased, the low frequency image gets blurrier and as the cutoff frequency is decreased, the high frequency image gets sharper.
Experimenting with cutoff frequencies on Marilyn and Einstein:
The following images are the outcomes of the best guessed cutoff frequncy