Pixl is a tool for image processing.
Currently, it allows us to process images using the following algorithms:
- dithering
- Floyd–Steinberg
- halftone
- grayscale
- average
- luminosity
- lightness
- normalize
- threshold
- static
- Otsu's Method
With a correctly configured Go toolchain:
go get -u github.com/bednarc/pixl
Here is an example of main.go file which gets filename.jpg as input, uses threshold function to process an image and save image as output.png
package main
import (
"image"
_ "image/jpeg"
"image/png"
"os"
"github.com/bednarc/pixl"
)
func main() {
file, err := os.Open("filename.jpg")
if err != nil {
panic(err.Error())
}
defer file.Close()
image, _, err := image.Decode(file)
if err != nil {
panic(err.Error())
}
output := pixl.Threshold{Algorithm: pixl.ThresholdAlgorithms.Otsu}.Convert(image)
newfile, err := os.Create("output.png")
if err != nil {
panic(err.Error())
}
defer newfile.Close()
png.Encode(newfile, output)
}
oryginal | dithering |
---|---|
output := pixl.Dithering{}.Convert(input)
oryginal | halfltone |
---|---|
output := pixl.Halftone{
ColorBackground: "#fffff0",
ColorFront: "#000000",
ElementsHorizontaly: 100,
OffsetSize: 20,
Shift: 50,
MaxBoxSize: 10,
TransparentBackground: false,
Normalize: true,
}.Convert(input)
oryginal | normalize |
---|---|
output := pixl.Normalize{}.Convert(input)
oryginal | threshold |
---|---|
output := pixl.Threshold{Algorithm: pixl.ThresholdAlgorithms.Otsu}.Convert(input)
oryginal | gray |
---|---|
output := pixl.Gray{Algorithm: pixl.GrayAlgorithms.Luminosity}.Convert(input)
If you want to contribute to a project and make it better, your help is very welcome. Contributing is also a great way to learn more about social coding on Github, new technologies, and their ecosystems.
There are some ideas for new features
- resize image
- rotate image
- square halftone pattern https://engineering.purdue.edu/~bouman/ece637/notes/pdf/Halftoning.pdf p.5
- new dithering algorithms
- Jarvis, Judice, Ninke dithering
- Stucki dithering
- Burkes dithering
- median cut algorithm
- normalize colorful image
go test -cpu 1 -bench=.
go test