Skip to content

Instantly share code, notes, and snippets.

@zzeleznick
Created October 8, 2015 14:48
Show Gist options
  • Save zzeleznick/e146e30205393b4ad9ec to your computer and use it in GitHub Desktop.
Save zzeleznick/e146e30205393b4ad9ec to your computer and use it in GitHub Desktop.
Seam Carving Project Documentation

CS194-26: Context-Based Image Resizing (Project 4)

Author: Zachary Zeleznick SID: 2324051 Date: 10/06/2015

Layout

Functional Directories: Do not remove

Directories Subfolders Description
data/ directory from images are loaded
examples/ a few images that were used in the beginning but later removed from main path
masks/ a collection of masks used for the mask parameter in main.py
seamData contains seam indices for precomputation, generated by generateSeamData.py
output/ directory for images to be saved
basic_images/ directory containing a few nice images
best_images/ directory containing my favorite images
bulk_data/ directory containing past output generated by benchmark.py
logs/ directory for logs run by generateSeamData.py or by benchmark.py

Depreciated: No longer in use

Directories Description
build/ earlier iterations of code compiled down to C via cython
old-code/ earlier iterations of code for reference
notebooks/ collection of a few tests
papers/ used for research

Main Files

Generate Output
  1. main.py returns a modified image from user-specified dimensions and optional parameters of saving, masking, and display.

            python main.py IMAGE_INDEX = 0; HORIZONTAL_CROP = 0; VERTICAL_CROP = 0; SAVE = False; MASK = False; DISPLAY = True
    
  2. benchmark.py generates modified images for all images in the data/ directory with user-specified dimensions and optional parameters of saving, masking, display, and log file output location

           python benchmark.py log.txt >  debug.txt
    
  3. generateSeamData.py generates seam data for for all images in the data/seamData/ directory with either user-specified height or width.

           python generateSeamData.py HORIZONTAL_CROP = False
    
  4. best.py demonstrates the best sampling of output for the reader

           python best.py
    
Helper Files
  1. IO_methods.py handle image and seam loading, reading, and saving.

  2. userInput.py handle user input for main.py, benchmark.py and general use

  3. utils.py contain useful functions called by main.py and others

Usage

Generate Seam Data
  1. If the data/ directory have images that have yet to been preprocessed, run

        python generateSeamData.py
    

This will generate 300 seams in the vertical direction and save them in data/seamData/. For horizontal seam generation run

```
    python generateSeamData.py horizontal
```
  1. Run all the images

    python benchmark.py
    

Current parameters are set to HORIZONTAL_CROP = 100; VERTICAL_CROP = 0; SAVE = True; HAS_MASK = 0; DISPLAY = False
For Display, change the boolean value of DISPLAY to True on line 7. Log file output is defaulted to mainLog.txt, but this can be changed by specifying the file name as the first parameter. More details are displayed to stdout, but can be easily piped to a secondary file (thanks to print override)

  1. Test a specific image
     python main.py 6 0 300 1 1 1
    

The first argument is the index of the image in data/ to be run. The second and third arguments are the number of pixels to remove from the image. A negative value corresponds to seam insertion, while a positive value is seam removal. The fourth argument is a boolean for optional saving to disk, the fifth is whether to search and load a mask from the data/masks/ directory, which helps to preserve sensitive artifacts such as faces or shadows. The sixth argument is display, which is defaulted to True.

  1. See all the Bells & Whistles in Action!

     python best.py
    

Note the difference between masked and unmasked seam removals, the benefit of masks for seam insertion, how quickly pre- proccessed seam removal can be, which pixels are removed and more! See the file for more.

Zachary Zeleznick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment