Example of a hybrid image result.
In this project, there are several filters applied on the example image. Those filters include identify filter, blur filter, large blur filter, sobel filter, laplacian filter and high pass filter. By using these filters, we can combine two different images into a hybrid one.
The basic algorithm for filters using in the project is convolution. The algorithm takes in image as input and calculate the output image by getting the product of each pixel in the original image with the filter by the equation:
Here the output image matrix is indicated by h, and the input image is given by f. The filter is represented by g.
[height, width, layer] = size(image);
[fheight, fwidth] = size(filter);
for color = 1:layer
for i = 1:height
for j = 1:width
current = 0;
ycnt = 1;
for y = -floor(fwidth/2):1:floor(fwidth/2)
xcnt = 1;
for x = -floor(fheight/2):1:floor(fheight/2)
if i + x > 0 && i + x <= height && j + y > 0 && j + y <= width
current = current + image(i + x, j + y, color) * filter(xcnt, ycnt);
xcnt = xcnt + 1;
end
end
ycnt = ycnt + 1;
end
output(i, j, color) = current;
end
end
end
The hybrid images are made by adding low-frequencies image with high-frequencies image. The filter used to produce those two images are high-pass filter and low-pass filter correspondingly. There is a need to adjust the cutoff frequency for different pairs of images. The low frequency image can be produced by removing frequencies higher than the threshold, while the high frequency image can be obtained by subtracting its low-frequency part from the original image. After getting the two images, we can combine them together by simply addition to get a hybrid image. The image with low frequency can be recognized in large distance, while the image with high frequency can be clearly seen in short distance.
cutoff_frequency = 5;
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;