Skip to content

mandykoh/autocrop

Repository files navigation

autocrop

GoDoc Go Report Card Build Status

autocrop is an automatic image cropping/region-of-interest finding implementation in Go.

autocrop uses an energy-based approach to determine regions of visual interest at which to stop cropping. Cropping is alpha channel aware and supports images with translucency.

autocrop currently assumes image data is sRGB encoded.

See the API documentation for more details.

Some examples of cropping decisions made by autocrop can be seen here:

Threshold 0.3

Example of textured background being cropped from around a pink square

Threshold 0.1

Example of space being cropped away around a character illustration

Threshold 0.15

Example of sky being cropped away around a bridge

This software is made available under an MIT license.

Example usage

Find the autocropped bounds of an image using BoundsForThreshold:

croppedBounds := autocrop.BoundsForThreshold(img, energyThreshold)

The energyThreshold is a value between 0.0 and 1.0 which determines at what energy level cropping stops, relative to the maximum energy of the image. Higher threshold values result in more aggressive cropping.

The ToThreshold function can be used to conveniently get a cropped image if you don’t need the bounds:

croppedImg := autocrop.ToThreshold(img, energyThreshold)

Command line tool

autocrop also provides a command line tool that can be installed as follows:

$ go install github.com/mandykoh/autocrop/cmd/autocrop

and used to crop images like this:

$ autocrop <input_image> <output_png> [threshold]

The threshold is optional and defaults to 0.1.

About

Automatic energy-based image cropping implementation in Go

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages