Giter Club home page Giter Club logo

python-scarving's Introduction

Years ago I wrote this code, which was most likely the very first Open Source implementation of the Seam Carving algorithm. Looks like even the Wikipedia editors might have been interested in my work (check the photo used in the demos, as well as how the carved seams are visualized etc).

This is a copy of my original blog post of 09/02/2007:

Seam Carving: Content-aware image resizing

Most people most likely saw the YouTube movie on content-aware image resizing which got blogged quite a lot lately. I read the corresponding paper, and wrote an implementation (not finished/perfect at all, but well) in Python. If it would ever become "production quality" a Gimp and/or GEGL plugin would be nice.

Here's a sample:

http://github.com/NicolasT/python-scarving/raw/master/castle_original.jpg

Resized using Gimp, cubic interpolation, 150px

http://github.com/NicolasT/python-scarving/raw/master/castle_gimp_150px.jpg

Resized image, 150px

http://github.com/NicolasT/python-scarving/raw/master/castle_150px.jpg

Overview of removed pixels

http://github.com/NicolasT/python-scarving/raw/master/castle_cutouts.jpg

This transformation is done in about 2 seconds (mainly because of some calculations in pure Python. For most calculations I use the Python Imaging Library and SciPy/NumPy, which are mainly C modules and much faster). As you can see the implementation still needs lots of love.

You can see another sample (image resized from 1000 to 250px in 8 seconds) here.

http://github.com/NicolasT/python-scarving/raw/master/seam_carving_6.png

Git repository is here. Please email any patches!

The algorithm itself is surprisingly "simple" and easy to understand, great job by the researchers! More on that later. I should be studying mathematical analysis now, 2nd time I got to redo this exam, bloody university :-(

Update: Using very expensive algorithm

http://github.com/NicolasT/python-scarving/raw/master/castle_expensive_150px.jpg

This image was generated by:

  • Loading the input image
  • 150 times:
    • Calculate energy and cost of current working picture
    • For every pixel in the top row, calculate the cost of the "best path" starting at this pixel
    • Figure out which path is the cheapest
    • Create an image which is the working image, minus this best path
    • Replace the working image with the image generated in the previous step

This took 273 seconds on my system, as the complexity is something like O(150*N*N*N*N*N*N*M) where M is the complexity of the gradient magnitude calculation.

Conclusion: not a workable solution :D

Do notice there are significant changes between this image and the one posted above. As I wrote this as a quick hack, I didn't include code to show which paths were removed from the original image.

python-scarving's People

Contributors

nicolast avatar

Stargazers

 avatar Zhang Cheng avatar Matt Gibson avatar Alexander Neal avatar Leechael avatar Jiashu Wang avatar  avatar

Watchers

 avatar Leechael avatar James Cloos avatar  avatar

Forkers

jagadish-gv

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.