pixl

package module
v0.0.0-...-14a2abd Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2020 License: MIT Imports: 6 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GrayAlgorithms = &grayAlgoList{
	Lightness:  "lightness",
	Average:    "average",
	Luminosity: "luminosity",
}

GrayAlgorithms consists of a list of algorithms that can be used as algorithm type in pixl.Gray struct. e.g. pixl.Gray{Algorithm: pixl.GrayAlgorithms.Lithtness}

View Source
var ThresholdAlgorithms = &thresholdAlgoList{
	Static: "static",
	Otsu:   "otsu",
}

ThresholdAlgorithms consists of a list of algorithms that can be used as algorithm type in pixl.Threshold struct. for ex: pixl.Threshold{Algorithm: pixl.ThresholdAlgorithms.Static}

Functions

This section is empty.

Types

type Dithering

type Dithering struct {
}

Dithering is a config struct

func (Dithering) Convert

func (dithering Dithering) Convert(input image.Image) image.Image

Convert takes an image as an input and returns dithered image

type Gray

type Gray struct {
	Algorithm grayAlgoName
}

Gray is a config struct

func (Gray) Convert

func (config Gray) Convert(input image.Image) *image.Gray

Convert takes an image as an input and returns grayscale of the image

type Halftone

type Halftone struct {
	TransparentBackground bool
	ColorBackground       string
	ColorFront            string
	Shift                 int8 /* -100(%) to 100(%) */
	ElementsHorizontaly   uint16
	OffsetSize            int8 /* -50(%) to 50(%) */
	MaxBoxSize            uint8
	Normalize             bool
}

Halftone is a config struct Configuration contains:

 TransparentBackground - if true then background of png image will be transparent
 ColorBackground - background color in hex format (e.g. #b690d9)
 ColorBackground - frontend color in hex format (e.g. #b690d9)
	Shift - shift between adjacent rows
 ElementsHorizontaly - amount of elements in the x axis
 OffsetSize - increases or decreases output pattern size
 MaxBoxSize - maximum size of output pattern
 Normalize - if true then image will be normalized before conversion to halftone

func (Halftone) Convert

func (config Halftone) Convert(input image.Image) image.Image

Convert takes an image as an input and returns halftone image

type Normalize

type Normalize struct {
}

Normalize is a config struct

func (Normalize) Convert

func (config Normalize) Convert(input image.Image) (output image.Image)

Convert takes an image as an input and returns a normalized image

type Threshold

type Threshold struct {
	Algorithm    thresholdAlgoName
	StaticLevel  uint8
	InvertColors bool
}

Threshold is a config struct Configuration contains:

Algorithm - grayscale Algorithm used to convert image
StaticLevel - threshold level is used only with Static Algorithm type
InvertColors - if true then change all white pixel with black pixels

func (Threshold) Convert

func (config Threshold) Convert(img image.Image) *image.Gray

Convert takes an image as an input and returns thresholded image

Jump to

Keyboard shortcuts

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