Project 1: Image Filtering and Hybrid Images
Image Filtering.
I implemented my_imfilter() which imitates the default behavior of the built-in imfilter() function. It has the following features:
- supports grayscale and color images.
- support arbitrary shaped filters, as long as both dimensions are odd.
- pads the input image with zeros.
- returns a filtered image which is the same resolution as the input image.
My algorithm is as follows:
- Step 1: Check if filter is odd shaped. If not, do nothing and return to function caller.If odd, then continue.
- Step 1.1: Check if filter is linearly separable by computing its singular value decomposition. If yes, then form the vertical and horizontal vectors. -- commented out
- Step 2: Check if the input image is B/W or colour.
- Step 2.1: If the input image is B/W, pad the input image with zeros. Now run 2 for loops to cover the actual pixels of the image, and perform element wise multiplication of sections of the image with the filter. The section size must be the same as the filter size. The final value of every pixel is the total sum of the above matrix obtained. Store the result in 'output' and it has the same resolution as that of input image. If the filter was found to be seperable, no need of nested loops. Just multiply the image with the vertical and horizontal vectors as obtained in Step 1.1.
- Step 2.2: If the input image is colour, we basically perform the above process on each slice/colour-channel of the image. So for each channel, pad the image with zeros. Now run 2 for loops to cover actual pixels of the image, and perform element wise multiplication of sections of the image with the filter. The section size must be the same as the filter size. The final value of every pixel is the total sum of the above matrix obtained.Store the result in 'output' and it has the same resolution as that of input image.
Hybrid Images.
I used Gaussean filters and experimented with multiple values for the cutoff_frequency. Algorithm for this part is pretty straight-forward:
- Step 1: Create a low-pass filter(Gaussean) with a specific cutoff_frequency.
- Step 2: Apply this low pass filter on one image. Output it.
- Step 3: Create another high-pass filter(Gaussean) with a specific cutoff_frequency.
- Step 4: Apply this high pass filter on the second image. Output it.
- Step 5: Add the above 2 filtered images. Output it.
Results!
|
Low cutoff freq = 7; High cutoff freq = 7 |
|
Low cutoff freq = 8; High cutoff freq = 5 |
|
Low cutoff freq = 5; High cutoff freq = 3 |
|
Low cutoff freq = 10; High cutoff freq = 8 |
|
Low cutoff freq = 3; High cutoff freq = 6 |
Custom Hybrid: Russell Brand + Jack Sparrow |
|
Low cutoff freq = 8; High cutoff freq = 5 |
THANK YOU!