Note: The author of the demo, Stéphane Roucheray, is a member of the PIMS team. The demo was first posted on the Pims World Labs weblog.

Content Aware Image Resizing is a way to re-target an image size without modifying its content ratio, in other words : non-linear image resizing. The algorithm was first explained by Shai Avidan and Ariel Shamir and published in 2007 (“Seam Carving for Content-Aware Image Resizing.”)
Since then several excellent Open Source implementations have been released. For example, there is a plugin for The Gimp and CAIR a standalone application in C++.
But thanks to Canvas and JavaScript it’s now possible to do this in the browser without a plugin.
Since version 1.5, Firefox offers bitmap manipulation through the Canvas API. Version 3.5 introduced not only the fastest Firefox JavaScript engine ever, but also a new Canvas method – createImageData – providing a much more powerful environment.

For this demo, a sub part of the Content Aware Image Resizing algorithm has been implemented. The width of the image can be reduced interactively without modifying its height. This implementation uses seam carving to re-size the image, subtracting the less visible vertical lines. It is a four step iterative algorithm. One iteration is one pixel width re-size. First an image is loaded into the Canvas context and then the iteration starts :
- A grayscale version of the image has to be calculated
- The edges of the image (Sobel convolution is used in our case) and its energy matrix is computed
- The seam of least energy (1 pixel vertical line from the bottom to the top of the energy matrix) is detected
- Then the pixel of the detected seam is removed from the original image and the result is re-injected as a source image to step 1
Each of the previous steps stores a whole matrix of data at the source image size. While these matrices are not all images but actually artifacts of the algorithm, storing them in an ImageData object is more convenient than using simple Arrays. This is why the createImageData method of the Canvas context is used. One of the benefits of this process is to allow showing the intermediate computations made under the hood.
This demo shows that’s possible to do more intelligent image resizing than just flattening an image’s pixels with CSS. Having computational and image manipulation capabilities directly in the browser opens up a new range of possibilities of how image data can be displayed to users. This is only one small demonstration of that.
Pingback from 颠覆网络35天 ─ 内容感知的图片大小调整 < MJiA on June 9th, 2009 at 2:45 am:
Pingback from Le Meilleur du Peer » content aware image resizing in javascript on June 9th, 2009 at 2:50 am:
Pingback from Content Aware Image Resizing @ Mozilla Hacks | Lambda on June 9th, 2009 at 5:21 am:
Pingback from Ajaxian » Animating SVG with Canvas and Burst on June 11th, 2009 at 5:57 am:
Pingback from Monthly Interesting Links Roundup (June 2009) on June 26th, 2009 at 12:23 am:
Pingback from Techknology’s Blog » Firefox 3.5 Will Arrive June 30 on June 26th, 2009 at 5:23 pm:
Pingback from Design Industries Blog » Blog Archive » Firefox 3.5 Will Arrive June 30 on June 27th, 2009 at 9:27 pm:
Pingback from Firefox 3.5 Will Arrive June 30 | Tech Invaders on June 28th, 2009 at 11:56 am:
Pingback from Firefox 3.5 to be released June 30 | BlogoFlux - Information Technology Blog on June 28th, 2009 at 12:08 pm:
Pingback from ParsanIT » امروز، مرورگر فایرفاکس ۳/۵ منتشر می شود |،مقالات مفید کامپیوتر و این on June 29th, 2009 at 9:40 pm:
Pingback from Firefox 3.5 on June 30th, 2009 at 9:33 am:
Pingback from Mozilla Firefox 3.5 Released | BlogoFlux - Information Technology Blog on June 30th, 2009 at 10:46 am:
Pingback from !!! فایر فاکس 3.5 هم آمد | تشکل سیاسی - دانشجویی هرمان on June 30th, 2009 at 11:56 pm:
Pingback from Shayan Amiri WebSite » Blog Archive » دانلود نسخه 3.5 مرورگر فایرفاکس رسید on July 1st, 2009 at 1:22 am:
Trackback from LaBoX on July 1st, 2009 at 7:01 am:
Pingback from مرورگر فایرفاکس ۳/۵ (نسخه نهایی ) on July 1st, 2009 at 12:42 pm:
Pingback from نسخه نهایی مرورگر فایرفاکس ۳/۵ | پاکباز دات آی آر |*_*| PAKBAZ.IR on July 2nd, 2009 at 1:25 am:
Pingback from Holnap érkezik a Firefox 3.5 | wordpress on July 3rd, 2009 at 12:25 am:
Pingback from نسخه نهایی مرورگر فایرفاکس ۳/۵ جهت دانلود منتشر شد on July 3rd, 2009 at 9:42 am:
Pingback from نسخه نهایی مرورگر فایرفاکس ۳٫۵ جهت دانلود منتشر شد | شبكه اطلاع رساني هاديران on July 5th, 2009 at 11:08 pm:
Pingback from 谋智社区 » Blog Archives » 颠覆网络35天 ─ 内容感知的图片大小调整 on July 6th, 2009 at 5:49 am:
Pingback from Zmiana rozmiaru zdjęcia z uwzględnieniem zawartości – stream of bytes on July 20th, 2009 at 1:56 pm: