CS 143 / Project 1 / Image Filtering and Hybrid Images

Algorithms

Filtering

Filter is done over each color image.

  1. The dimensions of the filter are obtained
  2. The image is padded using paddarray. The image is padded using reflected content by having padval be 'symmetric'. Symmetric image padding was used as it does not add darkness to the edges, nor does the images used have strong edges along image boundries that may add adverse effects.
  3. The sliding version of im2col is used to create the blocks a sliding window the size of the filter cuts out. Each block is stored as a column vector in the result.
  4. The filter is reshaped into a row vector for matrix multiplication
  5. padded_image . filter_row is calculated, doing the multiplcation and summing of the filter with each block. Each resulting pixel is now stored in row vector.
  6. col2im is used to turn the row vector back into the original dimensions of the image.

These are repeated for each channel and then are combined for the final image.

Hybrid Image Generation

Hybrid images are the result of combining the low frequencies of one image with the high frequencies of another. The low frequency image is obtained by filtering the image with a guassian filter. The high frequency image is the result of filtering the image with (unit impulse - guassian filter), where the unit impulse is a filter with the same dimension of the guassian with 1 in the center and 0's elsewhere. Two guassian filters were used, allowing one to specify the cutoffs for high and low frequencies independently.

Filtering algorithm


for (i=1:num_channels)
    fR = double(int8(size(filter, 1))/2);
    fC = double(int8(size(filter, 2))/2);

    %Init filtered image
    padded = padarray(image(:,:,i), [fR-1, fC-1], 'symmetric');

    %obtain the blocks, as columns
    blocks = im2col(padded, (size(filter)), 'sliding');

    %Reshape filter to a row vector
    filter_row= filter(:);

    %Perform filtering
    processed = filter_row * blocks;

    %Reshape resulting pixels back to correct dimensions
    result(:,:,i) = col2im(processed, size(filter), size(padded), 'sliding');
end

Hybrid image Results

Column 1: Low Frequencies of Image 1
Column 2: High Frequencies of Image 2
Column 3: Sum of the images produces a hybrid image
Column 4: Visualization of hybrid images

Filtering Examples

Blur, laplacian, high frequencies, sobel