Content-Aware Image Resizing using HTML5 <canvas>
This page is a very basic demo of Content-Aware Image Resizing (CAIR) using seam carving.
The demo is very slow, so you can see a screenshot of the effect with a 50% resize if you don’t want to wait. There is a lot of room for improvement.
The algorithm is the following:
- For each pixel from the top row, find the pixel under it that has the closest color (directly under or 1 pixel to the side.)
- Add the color distance to a column score.
- Repeat until arriving at the bottom row.
- Repeat steps 1 – 3 for each column.
- Remove the column with the lowest total score.
← Original image
← <img> tag, resized by the browser
← Context-aware resizing in <canvas> (seam carving)