Cat-Dog
This project focuses on the application of fundamental filters on the given images. The image filters implemented within this project are identify_filter, blur_filter, large_blur_filter, sobel_filter, laplacian_filter and high_pass_filter. With these filters, we can then build the hybrid images by combining high frequency image and low frequency image.
Before applying the filters on the image, we need to preprocess the image by padding the sides with extra pixels, otherwise we cannot calculate the new values for pixels on the sides. To accomplish this goal, we can simply pad the boundaries with zero values. The padding width is determinded by the filter's size.
% pad the boundaries with zero values
[m, n] = size(filter);
pad_image = padarray(image, [floor(m / 2), floor(n / 2)]);
Apply the filtering formula to calculate the value of the dot product of the matrix of the image and the filter matrix:
% use three for loop to calculate the new value for each pixel
[r, c, l] = size(image);
for layer = 1: l
for col = 1: c
for row = 1: r
value = sum(sum(pad_image(row : (row + m - 1), col : (col + n - 1), layer) .* filter));
output(row, col, layer) = value;
end
end
end
![]() |
![]() |
![]() |
Identity Image | Blur Image | Large Blur Image |
![]() |
![]() |
![]() |
Sobel Image | Laplacian Image | High Pass Image |
The hybrid image is constructed by combining two images filtered by high-pass filter and low-pass filter respectively. The key here is the cutoff frequency used to determine which part of the image can be preserved. For the first image, apply the filter to wipe off the components with higher frequency than the threshold and preserve the low frequency part. On the other hand, apply the same filter to the second image, and then subtract the filtered image from the original image to get rid of the low frequency part. Combine the images and get the hybrid image. Since the first image now only has low frequency part, it can be recognized when distance is large. The second image can be recognized better when the hybrid image is colse to eyes because high frequency part dominates in short distance.
% set the filter, apply on images and combine them
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;
![]() |
![]() |
The First Image (Original) | The Second Image (Original) |
![]() |
![]() |
The First Image (Low Frequency) | The Second Image (High Frequency) |
Final Hybrid Result
![]() ![]() ![]() |
![]() ![]() ![]() |
![]() ![]() ![]() |
![]() ![]() ![]() |
The preprocessing of the images is just to pad the boundaries of the image with zero values, which works out well for this project. The reason for the success of this kind of preprocessing is the small size of the filter. The padding width determined by the filter size is also small, thus the influence of the zero values is not significant. However, if the filter size is big, it would be better choice to reflect across edges. The hybrid image is constrcuted by combining a low frequency image and a high frequency image. The high frequency components of a image are the edges where the values of the pixels varies sharply, and the low frequency components are blurred color blocks without clear edges among them. When the image is close to the observer, the edge details are well caught by the eyes while the color blocks of image dominating when the image is far away. Thus we should choose the image with more sharp edges as the high frequency part and the image with less color blocks as the low frequency part to make a appropriate hybrid image.