Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/esimov/dithergo
Various dithering algorithms implemented in Go
https://github.com/esimov/dithergo
dithering-algorithms floyd-steinberg go image-processing
Last synced: about 2 months ago
JSON representation
Various dithering algorithms implemented in Go
- Host: GitHub
- URL: https://github.com/esimov/dithergo
- Owner: esimov
- License: mit
- Created: 2017-01-26T11:00:15.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2021-02-15T14:56:55.000Z (almost 4 years ago)
- Last Synced: 2024-12-10T08:10:51.308Z (2 months ago)
- Topics: dithering-algorithms, floyd-steinberg, go, image-processing
- Language: Go
- Homepage:
- Size: 20.6 MB
- Stars: 167
- Watchers: 4
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# dithergo
[![CI](https://github.com/esimov/dithergo/workflows/CI/badge.svg)](https://github.com/esimov/dithergo/actions)
[![Go Reference](https://pkg.go.dev/badge/github.com/esimov/dithergo.svg)](https://pkg.go.dev/github.com/esimov/dithergo)
[![license](https://img.shields.io/github/license/esimov/dithergo)](./LICENSE)Dithergo is a simple Go library implementing various [dithering](https://en.wikipedia.org/wiki/Dither) algorithm to produce halftone images. It supports color and monochrome image outputs.
The library implements the following dithering methods: ***Floyd Steinberg, Atkinson, Burkes, Stucki, Sierra-2, Sierra-3, Sierra-Lite***. All of these algorithms have something in common: they diffuse the error in two dimensions, but they always push the error forward, never backward.
We can represent this with the following diagram:
X 7 5
3 5 7 5 3
1 3 5 3 1(1/48)
where `X` represent the current pixel processed. The fraction at the bottom represents the divisor for the error. Above is the the `Floyd-Steinberg` dithering algorithm which can be transposed into the following Go code:
```go
ditherers = []dither.Dither{
dither.Dither{
"FloydSteinberg",
dither.Settings{
[][]float32{
[]float32{ 0.0, 0.0, 0.0, 7.0 / 48.0, 5.0 / 48.0 },
[]float32{ 3.0 / 48.0, 5.0 / 48.0, 7.0 / 48.0, 5.0 / 48.0, 3.0 / 48.0 },
[]float32{ 1.0 / 48.0, 3.0 / 48.0, 5.0 / 48.0, 3.0 / 48.0, 1.0 / 48.0 },
},
float32(multiplier),
},
},
}
```You can plug in any dithering algorithm, so the library can be further extended.
### Installation
`$ go get -u -v github.com/esimov/dithergo`
### Running
Type `go run cmd/main.go --help` to check all the supported commands. The library supports the following commands:
```
Usage of commands:
-e string
Generates & exports the color and greyscale mode halftone images.
Options: 'all', 'color', 'mono' (default "all")
-em float
Error multiplier (default 1.18)
-o string
Output folder
-t Option to export the tresholded image (default true)```
You can run all of the supported dithering algorithms at once, or you can run a specific one from the `cmd` directory.### Results:
| Input |
|:--:|
||
The below images are generated with the default options using Michelangelo's David statue as sample image.
| Color | Monochrome |
|:--:|:--:|
||
|
Atkinson | Atkinson |
||
|
Burkes | Burkes |
||
|
Floyd-Steinberg | Floyd-Steinberg |
||
|
Sierra-2 | Sierra-2 |
||
|
Sierra-3 | Sierra-3 |
||
|
Sierra-Lite | Sierra-Lite |
||
|
Stucki | Stucki |## Author
* Endre Simo ([@simo_endre](https://twitter.com/simo_endre))
## License
Copyright © 2018 Endre Simo
This software is distributed under the MIT license found in the LICENSE file.