cs180-portfolio

proj2: filters and frequencies

task 1: fun with filters

1.1: finite difference operator

I first found partial derivative matrices by convolving Dx = np.array([[1, -1]]) and Dy = np.array([[1], [-1]] with cameraman.png as a gray scale image matrix. I used scipy.signal.convolve2d with mode="same to keep the dimensionality of the matrix after convolutions. Afterwards, I created a gradient magnitude matrix by using the two partial derivative matrices derived earlier. g_m = np.sqrt(dx ** 2 + dy ** 2).

dx

dy

gradient magnitude

binarized, thresh=0.25

1.2: derivative of gaussian filter (DoG)

I applied a gaussian blur first and then found the partial derivative matrices of the blurred image to see if it helps with edge detection. The gaussian kernel was created using cv2.getGaussianKernel, and the 2d gaussian filter was creating doing the outer product of the gaussian kernel on itself. The kernel size k was 10 x 10 and the sigma was (k-1) / 6 since “the length of for the 99th percentile of gaussian pdf is 6 * sigma.

gaussian blurred cameraman.png

dx of blurred image

dy of blurred image

gradient magnitude

binarized, thresh=0.05

Second method I tried was to first blur the derivative matrices by convolving the gaussing filter with the finite difference matrices. Afterwards, I convolved the newly transformed gaussian filters with the original image to find the gradient magnitude.

dx of gaussian

dy of gaussian

dx of blurred image

dy of blurred image

gradient magnitude

binarized, thresh=0.05

Both methods work well and the output resutls look basically the same. There might be slightly some more noise in the first one compared to the second one, but it is only noticable when gone a thorough examination of both images.

task 2: fun with frequencies

2.1: sharpening

Steps to sharpening an image:

  1. Extract low frequencies of image via low pass filter. I used gaussian blur.
  2. Extract high frequenceis of image via image - low.
  3. Add high frequencies multipled by alpha back to image via image + alpha * high.

taj.jpg with alpha=1

taj.jpg

low taj.jpg

high taj.jpg

sharpened taj.jpg, alpha=1

side note

I used cv2 operations since they automatically deal with out of range values. I tried using np.clip after doing np matrix operations before but cv2 operations do a much better job.

taj.jpg

alpha=0

alpha=1

alpha=2

alpha=5

alpha=20

mlord.png

alpha=0

alpha=1

alpha=2

alpha=5

alpha=20

nostudy.png

alpha=0

alpha=1

alpha=2

alpha=5

alpha=20

I also tried “resharpening” an image by blurring an already sharp image and then sharpening it again.

nosleep.jpg

initial sharpened image, alpha=2

blur of initial image

sharpen, alpha=2

The resharpened image has more clear edges but has weird artifacts, presumably from creating previously nonexistant edges into edges. e.g. the face shading now has a bunch of weird cracks now.

2.2: hybrid images

To make make some hybrid images, align an the two images and then sum up one image’s low frequencies and the other’s high frequencies.

derek and nutmeg

derek

nutmeg

a furry

chimera

nina from full metal alchemist

nina's dog

...

gogeta

goku

vegeta

fusion!

frequency analysis

goku fft

goku high freq fft

vegeta fft

vegeta low freq fft

gogeta fft

The fft shows how the images align their frequencies an create the hybrid image of gogeta. You can tell via the white lines of frequencies from both images.

2.3: gaussian and laplacian stack

I did each stack to 10 layers.

gaussian stack of apple

layer 0

layer 3

layer 6

layer 10

gaussian stack of orange

layer 0

layer 3

layer 6

layer 10

laplacian stack of apple

layer 0

layer 3

layer 6

layer 10

laplacian stack of orange

layer 0

layer 3

layer 6

layer 10

2.4: multiresolution blending

oraple

please forigve me as i accidentally did 1 more layer than the paper itself.

layer 0

apple

orange

combined

layer 2

apple

orange

combined

layer 4

apple

orange

combined

layer 7

apple

orange

combined

apple

orange

mask

combined

oraple horizontal

apple

orange

mask

combined

kirby

kirby

kirby blue

mask

combined

gudetama breakfast (fail)

gudetama

breakfast

mask

combined

here’s a cursed egg instead

gudetama

c

breakfast

mask

combined

reflection

pretty fun project overall. learned how frequencies worked and basically how photoshop works with masking. made some fun references to some of my favorite animes :).

back to project list