autocrop

package module
v0.4.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2021 License: MIT Imports: 4 Imported by: 1

README

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoundsForThreshold

func BoundsForThreshold(img *image.NRGBA, energyThreshold float32) image.Rectangle

BoundsForThreshold returns the bounds for a crop of the specified image up to the given energy threshold.

energyThreshold is a value between 0.0 and 1.0 representing the maximum energy to allow to be cropped away before stopping, relative to the maximum energy of the image.

func Energies added in v0.3.0

func Energies(img *image.NRGBA, r image.Rectangle) (cols, rows []float32)

Energies returns the total row and column energies for the specified region of an image.

func ToThreshold

func ToThreshold(img *image.NRGBA, energyThreshold float32) *image.NRGBA

ToThreshold returns an image cropped using the bounds provided by BoundsForThreshold.

energyThreshold is a value between 0.0 and 1.0 representing the maximum energy to allow to be cropped away before stopping, relative to the maximum energy of the image.

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL