Project 1: Image Filtering and Hybrid Images

The project report contains the following

  1. Image filtering with examples
  2. Hybrid Images
  3. Creating Hybrid Images

Filtering is a fundamental operation in image processing. In this report filtering has been interpreted in both, spatial and frequency domain of the image. Filtering in the spatial domain is a mathematical operation on a neighbourhood of pixels around a given pixel. Filtering in the frequency domain can be interpreted as modification of frequencies in the image

Image filtering with examples

In the spatial domain, while implementing image filtering, a few considerations have to be made -

Code sample


%filtering code
filtered_image = [];
for channel=1:size(image,3)
    image_channel = image(:,:,channel); 
    %% padding the image
    [m,n] = size(image_channel);
    [fm,fn] = size(filter);
    padded_rows = floor(fm/2);
    padded_cols = floor(fn/2);
    %padded_image = padarray(image_channel,[padded_rows,padded_cols]);
    padded_image = padarray(image_channel,[padded_rows,padded_cols],'symmetric');
    %% filtering the image
    filtered_image_channel = [];
    %pixel wise filtering
    for i=padded_rows:m+padded_rows-1
        for j=padded_cols:n + padded_cols-1
            filtered_image_channel(i-padded_rows+1,j-padded_cols+1)...
                = sum(sum(padded_image(i-padded_rows+1:i-padded_rows+fm,j-padded_cols+1:j-padded_cols+fn) .* filter));
             
        end
    end
    filtered_image(:,:,channel) = filtered_image_channel;
end

Results of filtering

Figure 1. Blurring and edge detection using filtering

Figure 2. (Left)Darkening issue with zero padding, (Right)Resolved using symmetric padding

Hybrid images

Hybrid images are a combination of images in low frequencies and high frequencies. Due to the difference in frequencies and the nature of human vision, interpretation of the images is dependant on the viewing distance.

Code for hybrid images


%% Filtering and Hybrid Image construction
high_pass_frequency = 7;
low_pass_frequency = 4;
high_pass_filter = fspecial('Gaussian', high_pass_frequency*4+1, high_pass_frequency);
low_pass_filter = fspecial('Gaussian', low_pass_frequency*4+1, low_pass_frequency);

%% Create low frequency image
low_frequencies = my_imfilter(image1,low_pass_filter); 

%% Create high frequency image
high_frequencies = image2 - my_imfilter(image2, high_pass_filter);

%% Combine to create hybrid image
hybrid_image = low_frequencies + high_frequencies;

Hybrid image examples

Observations

The table contains the frequency pairs which were used to create the hybrid image for the given pair of images. Specific observations -
  • Hybrid images of some pairs like Submarine and Fish improved significantly with changed frequencies
  • In the Bicycle Motorcycle pair, the hybrid image was much more convincing in grayscale since the lower frequencies appear to the human eye as a shadow. While retaining color, the motorcycle's distinct red color was visible even with large blurs thereby making the hybrid image less convincing.
Image pair High pass frequency Low pass frequency
Cat - Dog 7 7
Einstein - Marilyn 7 4
Plane - Bird 5 4
Bicycle - Motorcycle [Grayscale] 8 5
Submarine - Fish 7 4

Creating Hybrid images

A hybrid image created using the below 2 images :

Figure 3. (Left) A ground level image of high rise buildings (Right) Batman's batarang

The resulting hybrid image obtained -

Figure 4. Hybrid image viewed as buildings from close (high frequencies) and batarang from far(low frequencies)

Observations

  • Image alignment is extremely important while creating hybrid images. Mis-alignments especially in the case of face mappings can create unsatisfactory hybrid images.
  • Another important aspect is the presence of high frequencies in the image meant to be passed with a low-pass filter. If the frequencies are too high, blurring will not be very effective and these frequencies will be visible even from a close viewing distance.
In the images displayed below, hybrid images are not very satisfactory because of misalignment and presence of high frequencies. The batarang is misaligned with the lighting effects of the aerial view of New York. Also, the batarang image has too many high frequencies that are visible despite blurring.

Figure 5. (Left) Aerial view of New York city. Credits : Michael Chinnici + PHOTOWORKSHOPADVENTURES.COM. Note the presence of similar lighting around all buildings in the centre of the image (Right) Batarang with high frequencies around the edges

The resulting hybrid image obtained -

Figure 6. Significant halo of the blurred image due to presence of high frequencies and a slight misalignment with the lighting in the original image causes this to be unsatisfactory. The batarang is visible even at a close viewing distance