michalsz / pixl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pixl

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

Install

With a correctly configured Go toolchain:

go get -u github.com/bednarc/pixl

Examples

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)
}

dithering

oryginal dithering
output := pixl.Dithering{}.Convert(input)

halfltone

oryginal halfltone
output := pixl.Halftone{
	ColorBackground:       "#fffff0",
	ColorFront:            "#000000",
	ElementsHorizontaly:   100,
	OffsetSize:            20,
	Shift:                 50,
	MaxBoxSize:            10,
	TransparentBackground: false,
	Normalize:             true,
}.Convert(input)

normalize

oryginal normalize
output := pixl.Normalize{}.Convert(input)

threshold

oryginal threshold
output := pixl.Threshold{Algorithm: pixl.ThresholdAlgorithms.Otsu}.Convert(input)

gray

oryginal gray
output := pixl.Gray{Algorithm: pixl.GrayAlgorithms.Luminosity}.Convert(input)

Contribute

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

benchmarks

go test -cpu 1 -bench=.

tests

go test 

License

License

About

License:MIT License


Languages

Language:Go 100.0%