Project 1: Image Filtering and Hybrid Images

Example of a processed hybrid image.

Hybrid images are static images that change in interpretation as a function of the viewing distance. By blending the high frequency portion of one image with the low-frequency portion of another, you get a hybrid image that leads to different interpretations at different distances. The goal of this project was

  1. To write a my_imfilter(I,f) function (analogous to imfilter() from matlab) which filters the multidimensional array of an image I with the multidimensional filter f.
  2. To create a hybrid image of two (reasonably aligned) images, by blending high frequency portion of one image with the low-frequency portion of another.Usually high pass component is visible only from far distance from the image. Hence, some of following visualization will scale down the hybrid images to make the high pass component observable.

Implementation

  • my_imfilter:
    my_imfilter applies the filter f with every* pixel of the original image and creates a new filtered image of the same resolution as of original image.This function works for filters of any width and height combination, as long as the width and height are odd. This restriction makes it unambigious which pixel in the filter is the center pixel. The tricky part was to handle the boundary pixels without parts of the filter being out of bounds.There are varous approaches to handle these boundary pixels, such as by padding the original image with 0s, or by replicating the image in spatial domain, or by mirroring the image content over edges. The imfilter function in Matlab uses padding by 0 option as a default option, but I have padded the image by mirroring it across the edges, as this is supposed to be a better approach, generally, to preserve the continuity of the image. This filter works with RGB as well as Gray scale images.
  • Creating a hybrid image:
    Given two images, image1 and image2, hybrid image is created by applying following transformations:
    hybrid image = image1* GaussianFilter1 + image2* (1 - GaussianFilter2) GaussianFilter is a smoothing filter, typically used for blurring images and reducing the noise. The intensity of blurring depends on the standard deviation (cutoff frequency) of the filter. Gaussian filter acts as a low pass filter and when such filtered image is subtracted from 1, only high frequency components are left acting as a high pass filter. These two filters were applied on the two images and the filtered images were blended together by simply adding the results.
    To describe the effects of low-pass and high-pass flters at a high level in terms of visual image, low pass filter will retain the colors of the image, but will smoothen the image, wherein high pass filter will retain the edges and sharpness of the image, but not the colors.
    The tricky part here was to manually set the appropriate cut-off frequencies for every pair of images used. There are some guidelines in choosing the two images and cutoff frequencies ( which I will be discussing in a later section below), but there are no rules which can be applied blindly to get the better hybrid images. It does involve manually tuning the frequencies.
  • Results

    After Appling various filters
    Row1(left to right)- 1. Identity Image, 2.High frequency image, 3. High pass image.
    Row2(left to right) 4. Sobel image 5. Blur image 6. Large blur image

    Most of the kernels used in these filters are well-known and hence could be easily used with my_imfilter. For example,
    sobel_filter = [-1 0 1; -2 0 2; -1 0 1]; (Respond to horizontal gradients)
    blur_filter = [1 1 1; 1 1 1; 1 1 1]; (Small blur)
    large blur is a gaussian filter
    laplacian_filter = [0 1 0; 1 -4 1; 0 1 0]; (High pass filter)
    high frequeency image is basically 1 - low-pass image

    1.Original cat image, 2.High pass filtered cat image, 3. Original dog image, 4. Low pass filtered dog image


    Scaled down dog-cat hybrid image - Dog is better visible in the scaled down version than in the original size hybrid image


    Other Hybrid Images


    Scaled hybrid image of a fish and a submarine


    Scaled hybrid image of a bicycle and a motorcycle


    Scaled hybrid image of a Einstein and a Marilyn


    Scaled hybrid image of a bird and an airplane


    Hybrid Image of a Building Shoot at Different Times from the Same Angle


    These are the photographs of a building taken at different times of the day, one with clear sky and hence clear background and the other one with cloudy and occluded background


    Hybrid image of these two scenes can be used for sort of noise cancellation and object recognition ( object of interest being the building in the front)


    References: Hybrid Images