CS194-26 Final Project

Hersh Sanghvi | cs194-26-add

 

Fake Miniatures

 

In this project, we aim to create a fake tilt-shift effect by blurring areas of the image that are far away from a plane of focus specified by the user. This plane of focus is defined by two user defined points which are then converted into a rectangle that spans either the entire width or height of the image, depending on the orientation of the points.

I achieved this by dividing the image into patches, and applying a blur to each patch based on its distance to a polygon that is supposed to be in focus. This has the potential to create a very patchy effect in the image, so I fixed this by setting a step size for iterating through the image to be half the patch size. This creates an averaging effect and eliminates the patchy look. In addition, I added saturation by converting to the HSV colorspace and multiplying the saturation by 1.3.

 Take a look at the results:

Description: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_1:rainier.jpgDescription: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_1:rainier_mini.jpg

(source: u/indieaz on reddit)

 

Description: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_1:sanfran.jpgDescription: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_1:sanfran_mini_rect.jpg

(source: Alamy)

 

Description: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_1:yosemite.jpgDescription: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_1:yosemite_mini_rect.jpg

(source: myself)

 

Description: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_1:berkeley_day.jpgDescription: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_1:berkeley_day_mini.jpg

(source: myself)

 

Defining more complex DOF regions

 

Sometimes it is not sufficient to simply define a rectangular region. This is seen particularly  poignantly in the Yosemite image above, where the trees in the foreground are considered in focus, but they really shouldnÕt be because they are vastly closer than the actual object of focus. Therefore, I allow users to specify a polygon of focus instead of simply a rectangle.

Description: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_1:yosemite.jpgDescription: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_1:yosemite_mini_obj_better.jpg

Notice how the trees are now out of focus, providing a much better effect!

 

In addition, these complex regions can be used to create a cool ÒvignetteÓ type effect:

Description: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_1:airport.jpgDescription: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_1:airport_mini_obj.jpg

 

This project was super cool, since I had seen tilt shift effects before made by using a very narrow depth of field lens and thought this effect was very cool. It was interesting to see how this effect could be achieved by very simple comp photo code.

 

 Seam Carving

 

In this project, we aim to resize images in a content-aware manner, to make them smaller while preserving the salient features of the image. This is done by specifying an energy function over the image, and then removing continuous seams that minimize the total energy used over the seam. To do this, we use the pretty straightforward Bellman-Ford algorithm, which is a dynamic programming technique. Normally, the gradient function is used for the energy. However, this can be susceptible to noise, so I decided to use the Sobel derivative function, which can also smooth out the image a little to eliminate noise. Here are the results of where this worked:

 

Description: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_2:canyon.jpgDescription: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_2:canyon_cropped.jpg

The Fiery Furnace @ Arches National Park

 

Description: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_2:waterfall.jpgDescription: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_2:waterfall_cropped.jpg

Upper and Lower Yosemite Falls

 

Description: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_2:narrows.jpgDescription: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_2:narrows_cropped.jpg

The Narrows at Zion National Park

 

Description: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_2:sanfran.jpgDescription: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_2:sanfran_cropped.jpg

San Francisco skyline

 

Description: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_2:arch.jpgDescription: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_2:arch_cropped.jpg

Landscape Arch @ Arches National Park

 

Description: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_2:utah.jpgDescription: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_2:utah_cropped.jpg

Canyonlands National Park

 

Failure Cases

 

Sometimes, the energy function doesnÕt work very well. This is often the case for pictures that have a large amount of semantic information, such as faces, or rigid structures, such as diagonal pathways that are not x or y aligned (the San Francisco one above worked fine since the buildings were vertically aligned).

 

Description: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_2:deathvalley.jpgDescription: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_2:deathvalley_cropped_fail.jpg

Since the pathway is not aligned to the x or y axes, we get jagged artifacts due to the compression. We also get similar artifacts in the sky. This could be solved by somehow modifying the energy function to preserve semantic object information.

 

Description: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_2:beach.jpgDescription: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_2:beach_cropped_fail.jpg

This is also a failure case, although a more subtle one at that. Ideally, it would have cropped equal parts of the sky and beach, but the sky contains much less information than the sand, which also does not contain a lot of information. Thus, the beach is mostly kept intact while the trees are sliced in a somewhat jagged matter and completely getting rid of the sky.

 

Description: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_2:kayak.jpgDescription: Macintosh HD:Users:Hersh:Programming:cs194-26:final_proj_2:kayak_cropped.jpg

As we can see, because the water contains a lot of information, the seam carving instead goes through the rigid structure of the kayak, creating a wavy, water-like effect, which of course ruins the image of the kayak.

 

I learned a lot doing these projects! It was cool to think about how the various energy functions would affect the seam carving, and how the dynamic programming approach selected the ÒoptimalÓ seam.