Getting Started
The package is written in Python 3 and requires a recent version of numpy
and scikit-image
. Invoke the main.py
file to run each tool.
main.py
contains two sub-utilities: one for carve
-ing seams from an image, and another for generating fake mini
atures by simulating depth of field.
usage: main.py [-h] {carve,mini} ...
Seam Carving and Fake Miniatures
positional arguments:
{carve,mini}
carve Seam carving
mini Fake miniatures
optional arguments:
-h, --help show this help message and exit
Photography
Two of the photos in this project are original.
All other images are available online via CC0 license which allows for reuse and redistribution without permission or attribution.
Seam Carving
Seam carving is a method for content-aware resizing and retargeting. Instead of directly cropping or rescaling which isn't adaptive to the content, seam carving removes the least important vertical and horizontal seams from an image.
Take the beach scene, for example. Much of the scene is just the background transitioning between the sandy beach and the blue oceanwater. We can remove the seams in these unimportant regions first since each seam in that area carries very little additional detail.
In the narrowest image, we can clearly tell the seams which were removed from the image as they leave artifacts since the adjacent pixels no longer match in color or intensity.
Still, seam carving is a generally effective algorithm, working on a wide variety of images and textures.
Seam carving has some difficulty when choosing between different possible seams. In the windmills scene, the path through the windmill on the right is lower than the path cost for other paths on the left because the program simply takes a sum of values provided by the energy function. In this case, we used a Sobel filter to compute the X-direction and Y-direction gradients, but it isn't aware of object costs. Traveling through the blade of the windmill likely incurs a lower cost than the smaller, incremental costs along other paths.
While we only show vertical seam carving above, the algorithm is also capable of removing horizontal seams by first transposing the image, removing vertical seams, and then transposing the result back to the original orientation.
Fake Miniatures
Strong depth of field effects can be selectively added to images during post-processing to yield a "fake miniature" effect. The program works by defining a mask region and then selectively applying a gaussian blur outside of the masked region.
To further enhance the effect, brightness and saturation were also increased slightly to make the photo pop out.
These examples work well primarily because the scene has an easy-to-map depth map. Even though we only define the depth of field plane using a rectangular area, it's sufficient for creating the depth of field effect because the plane extends so far into the horizon.
We can further improve the effect in some scenes, like the Street scene, by defining a custom mask instead of relying on the standard rectangular area. This allows us to better capture the true geometry and depth of the scene.