CS 143 / Project 1 / Image Filtering and Hybrid Images

Low-frequency filter example.

The image filtering function processes each color channel of the given image separately. For each channel, it rearranges all possible blocks that the given filter can slide over into columns. The resulting column vector is then multiplied with the filter and then rearranged back to the intial dimensions. The new matrix is eventually included in the result as one of the filtered color channels.

The function treats vector-filters differently from matrix-filters by performing two 1D convolutions and avoiding the quadratic cost of 2D kernels. Regardless the filter though, the function follows the same basic functionality:

  1. Calculate the image padding as the extra rows and columns needed in order to apply the filter.
  2. Start iterating over each channel.
  3. Rearrange the channel matrix into a column vector, where each column repressents an image block that the filter slides over.
  4. Multiply the resulting row vector with the filter.
  5. Rearrange the result back to the 2D dimensions of the padded image.
  6. Include the filtered layer in the container for the resulting image.
  7. Stop iterating and return filtered image.

The details for each different filter distiction are listed below.

Hybrid image transitions.

Vector filters

When a vector filter is given, the padding is set as the length of the vector for both the extra rows and columns. Then for some channel, the padded image is rearranged into the column vector where the filter slides over, performing horizontal convolution. The resulting matrix is then convoluted vertically, hence resulting in the filtered channel.

Matrix filters

For matrix filters, the padding is first calculated as the extra rows and columns needed for convolution, before converting the padded image into the column vector and applying the filter over it. The filtered column vector is rearranged back into the original dimensions and added to the result.

Example applications of filters over images