CS 194-26 Project 2: Fun with Filters and Frequencies
Arjun Dhamrait
Part 1
1.1: Finite Difference Operator
Without smoothing, these are the results of using the Finite Difference Operator:
From left to right: dx, dy, magnitude, edges
The threshold for edges was calculated (after a bit of tinkering) to be 2 standard deviations above the mean pixel brightness. This has many false positives with the edge detection!
1.2: DoG Filter
With smoothing, the results are nicer.
From left to right: smoothed magnitude, smoothed edge. note: teh smoothed magnitude is really dim!
With the same edge threshold as before, this has almost no false negatives! Also the edges are thicker.
Here are the DoG filters I got:
1.3: Image Straightening
To find the best image rotation, first I converted the image to grayscale. Then, using the previous smoothed gaussian filter. Then for each angle in the range of -5 to 5, I rotated the image, calculated the gradient angles via np.atan2
, and created a histogram of all the angles in the image. Finally, I weighted each histogram’s counts with a vector that is 1 at -180, -90, 0, 90, and 180 degrees and 0 everywhere else. From that, the dot product I get is roughly how many edges are straight. Finally, I created a map between each angle and the dot product calculated and found the argmax. This gave pretty good results.
The facade image
angle |
image |
histogram |
Dot product |
-5 |
|
|
1646835.0 |
-4 |
|
|
1575707.0 |
-3 |
|
|
1494908.0 |
-2 |
|
|
1406007.0 |
-1 |
|
|
1315194.0 |
0 |
|
|
1229365.0 |
1 |
|
|
1237901.0 |
2 |
|
|
1245104.0 |
3 |
|
|
1245960.0 |
4 |
|
|
1240590.0 |
5 |
|
|
1230878.0 |
The final chosen straightened image:
angle |
image |
histogram |
Dot product |
-5 |
|
|
1646835.0 |
Horizon image
failure case: Vent image
This seems to align to the shadows…
Failure case : Room image
There was a failure case with the room image. This is probably to do with the pattern on the floor, and the fact that the only line that would actually be 19 or 180 degrees when properly straightened would be the vertical edges of the room.
Part 2
2.1: Image Sharpening
For this part, the goal was to combine each separate convolution into one filter. Starting off, we have the sharpened image I’, the original image I, the unit impulse u, the alpha level α, and the gausian filter g:
I′=I+α(I−g∗I)
Moving this around we can get the overall filter:
I′=u∗(α+1)−α∗g=I∗F
where F = u∗(α+1)−α∗g. Combining the filters actually made sharpening happen super fast! It all took less than a second to sharpen images at alpha levels 1 through 5.
|
0 |
1 |
2 |
3 |
4 |
Orple |
|
|
|
|
|
Taj |
|
|
|
|
|
Whrythe |
|
|
|
|
|
note: these images are getting dimmer… I wasn’t able to figure out why, but you can see that the details are getting sharper as well.
sharpening an already blurry image doesn’t really work…
Blurry |
Sharpened |
|
|
2.2: Hybrid Images
For this part, the goal was to create hybrid images. This was actually pretty simple, I just chose a highpass filter with a size of 11 and a sigma of 2 and a low pass filter of size 15 with a sigma of 3. The results are pretty crazy, the Bernie-Banny is kind of scary…
Bells and whistles: I got this to work with color pretty well. I found that using both the high and low images with color gives the same output as using just the low image, and making the high frequencies color while the low frequencies are grayscale doesn’t look good.
Danny-Bernie
Dog-Cat
2.3: Gausian and Laplacian Stacks
This was also pretty simple, I just followed almost exactly the algorithm given for a stack.
Lincoln
Using the stack on the Lincoln, you can see that the high frequencies is all of the small details in the image, and at the low frequencies there are only the overall lincoln image.
Bernie-Danny
A similar thing is seen on the Bernie-Danny, where at the high frequencies you can see Danny clearly, but at the low frequencies you can only see Bernie.
2.4: Multiresolution Blending
This was fun. With python, I was able to get the actual blending down to one line, which is really neat. The end results as well are terrifying.
Bells and whistles: As you can see, I was able to get the blending to work well with color images. This actually required no additional effort in this problem as I wrote the convolve() function to either convolve the only level of the image, or convolve each layer in the case of 3d images.
Orple
Arjun Mouth
Coolest thing in the project
The Arjun-mouths were really scary lol, but overall the laplacian stacks and gaussian stacks were really interesting and useful!
CS 194-26 Project 2: Fun with Filters and Frequencies
Arjun Dhamrait
Part 1
1.1: Finite Difference Operator
Without smoothing, these are the results of using the Finite Difference Operator:
From left to right: dx, dy, magnitude, edges
The threshold for edges was calculated (after a bit of tinkering) to be 2 standard deviations above the mean pixel brightness. This has many false positives with the edge detection!
1.2: DoG Filter
With smoothing, the results are nicer.
From left to right: smoothed magnitude, smoothed edge. note: teh smoothed magnitude is really dim!
With the same edge threshold as before, this has almost no false negatives! Also the edges are thicker.
Here are the DoG filters I got:
1.3: Image Straightening
To find the best image rotation, first I converted the image to grayscale. Then, using the previous smoothed gaussian filter. Then for each angle in the range of -5 to 5, I rotated the image, calculated the gradient angles via
np.atan2
, and created a histogram of all the angles in the image. Finally, I weighted each histogram’s counts with a vector that is 1 at -180, -90, 0, 90, and 180 degrees and 0 everywhere else. From that, the dot product I get is roughly how many edges are straight. Finally, I created a map between each angle and the dot product calculated and found the argmax. This gave pretty good results.The facade image
The final chosen straightened image:
Horizon image
failure case: Vent image
This seems to align to the shadows…
Failure case : Room image
There was a failure case with the room image. This is probably to do with the pattern on the floor, and the fact that the only line that would actually be 19 or 180 degrees when properly straightened would be the vertical edges of the room.
Part 2
2.1: Image Sharpening
For this part, the goal was to combine each separate convolution into one filter. Starting off, we have the sharpened image I’, the original image I, the unit impulse u, the alpha level α, and the gausian filter g:
I′=I+α(I−g∗I)
Moving this around we can get the overall filter:
I′=u∗(α+1)−α∗g=I∗F
where F = u∗(α+1)−α∗g. Combining the filters actually made sharpening happen super fast! It all took less than a second to sharpen images at alpha levels 1 through 5.
note: these images are getting dimmer… I wasn’t able to figure out why, but you can see that the details are getting sharper as well.
sharpening an already blurry image doesn’t really work…
2.2: Hybrid Images
For this part, the goal was to create hybrid images. This was actually pretty simple, I just chose a highpass filter with a size of 11 and a sigma of 2 and a low pass filter of size 15 with a sigma of 3. The results are pretty crazy, the Bernie-Banny is kind of scary…
Bells and whistles: I got this to work with color pretty well. I found that using both the high and low images with color gives the same output as using just the low image, and making the high frequencies color while the low frequencies are grayscale doesn’t look good.
Danny-Bernie
Dog-Cat
2.3: Gausian and Laplacian Stacks
This was also pretty simple, I just followed almost exactly the algorithm given for a stack.
Lincoln
Using the stack on the Lincoln, you can see that the high frequencies is all of the small details in the image, and at the low frequencies there are only the overall lincoln image.
Bernie-Danny
A similar thing is seen on the Bernie-Danny, where at the high frequencies you can see Danny clearly, but at the low frequencies you can only see Bernie.
2.4: Multiresolution Blending
This was fun. With python, I was able to get the actual blending down to one line, which is really neat. The end results as well are terrifying.
Bells and whistles: As you can see, I was able to get the blending to work well with color images. This actually required no additional effort in this problem as I wrote the convolve() function to either convolve the only level of the image, or convolve each layer in the case of 3d images.
Orple
Arjun Mouth
Coolest thing in the project
The Arjun-mouths were really scary lol, but overall the laplacian stacks and gaussian stacks were really interesting and useful!