Close Show/hide page

Seam Carving in AS3, with source

Thumbnail - Click me

Seam carving is a recently unveiled technique by Shai Avidan and Ariel Shamir to intelligently resize images (YouTube; white paper).

Like Hector Yee (whose writeup was very useful), I decided to try my hand at an implementation of it just for the hell of it, but in Actionscript 3.

The attached demo only resizes images vertically, not horizontally. I wish I could have, but didn’t bother including a dynamic image loader. It’s also, well, very pokey, but the code is readable and the output seems accurate. If you can stand the wait, press [M] a few times to load up the seam calculation queue.

But the most valuable thing about this demo is its publicly available source code under a Creative Commons license:

So if you’re so inclined, please improve, extend, optimize, and/or port this code. I’m not planning on doing any further work on it. Just let me know if you find the code useful, and share your work.

If you’re interested in a more fully-realized online demo of seam carving, here’s one that’s been done in Java.

Update: Additionally, as it turns out, Patrick Swieskowski has already put up an online seam carving Flash demo here.

Version: 0.8

Licensed under a Creative Commons Attribution 3.0 License.

16 Responses to “Seam Carving in AS3, with source”

  1. Luca says:

    This is impressive! :O

    I can’t believe my eyes!

  2. Links: September 3, 2007

    Awesome Context Aware Image Sizing:  Lots of people are talking about this Truly Great Innovation for photo editors!  Hope for it in PhotoShop soon!
    An Introduction to Erlang for Curly Brace Programmers:  Good intro to massively parallel language …

  3. admin says:


    I love the experiments section on your portfolio website.


  4. Hector Yee says:

    Nice implementation! Did you find the same problems with pictures with lots of straight edges? I found it worked fine when theres sky and bushes to delete but if its mainly buildings it seems to distort the edges too much.

  5. admin says:


    I’m also seeing the same issues with straight edges. Mostly, I’m thinking it’s intrinsic to the algorithm. Which is not to say there may not be an ingenious solution to the problem…

    I’ve been wondering if the whole process could be ‘anti-aliased’ by scaling the image by 100% using a bicubic or bilinear filter, and then doing the seam carving from there. It would, of course, take 4 times as long…

    Again, thanks for the writeup on your blog.


  6. Tim Wintle says:

    Hi, I’ve also been doing a version of this, (but in python) – and I am trying to get the people who have done implementations together to compare the outputs on the same image- if you are interested email me, or see my blog.

  7. Nice implementation of seam carving, one of the first. The problem with geometric figures (lots of lines) is real, as people have pointed out. I would like to see how it behaves for people pictures, though.

  8. Will says:

    Check out for a full-featured Flash-based implementation of seam carving that lets you resize your own images, both in height and width simultaneously, in real time. (You can rescale and crop images too!) for example images

  9. Ian Hickman says:

    I just found the video – this seam carving lark is amazing!

  10. Br. Brick says:

    Projectlinks gives a 404 – not found!

  11. grabek says:

    AWESOME! Finally, someone is doing some real stuff with flash

  12. Franklyn says:

    This is CRAZY! :)

  13. Golf-Ace says:

    The links to the source are dead. :( Any way of getting a copy?

  14. admin says:

    Hi sorry about that. The links are fixed now.

Leave a Reply