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 |
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.
Steps to sharpening an image:
image - low
.image + alpha * high
.
taj.jpg |
low taj.jpg |
high taj.jpg |
sharpened taj.jpg, alpha=1 |
I used
cv2
operations since they automatically deal with out of range values. I tried usingnp.clip
after doing np matrix operations before butcv2
operations do a much better job.
alpha=0 |
alpha=1 |
alpha=2 |
alpha=5 |
alpha=20 |
alpha=0 |
alpha=1 |
alpha=2 |
alpha=5 |
alpha=20 |
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.
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.
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 |
nutmeg |
a furry |
nina from full metal alchemist |
nina's dog |
... |
goku |
vegeta |
fusion! |
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.
I did each stack to 10 layers.
layer 0 |
layer 3 |
layer 6 |
layer 10 |
layer 0 |
layer 3 |
layer 6 |
layer 10 |
layer 0 |
layer 3 |
layer 6 |
layer 10 |
layer 0 |
layer 3 |
layer 6 |
layer 10 |
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 |
apple |
orange |
mask |
combined |
kirby |
kirby blue |
mask |
combined |
gudetama |
breakfast |
mask |
combined |
gudetama |
c
breakfast |
mask |
combined |
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 :).