Project 1: Image Filtering and Hybrid Images

Hybrid Image of Dog and Cat

For project 1, we were required to write our own image filtering function and then filter images in different ways including blur, high frequency, low frequency, etc. We then used this filter function to create hybrid images, by taking low frequencies of an image and high frequencies of another and combining them. This results in an image that reflects the high frequency image up close, and the low frequency image from far away. My filtering function works as follows:

  1. Pad the image with zeros relative to the size of the filter being used
  2. Iterate over the 3 channels of the image and over each non-padding pixel value
  3. Create a matrix of neighbors of each pixel relative to the size of the filter
  4. Multiply the filter and the neighbors and then sum the resulting matrix
  5. Divide that sum by the sum of the filter and place the value in a new image matrix

Image filter snippet

This snippet shows my iteration technique and how I chose to transform between padding pixel coordinates and final image coordinates


for z = 1:3
    for x = xstart:xend
        for y = ystart:yend
            xind = x - xstart + 1;
            yind = y - ystart + 1;
            newmatrix = times(padimage((y-padrow:y+padrow),(x-padcol:x+padcol),z), filter);
            avg = sum(sum(newmatrix))/sum(sum(filter));
            newimage(yind, xind, z) = avg;
        end
    end
end

Results in a table

Original cat
Large blur, sobel, laplacian, high pass
Original cat and dog
High frequency cat, low frequency dog, hybrid image
Original Einstein and Marilyn
High frequency Einstein, low frequency Marilyn, hybrid image

The results of my filtering method are effectively the same as the imfilter() method ignoring floating point precision issues. The only thing I considered changing is my padding method to duplicate edges or something other than zero padding, because large filters result in a black edge which is pretty ugly when that isn't intended.
Additionally, the cat-dog hybrid image is computed with a cutoff_frequency of 7, whereas the einstein-marilyn hybrid image is computed with a cutoff_frequency of 4, as it resulted in a more balanced image.