This project uses filters and frequencies manipulate images in various ways. For example, we can blur an image, create a hybrid image between two images, and blend two images together. Some concepts applied include finite difference operators, derivative of Gaussian filters, Gaussian stacks and Laplacian stacks. Scroll down to read more!
I set Dx
and Dy
to be 2D numpy
arrays and convolved each of them with the 0th channel of the cameraman image using scipy.signal.convolve2d
, setting mode=same
. Afterwards, I took the gradient magnitude of the two images post-convolution using the distance formula sqrt(image1 ^ 2 + image2 ^ 2)
. Finally, I binarized the gradient magnitude image, setting the threshold to 75.
I used get_gaussian_kernel_2d
from discussion and set kernelSize=10
and sigma=1.5
to create my Gaussian.
For the first part, I blurred the original image by convolving it with the Gaussian. Next, I convolved the blurred image with Dx
and Dy
, before finding its gradient magnitude and binarizing it.
For the second part, I convolved my Gaussian with Dx
and Dy
before convolving the original image with the derivative of Gaussian. I then found the gradient magnitude and binarized, as usual.
Using this approach, we can see that the binarized edges are more defined (thicker and rounder). There is also less noise, especially near the bottom of the image. However, we also lose some details of the camera. We can also see that our two approaches yield the same output image, as expected.
I used the formulas from lecture to derive image sharpening. Let B
be the blurred image (convolving the original image with Gaussian(10, 1.5)
), img
be the image and alpha
be the sharpening factor. Then, our sharpened image is img + alpha * (img - B)
. I used alpha=1
for all images below.
I chose to blur and sharpen the already sharp image of the dam. It turns out that this resulting image is more blurry than the original sharpened image, due to the blur losing information in the image.
First, I used the skeleton code to align my images. I used Gaussian(60, 10)
as the kernel for my high frequency image and Gaussian(6, 1)
for my low frequency image. I blurred the images with their respective Gaussians. I averaged the blurred low frequency image and the difference between the high frequncy image and its blurred version to get a hybrid photo. I then converted it to grayscale using the rgb2gray
function from discussion.
A hybrid I tried was combining the Kingaroo with a boba drink - however, that unfortunately failed. It was difficult to align it, and even more difficult to find fitting Gaussian parameters to make a good hyrbid considering the shapes of the two figures in question.
I chose to display the 2D Fourier transform of the Kingaroo and Uniqloroo Hybrid.
I used the lecture slides as inspiration for creating my Gaussian and Laplacian stacks. For each level of the Gaussian stack, I blurred the previous level by Gaussian(36, 6)
. To make my Laplacian stack, I subtracted the value in index i-1
from the value in index i
of my Gaussian stack, then added the highest level of my Gaussian stack to the end.
To build my Laplacian stack for a blended image, I used the formula A[i] * mask[i] + B[i] * (1 - mask[i])
from the lecture slides as inspiration, where A
and B
correspond to the Laplacian stacks of the two images. To complete the blend, I summed the values in the stacks, which returned the desired image.