paint-brush
Seamless Point-of-Interest Cropping: Automating Image Focus Extractionby@imgix
190 reads

Seamless Point-of-Interest Cropping: Automating Image Focus Extraction

by imgixJune 20th, 2023
Read on Terminal Reader
Read this story w/o Javascript

Too Long; Didn't Read

Need to crop to the most important part of your images? Try imgix's #EntropyCropping and automate point-of-interest cropping!

People Mentioned

Mention Thumbnail
featured image - Seamless Point-of-Interest Cropping: Automating Image Focus Extraction
imgix HackerNoon profile picture

Cropping is a key technique for improving images. Removing unnecessary background information or changing an image's aspect ratio can greatly improve the viewer's focus on the image. imgix offers many cropping methods, including face detection. This tutorial will focus on automatic point-of-interest cropping (crop=entropy) and how you can use it to crop to the most salient, or significant, aspects of the image. In particular, areas of high contrast are considered to be the most salient.


Basic Entropy Cropping

Suppose we want to crop the following image to remove a large amount of the static black background from the image.


image before cropping


umbrella.jpg?w=640


The first step is to set the w and h parameters, and the fit=crop mode. This will resize the image to fill the selected width and height boundaries, and then crop any excess image data.


fit=crop



image after simple cropping to width and height


width: w=200
height: h=200
fit: fit=crop


umbrella.jpg?w=200&h=200&fit=crop


imgix's default cropping starts at the center of the image, removing data that falls outside of the given parameters. However, in addition to cropping the image, we also want the umbrella to be in the center. To do this, we add crop=entropy to the query string so that the “middle” becomes the most salient aspect of the image. The umbrella strongly contrasts with the rest of the image, so it becomes the focus.



fit=crop&crop=entropy

image after entropy or point-of-interest cropping



crop: crop=entropy


umbrella.jpg?w=200&h=200&fit=crop&crop=entropy


The goal was to remove a large amount of the static black background to center on the subject. In this example, the subject of the image was the red umbrella, and adding crop=entropy allowed the cropping functionality to center around it. However, the subject of an image isn’t always an inanimate object.


An Alternative to Face-centered Cropping

Suppose we want to resize and crop the following image to center on the model.


image before cropping



womanlandscape.jpg?w=640


The image was taken using the rule of thirds, allowing for a visually-appealing image while maintaining the model off-center. However, we also want to create smaller snippets of the image to use in multiple places on a website.


fit=crop

image after simple cropping to width and height



womanlandscape.jpg?w=200&h=200&fit=crop


Since the cropping functionality focuses on the center of the image, and the model is off-center, she doesn’t fully appear in the snippet. We can use the face-detection crop functionality to center image around her face.


fit=crop&crop=faces


image after cropping to the face area


womanlandscape.jpg?w=200&h=200&fit=crop&crop=faces


The face-detection crop mode successfully detected her face and centered the image around it. However, we are also interested in her outfit, and it isn't entirely in the frame. The model’s knee is partially hidden, so we instead add crop=entropy so that the entire outfit is included in the scene.



fit=crop&crop=entropy

image after entropy cropping


womanlandscape.jpg?w=200&h=200&fit=crop&crop=entropy


How Does Entropy Cropping Work?

Whereas the face crop mode looks for faces and centers on them for cropping, the entropy crop mode looks for high-contrast areas and focuses on those.

fit=crop



image before cropping

fit=crop


contrast detection in an email



In the above figure, we’ve modified the image to highlight the areas of high contrast in the image. The modified version demonstrates the point of interest in the image—in this case, the salamander's head. The entropy crop mode ignored the static color of the image, instead focusing on the areas where the black and white meet—the salamander’s bright colors provide high contrast against its background.


In the examples below, this ability of the entropy crop mode to focus on high-contrast areas keeps the salamander centered as the subject of the image regardless of portrait or landscape orientation. Assuming your images have high contrast areas in a similar way, this enables you to art-direct your images automatically by using crop=entropy to fit many different sizes and aspect ratios for different designs.


fit=crop&crop=entropy


image after entropy cropping


image after entropy cropping

Also published here.

To learn more, check out the imgix documentation page.