Project 1: Image Filtering and Hybrid Images

Example of filter being applied to image, highlighting the need for padding

Inorder to perform the hybrid-filtering of images required by the assignment, I had to first implement a function to apply a filter to an image. This is where my_imfilter comes in. The idea behind this function was to:

  1. Perform a minimum padding on the input image to avoid loss of information with the traditional filtering technique
  2. Iterate through the padded image such that the filter can be applied where possible by element-wise multiplication
  3. Fill in the output matrix with values representing the sum of the element-wise multiplication performed when applying the filter
  4. Repeat this operation for each of the three color channels of the image (RGB)
  5. Return the output image

Much of the thought in my implementation was regards to the method in which I indexed through the pixels in the image to apply the filter. To avoid going out of bounds as well as to hit every pixel, I had to first calculate the midpoint of the filter. Because the filter is guaranteed to be off odd x odd dimension, this was easily found by floor(rowCount/2), floor(colCount/2). Once these midpoints could be calculated, the padding size applied to the image could easily be represented as a [midRow, midCol] array and the indexing within the image could start just past this padding at image(midRow + 1, midCol + 1).

The Filtering Function


%Iteration over pixels detailed below
 for i = relRow + 1: s(1) + relRow;
    for j = relCol + 1: s(2) + relCol;
        %element-wise multiplication
        mult = image(i - relRow: i + relRow, j - relCol: j + relCol) .* filter;
        %sum results and input into the center of the nxm grid
        output(i - relRow, j - relCol) = sum(mult(:));
    end
end

Generating Hybrid Images


%Three step process to generate a hybrid image:
low_frequencies = my_imfilter(image1, filter);
high_frequencies = image2 - my_imfilter(image2, filter);
hybrid_image = low_frequencies + high_frequencies;

Hybrid Images Examples

The above sets of images were created applying the im_filter algorithm to sum up the low-frequencies from image1 and the high-frequencies from image2. The top row contains the two input images, and the respective low-frequency and high-frequency version of those images. The bottom row contains the resulting images at different scales to fully observe the hybrid effect. It is also worth noting that the 'threshold' parameter had to be manually adjusted to achieve the above results on an pair-by-pair basis.