dither

module
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: May 29, 2023 License: GPL-3.0

README

dither

Implements the Error Diffusion Dithering algorithm, and some other image manipulation techniques. It is a work in progress, more effects are in the work. This go module contains multiple packages:

  • process: the core functionality, implementing the image algorithms (like FSD).
  • geom: some simple geometry types (like Point) and functions to manipulate them.
  • imgutil: some image utilities, like OpenImage.
  • kmeans: k-means clustering implementation, useful for finding the k most prominent colors in an image.
  • nearneigh: a work in progress, impelementation of a nearest neighbour search algorithm.
  • kdtree: a work in progress, implements a kd tree search structure for fast nearest neighbour.
  • colorpalette: a custom defined colorpalette type, with accompanying functions.
  • gifeo: a package for creating dithered gif videos (gif + video = gifeo)
  • needle: some functions that are useful for multithreading (the needle)
example image created using the dither module. example gif video created using the dither module.

Usage

In your go module (after having run go mod init mymodule), get this module by running go get github.com/mielpeeters/dither. You can then import the various packages in your code.

As an example, here is code you could write to apply the Floyd Steinberg Dithering algorithm:

package main

import (
	"github.com/mielpeeters/dither/colorpalette"
	"github.com/mielpeeters/dither/imgutil"
	"github.com/mielpeeters/dither/process"
)

func main() {
    // open the input image
    img, err := imgutil.OpenImage("path/to/imputImage.any")
    if err != nil {
    return
    }

    // scale the image down with a given scale
    scale := 10
    scaledImage := process.Downscale(img, scale)

    // get the palette in which to create the new image
    amountOfColors := 5
    colorpalette.SampleFactor = 2
	colorpalette.KMTimes = 4
    palette = colorpalette.Create(pixels, amountOfColors)

    // apply dithering to the image
    paletted := process.ApplyErrorDiffusion(pixels, palette, &process.FloydSteinBerg)

    // save the image as a GIF (efficient for paletted images)
    imgutil.SaveGIF(paletted, "path/to/outputImage.gif")
}

License

This module is licensed under version 3 of the GNU General Public License.

Directories

Path Synopsis
Package gameofcolor is a generalization of the Conway's Game of Life idea.
Package gameofcolor is a generalization of the Conway's Game of Life idea.
Package gifeo can be used to create gif videos, from a premade set of images
Package gifeo can be used to create gif videos, from a premade set of images
Package imgutil offers some useful general functions for working with images within the dither module.
Package imgutil offers some useful general functions for working with images within the dither module.
Package particled implements a new image type that stores each (original) pixel with constant colour at variable location.
Package particled implements a new image type that stores each (original) pixel with constant colour at variable location.

Jump to

Keyboard shortcuts

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