Project 1: Image Filtering and Hybrid Images

Example of a hybrid Image.

This project was aimed at familiarising with the concept of Image Filtering and Hybrid Images. In this project, pair of images of same size and orientation were given. One image of the pair was filtered using the low pass filter and the other one was filtered using the high pass filter. Then these images were combined together to create a hybrid images. The various image pairs taken are

  1. Cat and Dog
  2. Fish and Submarine
  3. Einstein and Marilyn
  4. Bicycle and Motorcycle
  5. Bird and Plane
  6. Justin Bieber and Miley Cyrus

Some of the important considerations which were taken into account before obtaining the hybrid images were:

  1. It is important the images in the pair should be of the same size and orientation, else the image will not be so appealing and more importantly the code won't run (obviously))
  2. One parameter which was to be tuned was the cut-off frequency. Initially I used the same frequencies for both the images. Then I further tuned the cut-off frequencies taking one for each of the image. We obtain better images if we take different cut-off frequencies for each of the filter, as it will help us in retaining suitable features for each image. We can customise the feature selection in this way.
  3. It is important to understand that which image is to be blurred and for which image the edges (fine details) should be retained.

Step 1: Creating a filter similar to imfilter of MATLAB

We created a function which inputs two arguments the image and the filter to be used for the image. This image uses the filter as a sliding window and computes the final image with the same dimensions as the input image by using the dot product. Then the results were verified by using the identity filter & the large blur filter (low pass filter), Sobel filter & Laplacian filter (high pass filter). Then the results were tested for each of the image pair in order to identify which image is to be passed using which filter.

Example 1: Dog and Cat

Figure showing the results of the cat.jpg with the identity filter, large blur filter, Sobel Filter and the Laplacian Filter.

Figure showing the results of the dog.jpg with the identity filter, large blur filter, Sobel Filter and the Laplacian Filter.

In this pair, we saw that the cat has more sharp features as compared to the dog.

Example 2: Fish and Submarine

Figure showing the results of the fish.jpg with the identity filter, large blur filter, Sobel Filter and the Laplacian Filter.

Figure showing the results of the submarine.jpg with the identity filter, large blur filter, Sobel Filter and the Laplacian Filter.

In this pair, we saw that the fish has more sharp features with the scales, eye and fins as compared to the submarine.

Example 3: Einstein and Marilyn

Figure showing the results of the einstein.jpg with the identity filter, large blur filter, Sobel Filter and the Laplacian Filter.

Figure showing the results of the marilyn.jpg with the identity filter, large blur filter, Sobel Filter and the Laplacian Filter.

In this pair, we saw that Einstein has more sharp features like the hair, mustache, eyes, nose and wrinkles on the face as compared to Marilyn.

Example 4: Bicycle and Motorcycle

Figure showing the results of the bicycle.jpg with the identity filter, large blur filter, Sobel Filter and the Laplacian Filter.

Figure showing the results of the motorcycle.jpg with the identity filter, large blur filter, Sobel Filter and the Laplacian Filter.

In this pair, the bicycle is bigger in size as compared to the motorcycle, so the features of bicycle otherwise will suppress the features of the mototrcycle.

Example 5: Plane and Bird

Figure showing the results of the bird.jpg with the identity filter, large blur filter, Sobel Filter and the Laplacian Filter.

Figure showing the results of the plane.jpg with the identity filter, large blur filter, Sobel Filter and the Laplacian Filter.

In this pair, we saw that the bird has more sharp features as compared to the plane.

Example 6: Justin Bieber and Miley Cyrus

Figure showing the results of Justin Bieber with the identity filter, large blur filter, Sobel Filter and the Laplacian Filter.

Figure showing the results of Miley Cyrus with the identity filter, large blur filter, Sobel Filter and the Laplacian Filter.

In this pair, we saw that Bieber has more sharp features as compared to Miley.

Example of code for imfilter


function output = my_imfilter(image, filter)
[m,n,o] = size(image);
[f1,f2] = size(filter);

for i = 1:o
    I(:,:,i) = padarray(image(:,:,i),[floor(f1/2), floor(f2/2)]);
end    
    
output = zeros(m,n,o);

for i = 1:o
    for j = 1:m
        for k = 1:n
            output(j,k,i) = sum(sum((I(j:j+f1-1,k:k+f2-1,i).*filter)));
        end
    end
end

Step 2: Implementing the filter created and generate hybrid images

So as mentioned above the images were filtered using the imfilter function. One image was passed through the low pass filter and the other one was passed through the high pass filter. The high pass filtering was done using the low pass filter. The image was filtered using the low pass filter and then the filtered image was subtracted from the original image, only to retain the high frequencies. The filtered images were then combined together to generate a hybrid image.

Results in a table

Example 1: Cat and Dog

Cat has been passed through the high pass filter with cut-off frequency = 10 and the dog has been passed through the low pass filter with cut off frequency = 7

Hybrid Image of Cat and Dog

Example 2: Fish and Submarine

Fish has been passed through the high pass filter with cut-off frequency = 4 and the Submarine has been passed through the low pass filter with cut off frequency = 5

Hybrid Image of Fish and Submarine

Example 3: Einstein and Marilyn

Einstein has been passed through the high pass filter with cut-off frequency = 3 and the Marilyn has been passed through the low pass filter with cut off frequency = 5

Hybrid Image of Einstein and Marilyn

Example 4: Bicycle and Motorcycle

Bicycle has been passed through the high pass filter with cut-off frequency = 4 and the Motorcycle has been passed through the low pass filter with cut off frequency = 6

Hybrid Image of Motorcycle and Bicycle

Example 5: Bird and Plane

Bird has been passed through the high pass filter with cut-off frequency = 4 and the Plane has been passed through the low pass filter with cut off frequency = 6

Hybrid Image of Motorcycle and Bicycle

Example 6: Miley Cyrus and Justin Bieber

Justin Bieber has been passed through the high pass filter with cut-off frequency = 10 and Miley Cyrus has been passed through the low pass filter with cut off frequency = 10

Hybrid Image of Justin Bieber and Miley Cyrus

Observations

  1. The orientation and the size of the pair of the images should be the same.
  2. For a few pair of images using different cut-off frequency for each of the filter (low-pass and high pass) can give better results.
  3. It can also be seen that images with fine details if passed through the high pass filter and the other one through the low pass filter, then the results obtained are better. If the images are swapped then the results are not so convincing.

Example of bad hybrid images

Figure showing the results of swapping the dog and the cat images. The image of dog is not so clear.

Figure showing the results of swapping the fish and the submarine. Although the fish can be seen in the last image, but the fine features of the shape of the fish are lost.

Conclusion

  1. A filter similar to imfilter() function of MATLAB was developed which was further used as a high pass and low pass filter. The images obtained from each of the filter were combined together to generate the hybrid images.