Oleksii Trekhleb, a software engineer at Uber, recently explored using dynamic programming to speed up a content-sensitive, processor-intensive image resizing algorithm. Developers can use content-aware resizing to fit images into a variety of encompassing contexts (eg, screen form factors, responsive layout container) while preserving key image characteristics.
An article titled Seam sculpting for content-sensitive image resizing explained the motivation behind content sensitive image resizing as following:
The diversity and versatility of display devices today place new demands on digital media. […] HTML supports dynamic layout and text changes. However, [… images] Usually remain rigid in size and cannot deform to automatically accommodate different layouts. […] The size or aspect ratio of an image must change, to suit different displays such as cell phones or PDAs, or to print on a given paper size or resolution.
Standard image scaling is not sufficient as it ignores the content of the image and can usually only be applied uniformly. Cropping is limited because it can only remove pixels from the periphery of the image. More efficient resizing can only be achieved by taking into account the content of the image and not just geometric constraints.
Content-sensitive image resizing therefore strives to preserve important characteristics of an image and to perform image resizing (whether reduced or enlarged) without distortion.
|Original image||With face detection||Without face detection|
Previous sample images are provided by Cairo, an open source Go library that uses the Pigo face detection library. The author of the library explained that a complete Go solution allows high processing speed (Go compiles to native code) without the need to install third-party modules.
O(w + h) or
w are the height and width of the image, respectively. The resultant JS IMAGE CARVER The web application currently allows users to scale down images in the browser (scaling):
The preceding animation illustrates the basic principles of the seam sculpting algorithm. The white lines (the seams) are the set of pixels in the image labeled for removal. The original article describes the algorithm as follows:
[The seam carving algorithm] changes the size of an image by gracefully cropping or inserting pixels in different parts of the image. The seam sculpture uses an energy function defining the importance of the pixels. A seam is a connected path of low energy pixels crossing the image from top to bottom or left to right. By successively removing or inserting seams, we can reduce, but also enlarge, the size of an image in both directions. For image reduction, […] we remove more low energy pixels and fewer high energy pixels.