Content aware image resizing
Comments: 6 - Date: October 10th, 2007 - Categories: Graphics
The concept of content aware image resizing is to resize an image whilst preserving the important parts of the image. A very simple and neat method to do this was presented in a paper at this years SIGGRAPH, the superb results of which can also be seen in this YouTube video.
The trick involves removing least cost seams through the image instead of the evenly spaced columns or rows that scaling removes. All the details are in the very readable and clear paper. Unfortunately the idea was simply too neat to avoid tinkering with. Thus we arrive here. I’ve implemented the basics of the paper pretty much as is, using directional Sobel filters to calculate the cost of removing pixels.
The photo below is a good example of a photo that works with this technique.
This resizes horizontally to:
(content-aware vs. standard scaling)
and vertically to:
The content aware resizing creates much clearer shrunk images of the origninal preserving the houses on the right. Unfortunately this resizing doesn’t work well for most images, it works best for images with areas of detail and flat areas. Download it, give it a go and see what it can do. The application and source code (BSD Licence) are available for anyone to tinker with and improve.
There are obviously lots more possible things that could be done to this app. Including: suitability estimate based on the variance of the seam costs, image expanding, different weighting algorithms to choose for different images, pre-calculation and live resizing, and weight painting for areas of interest/disinterest.
If you find any nice examples or find a use for the source code let me know.
Comment by n[ate]vw - October 10, 2007 @ 4:34 pm
To echo your thoughts, this is “simply too neat” to not find a use for, especially with BSD-licenced source! I’m planning to start in 2008 working on an image-related program, d.v., so maybe I can find a way to work it in.
Comment by n[ate]vw - October 10, 2007 @ 4:45 pm
Also, your binary doesn’t work on Tiger (__NSSetProgramVars symbol not found). The source compiles, but the file chooser doesn’t let me select any images — which could also be a backwards-incompatibility, as I can’t open the main menu nib file in Xcode 2.4.1.
Comment by Nathan Youngman - October 10, 2007 @ 7:19 pm
Hi Will,
There is a fast OCaml implementation here, with some other tricks:
http://eigenclass.org/hiki/
– nathan.
Comment by admin - October 10, 2007 @ 10:43 pm
Cheers. The app and source code both now work.
I’ll take a look at the OCaml approach, but speed-wise he’s comparing it to python. I think the object removal trick is one of the better uses of this technique and would obviously make a nice small separate app.
Comment by Nathan Youngman - November 4, 2007 @ 4:59 pm
True, OCaml is compiled vs. interpreted like Python. However, it sounded like he had altered the algorithm a bit as well.
There sure seems to be a lot of good stuff in Leopard for development. Like ImageKit basically gives your app iPhoto functionallity. Handy for something like this, perhaps.
Ciao, Nathan.
Comment by Delia - May 1, 2008 @ 7:53 pm
The content aware image resizing technique is great and I’m sure it will make history. I found a tool that implements great algorithms form image resizing at reshade.com. The accuracy and quality obtained are stunning .The sharpness of the picture is maintained at any zoom factor.
Leave a comment