Jennifer Liu, cs194-26-aag
Christine Zhou, cs194-26-act
To shrink an image vertically or horizontally, we can use seam carving, which involves repeatedly removing the least important "seam" in an image until we have achieved the desired dimensions. To find such a seam, we define the importance of each pixel in the target image using the dual gradient energy function: Δ2x(x,y) + Δ2y(x,y), where Δ2x(x,y) = Rx(x,y)2+Gx(x,y)2+Bx(x,y)2 . Rx(x,y), Gx(x,y), and Bx(x,y) are defined as the difference between the red, green, and blue components respectively between pixel(x+1, y) and pixel(x-1, y). Δ2y(x,y) is defined similarly, with Ry(x,y), Gy(x,y), and By(x,y) being the difference between the red, green, and blue components between pixel(x, y+1) and pixel(x, y-1). For pixels at the border of the image, we use the same pixels, but wrap around the non-existent pixel to the opposite side of the image. Using this energy function as our pixel cost, we then use dynamic programming to find the path of least cost (the seam) in the image, and repeatedly remove it. Shrinking an image vertically, we would look for a least-cost seam from left edge to the right edge. To shrink an image horizontally, we would look for a least-cost seam from the top edge to the bottom edge of the image.
Here are the results:
Successes:
Failures:
Attempting to shrink this image horizontally resulted in spiderman losing a portion of his knee :(
Attempting to shrink this image horizontally resulted in a part of Thor's hammer getting lost :(
The most important thing we learned was that how the energy function is defined matters the most in seam carving. Perhaps defining a different energy function could have prevented Thor's hammer from being distorted in the above image.
To duplicate the famous in-camera effect, the vertigo shot (also called the dolly zoom), we used a DSLR for its real zoom lens. To create the effect, we would choose a subject for our photograph sequence, and repeat the following steps:
Here are the results:
Subject: Pencil Case
Subject: Water Bottle
For bells & whistles, we created gifs of the image sequences above.
These images were taken at the table on the 7th floor of Soda Hall. Initially, we tried using a very large lens, and would have trouble getting the camera to focus on the subject if it wasn't far away enough. After switching to the normal DSLR lens, it was easier to focus on objects close by. Positioning the subject in the exact same location on the camera was another challenge. It was difficult without a tripod, but we tried to get it as close as possible by putting post-its on the LCD (the screen on the back of the DSLR).
To create the fake miniatures, we used plt.ginput
to get the coordinates of
the area that we wanted to remain in focus. We select four points to get the
part of the image that we want to focus (we can simulate horizontal and vertical
directions by clicking points that take up the entire image horizontally or
vertically), then we apply a 2D Gaussian on the image. To smooth out the
unblurred part of the image to make a fainter seam, we use varying-sized 2D
Gaussians (sigma 1 close to the image and sigma 2 farther away from the image)
and repeatedly convolve our image with these Gaussians. The repeated convolution
with the Gaussian creates the effect of larger Gaussians as we get closer to the
edges of the photos, creating more of a blur of the image as we get further.
Here are some of the results with other images using vertical, horizontal, and irregular (not the entire horizontal or vertical distance) bounding areas:
In most cases, the irregular bounding areas gave more control over which parts to be blurred and focused and resulted in better images. Here are some of the results with our own images using irregular bounding areas:
Sources of images:
Chania: https://www.alargo.com/photooftheday/chania-city-from-above
Melbourne: https://pixabay.com/en/melbourne-skyline-skyscrapers-595426/
Vatican: https://www.hongkiat.com/blog/bird-eye-view-cities/
Old town: https://commons.wikimedia.org/wiki/File:TrzebiatowOldTownbird%27s-eyeview_2007-10b.jpg