GithubHelp home page GithubHelp logo

tiandiyiqi / halfgone Goto Github PK

View Code? Open in Web Editor NEW

This project forked from maxhalford/halfgone

0.0 0.0 0.0 1.7 MB

:white_square_button: Black and white digital halftoning

License: MIT License

Go 100.00%

halfgone's Introduction

halfgone

This repository contains implementations of digital halftoning - also called dithering - algorithms written in Go. The implementations are restricted to black and white rendering and are based on the image library from Go's standard library.

The implementations are quite fast but are not optimized for production where you would typically want to use bit shifting when possible. I moved the common code for error-diffusion dithering into a separate functions because it's always the same underlying algorithm, whether it be Floyd-Steinberg dithering or Stucki dithering. I did the same for ordered dithering. In production you would probably want to choose a particular dithering algorithm and avoid using generic code which makes it harder to write optimized code.

If you are interested in digital halftoning, this web page is, in my opinion, a fantastic introduction. I've also written a blog post which goes through some of the implementations.

Original image

img := LoadImage("images/penguin.jpg")

original

Grayscale

gray := ImageToGray(img)

grayscale

Inverted grayscale

InvertGray(gray)

reversed_grayscale

Threshold dithering

halfgone.ThresholdDitherer{Threshold: 127}.Apply(gray)

threshold_dithering

Random threshold dithering

halfgone.RandomThresholdDitherer{MaxThreshold: 255, RNG: rng}.Apply(gray)

random_threshold_dithering

Importance sampling

halfgone.ImportanceSampling{N: 4000, Threshold: 100, RNG: rng}.Apply(gray)

importance_sampling

Bosch and Herman’s grid-based dithering

halfgone.GridDitherer{K: 5, Alpha: 3, Beta: 8, RNG: rng}.Apply(gray)

grid_dithering

Ordered dithering

Order-2 ordered dithering

halfgone.Order2OrderedDitherer{}.Apply(gray)

order_2_ordered_dithering

Order-3 ordered dithering

halfgone.Order3OrderedDitherer{}.Apply(gray)

order_3_ordered_dithering

Order-4 ordered dithering

halfgone.Order4OrderedDitherer{}.Apply(gray)

order_4_ordered_dithering

Order-8 ordered dithering

halfgone.Order8OrderedDitherer{}.Apply(gray)

order_8_ordered_dithering

Error-diffusion dithering

Floyd-Steinberg dithering

halfgone.FloydSteinbergDitherer{}.apply(gray)

floyd_steinberg_dithering

Jarvis-Judice-Ninke dithering

halfgone.JarvisJudiceNinkeDitherer{}.Apply(gray)

jarvis_judice_ninke_dithering

Stucki dithering

halfgone.StuckiDitherer{}.Apply(gray)

stucki_dithering

Atkinson dithering

halfgone.AtkinsonDitherer{}.Apply(gray)

atkinson_dithering

Burkes dithering

halfgone.BurkesDitherer{}.Apply(gray)

burkes_dithering

Sierra dithering

halfgone.SierraDitherer{}.Apply(gray)

seria_dithering

Two-row Sierra dithering

halfgone.TwoRowSierraDitherer{}.Apply(gray)

two_row_seria_dithering

Sierra Lite dithering

halfgone.SierraLiteDitherer{}.Apply(gray)

seria_lite_dithering

License

The MIT License (MIT). Please see the license file for more information.

halfgone's People

Contributors

maxhalford avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.