Seam Carving and Miniatures

A CS 194-26 project by Kevin Lin, cs194-26-aak

Traditional image retargeting techniques directly map pixels from the source image to the target image and use interpolation or blurring to ensure the result looks good. However, this direct mapping means that ratios and proportions are lost.

We designed an adaptive image retargeting system based on Avidan and Shamir's seam carving algorithm which chooses the most unnoticeable seams to remove from an image.

In normal images, depth of field requires lightfield information such as the distance of each object, but we can simulate the depth of field effect with selective gaussian blurring.

We applied image post-processing techniques to generate fake miniatures with strong depth of field effects.

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 miniatures 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.

Street in Kyoto
"Hinamizawa"

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.

Beach
Beach (narrower)
Beach (narrowest)

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.

Canyon
Carved Canyon
Lake and sky
Carved Lake and sky
Sparks
Carved Sparks
Wall
Carved Wall
Windmills
Carved Windmills

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.

Beach
Miniature Beach
"Hinamizawa"
Miniature "Hinamizawa"
Park
Miniature Park
River
Miniature River
Street
Miniature Street

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.

Miniature Street (mask)
Miniature Street (with mask)