fun with
filters & frequencies
Nadia Hyder
PART ONE
1.1:
FINITE DIFFERENCE OPERATOR
For
this part of the assignment, I worked with the cameraman image to create its edge
image. I convolved the image with finite difference operators [[1,-1][ and
[[1],[-1]], found their gradient magnitude image, and binarized it to create an
edge image.
Partial
derivative in x |
Partial
derivative in y |
Gradient
magnitude |
Edge
image |
|
|
|
|
1.2
DERIVATIVE OF GAUSSIAN FILTER
The
results from 1.1 were noisy, so I convolved the image with a gaussian filter to
blur the image, then convolved with the finite difference operators. I then
binarized the resulting gradient magnitude image to create a less noisy edge
image. Because convolution is commutative, we can achieve the same results
using a single convolution instead of two by creating derivative of gaussian
filters. This gave a less noisy edge image.
1.3
IMAGE STRAIGHTENING
I
implemented an image straightening algorithm which relies on a statistical
preference for vertical and horizontal edges in most images. In my
implementation, I tested rotations from -10 to 10 degrees and computed the
gradient angle of the edges in the image (after cropping out the outer edges).
The straightened image is the rotation with the greatest proportion of
horizontal and vertical edges (sum of # of -180, -90, 0, 90 degree edges).
Original
image |
Histogram
of angles |
Straightened
image (rotated by -3 degrees) |
Histogram
of angles |
|
|
|
|
Here
are the results on additional images of my choosing:
Original
image |
Histogram
of angles |
Straightened
image |
Histogram
of angles |
|
|
rotated
7 degrees |
|
|
|
rotated
10 degrees |
|
Failure
case
The
straightening algorithm failed on the following image because it has many
edges, but in this case horizontal and vertical edges cannot be used to
determine whether the image is straight.
|
|
rotated 10 degrees |
|
PART TWO
2.1
IMAGE SHARPENING
I
implemented image sharpening by applying a Gaussian filter to the image, then
creating an “unsharp mask” by subtracting the blurred image from the original,
then adding the mask multiplied by some weight to the original image.
Here
are some images before and after image sharpening:
|
|
|
|
I
then tried blurring a high-res image and sharpening it. While the sharpened version
is not as sharp as the original high-res image, it is considerably sharper than
the blurred image.
High-res
image |
Blurred
image |
Blurred
then sharpened image |
|
|
|
2.2
HYBRID IMAGES
To
create image hybrids, I aligned the two images on the eyes, applied a low pass
filter (Gaussian) to the first image, and a high pass filter to the second
image. I then averaged the two images to create the final result.
Image
1 |
image
2 |
hybrid |
|
|
|
Here
is another hybrid I tested and its FFT analysis:
|
|
|
Image 1 |
Image 2 |
High frequency |
Low frequency |
Hybrid |
|
|
|
|
|
2.3
GAUSSIAN AND LAPLACIAN STACKS
To
create a Gaussian stack, I continuously convolved the input image with a
Gaussian filter at every level of the stack. To create the Laplacian stack, I
found the differences between adjacent levels of the gaussian stack.
Gaussian
stack
|
|
|
|
|
|
Laplacian
stack
|
|
|
|
|
|
2.4
MULTIRESOLUTION BLENDING
I implemented multiresolution blending
by combining Laplacian layers and a gaussian layer. I first created a gaussian
stack for a binary mask, and gaussian and Laplacian stacks for the input images.
We blend the images with lower frequencies increasingly blurred, creating a stack
given by the equation described in the following paper:
The blended image is the sum of all the
layers.
|
|
|
|
|
|
|
|
|
|
|
|
Laplacian stacks of Mario Kart + Tesla
(irregular mask image)
|
|
|
|
|
|
TAKEAWAYS
While
this project offered several important insights, the biggest one is probably
how powerful and versatile the Gaussian high-pass filter is, and how pivotal
convolution is to image manipulation. I have always wondered how the iPhone
performs automatic image straightening, and I now have the tools in my toolbelt
to perform it myself! This project has been very rewarding. After this project
I have gained a lot of insight about how to perform edge detection, alignment,
image sharpening, and image filtering. At the core of it all is the gaussian
filter!