Project 1: Image Filtering and Hybrid Images

Hybrid image for cat&dog.

The goal of this project is to use my_imfilter() function to create hybrid images which are static images that can have different interpretation in terms of different viewing distance. We use my_imfilter() function to cut off high frequency of one image and low frequency of the other one, then combine the two filtered images together to get hybrid image. my_imfilter() function imitates the default behavior of built in function imfilter() which is provided in Matlab.

The hybrid image at the right combines the low-pass version of dog.bmp and high-pass version of cat.bmp. So if you look at the image from very close, you will see a cat, but if you look at it from far away, you will see a dog.

Algorithm for filtering function

  • 1. Create an empty output image which has same size as input image.
  • 2. Create an empty matrix(tempM) which has the same row and column numbers as filter and same dimension as input image.
  • 3. Perform convolution on each neighborhood. If current entry is outside the image boundary, fill that entry in tempM with 0. Otherwise fill that entry in tempM with the value in input image.
  • 4. Fill the output image with the value calculated before.
  •  
    Example for step 3: Suppose we have an input image as shown in Image1, and a 3*3 filter(not shown in the image). tempM is in red edges. To calculate value for (1,1,dim) entry in output image, we need to calculate the dot product between tempM and filter. Shaded areas in tempM are entries that outside the image boundary, we fill them with 0. The value of each position in tempM is shown in Image2:

    Image1

    Image2

    
    [height,width,dim]=size(image);
    [row,col]=size(filter);
    output=zeros(height,width,dim); %create output image
    tempM=zeros(row,col,dim);
    for i=1:height  %every element in image
        for j=1:width
            counter1=1;
            for m=i-(row-1)/2:i+(row-1)/2 %each neighbourhood
                counter2=1;
                for n=j-(col-1)/2:j+(col-1)/2
                      for k=1:dim
                        if (m<1)||(m>height)||(n<1)||(n>width)   %zero padding if outside the image boundary
                            tempM(counter1,counter2,k)=0;   
                        else
                            tempM(counter1,counter2,k)=image(m,n,k);
                        end
                      end
                      counter2=counter2+1;
                end
                counter1=counter1+1;
            end
            for k=1:dim
                temp=tempM(1:row,1:col,k).*filter;
                sumTemp=sum(sum(temp));
                output(i,j,k)=sumTemp;
            end
        end         
    end
    

     

    Algorithm for creating hybrid image

  • 1. Perform my_imfilter() on first image to get low frequency image.
  • 2. Perform my_imfilter() on second image, then subtract the blurred version of image2 from the original version of image2 to get high frequency image.
  • 3. Combine two images together
  • 
            low_frequencies = my_imfilter(image1,filter);
            high_frequencies = image2-my_imfilter(image2,filter);
            hybrid_image = low_frequencies+high_frequencies;
        

     

    Results for my_imfilter() function

  • The first image on the first row is the input image.
  • The second image on the first row is the output after applying an Identify filter.
  • The third image on the first row is the output after applying a box filter.
  • The fourth image on the first row is the output after applying a Gaussian filter.
  • The first image on the second row is the output after applying a Oriented filter.
  • The second image on the second row is the output after applying a High pass filter.
  • The last image on the second row is the output after applying another High pass "filter".
  •  

    Results for hybrid images

    Group 1: dog(low frequency) & cat(high frequency) -----cutoff frequency=7

    low high hybrid
     

    Group 2: motorcycle(low frequency) & bicycle(high frequency)-----cutoff frequency=14

    low high hybrid
     

    Group 3: plane(low frequency) & bird(high frequency)-----cutoff frequency=16

    low high hybrid
     

    Group 4: submarine(low frequency) & fish(high frequency)-----cutoff frequency=5

    low high hybrid
     

    Group 5: marilyn(low frequency) & einstein(high frequency)-----cutoff frequency=7

    low high hybrid
     
     

    Extra Credit(Mona_lisa & da Vinci)

    The hybrid image consists of the low frequency version of da_Vinci.jpg and the high frequency version of Mona_Lisa.jpg. As a result, if you look at the image from very close, you will see Mona Lisa. But if you look at the image from far away, you will see the portrait of da Vinci.

    low high hybrid