Seam Carving in AS3, with source
Seam carving — the recently unveiled technique by Shai Avidan and Ariel Shamir to intelligently resize images (YouTube; white paper) — really captured my imagination when I came across it last night, as it has for many others.
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.

This is impressive! :O
I can’t believe my eyes!
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 …
have a look at this one.
http://blog.je2050.de/2007/09/02/content-aware-image-resizing/
http://je2050.de/showroom.php?file=ImageResizing2
or this:
http://www.quasimondo.com/archives/000651.php
mojave,
I love the experiments section on your portfolio website.
Lee
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.
Hector,
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.
Lee
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. http://www.timwintle.co.uk
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.
Check out rsizr.com 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!)
http://rsizr.com/about/gallery/ for example images
I just found the video – this seam carving lark is amazing!
Projectlinks gives a 404 – not found!
thanks
AWESOME! Finally, someone is doing some real stuff with flash
This is CRAZY! :)
The links to the source are dead. :( Any way of getting a copy?
Hi sorry about that. The links are fixed now.