https://github.com/mandykoh/autocrop
Automatic energy-based image cropping implementation in Go
https://github.com/mandykoh/autocrop
image-analysis image-manipulation image-processing
Last synced: 5 months ago
JSON representation
Automatic energy-based image cropping implementation in Go
- Host: GitHub
- URL: https://github.com/mandykoh/autocrop
- Owner: mandykoh
- License: mit
- Created: 2019-10-23T10:06:34.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2021-06-03T07:59:33.000Z (about 5 years ago)
- Last Synced: 2025-08-14T11:24:47.441Z (10 months ago)
- Topics: image-analysis, image-manipulation, image-processing
- Language: Go
- Size: 1.71 MB
- Stars: 13
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# autocrop
[](https://godoc.org/github.com/mandykoh/autocrop)
[](https://goreportcard.com/report/github.com/mandykoh/autocrop)
[](https://travis-ci.org/mandykoh/autocrop)
`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](https://godoc.org/github.com/mandykoh/autocrop) for more details.
Some examples of cropping decisions made by `autocrop` can be seen here:
_Threshold 0.3_

_Threshold 0.1_

_Threshold 0.15_

This software is made available under an [MIT license](LICENSE).
## Example usage
Find the autocropped bounds of an image using [`BoundsForThreshold`](https://godoc.org/github.com/mandykoh/autocrop#BoundsForThreshold):
```go
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`](https://godoc.org/github.com/mandykoh/autocrop#ToThreshold) function can be used to conveniently get a cropped image if you don’t need the bounds:
```go
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 [threshold]
```
The threshold is optional and defaults to 0.1.