Project 1: Image Filtering and Hybrid Images

The purpose of this assignment was to gain an understanding of image filtering and apply this to hybrid image generation.

Design Considerations

  • Boundary cases
  • Color images
  • Cutoff-Frequency for hybrid images
  • To address the boundary issues a copy of the image being filter was created that had built in filtering. To do this a new image was created that was the width of the original plus the floor of half of the filter width, the height of the original plus the floor of half of the filter height and with the original image centered in this image. The padded image could be larger than this, but this size scheme makes the filtering process simpler as the first filter location necessary will be the first pixel in this image.

    Handling color images for this assignment is relatively easy. All that was needed was to also loop through the multiple 3rd dimensions of the image array that represent the various color channels.

    The cutoff-Frequency was already implemented but need to be tuned somewhat for accurate results with the different images

  • Cat & Dog - 7
  • Bird & Plane - 6
  • Motorcycle & Bicycle - 15
  • Einstein & Marilyn - 4
  • Fish & Submarine - 15
  • The following is my code for my_imfilter.m. It shows the creating of the padded image and loops necessary. A simple summary of what is happening is a loop through all pixels in the original image and calculating its new value by iterating through and summing all values of the filter multiplied with their corresponding pixel values.

    
    [height, width, dim] = size(image);
    new_image = zeros(height, width, dim);
    [filter_height, filter_width] = size(filter);
    
    padded_image = zeros(height + filter_height - 1, width + filter_width - 1, dim);
    padded_image((filter_height - 1) / 2 + 1 : (filter_height - 1) / 2 + height, (filter_width - 1) / 2 + 1 : (filter_width - 1) / 2 + width, 1 : dim) = image;
    
    % loop through all pixels in image
    for x=1:height
        for y=1:width
            for z=1:dim
                % for each pixel loop through filter and update new_image
                for i=1:filter_height
                    for j=1:filter_width
                        new_image(x, y, z) = new_image(x, y, z) + padded_image(x + i - 1, y + j - 1, z) * filter(i, j); 
                        % again 1 indexing is the worst.
                    end
                end
            end
        end            
    end
    

    Results in a table (right click and view image for best effect)

    The only thing I have to add here is that Marilstein is pretty weird looking.