{"id":17189107,"url":"https://github.com/esimov/colorquant","last_synced_at":"2025-04-13T19:23:24.862Z","repository":{"id":91223552,"uuid":"85500800","full_name":"esimov/colorquant","owner":"esimov","description":"Go library for color quantization and dithering","archived":false,"fork":false,"pushed_at":"2021-01-21T14:33:23.000Z","size":2374,"stargazers_count":85,"open_issues_count":0,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-27T10:04:20.207Z","etag":null,"topics":["color-quantization","dithering","draw","golang","image-processing","quantization"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/esimov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"esimov"}},"created_at":"2017-03-19T18:58:02.000Z","updated_at":"2024-09-01T18:08:40.000Z","dependencies_parsed_at":"2023-03-20T18:16:51.159Z","dependency_job_id":null,"html_url":"https://github.com/esimov/colorquant","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esimov%2Fcolorquant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esimov%2Fcolorquant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esimov%2Fcolorquant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esimov%2Fcolorquant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/esimov","download_url":"https://codeload.github.com/esimov/colorquant/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248766687,"owners_count":21158302,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["color-quantization","dithering","draw","golang","image-processing","quantization"],"created_at":"2024-10-15T01:10:45.939Z","updated_at":"2025-04-13T19:23:24.841Z","avatar_url":"https://github.com/esimov.png","language":"Go","funding_links":["https://github.com/sponsors/esimov"],"categories":[],"sub_categories":[],"readme":"# Colorquant\n[![CI](https://github.com/esimov/colorquant/workflows/CI/badge.svg)](https://github.com/esimov/colorquant/actions)\n[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go)](https://pkg.go.dev/github.com/esimov/colorquant)\n[![license](https://img.shields.io/github/license/esimov/colorquant)](./LICENSE)\n\nColorquant is an image / color quantization library written in Go. It can be considered as a replacement for the quantization and dithering part of the \u003ca href=\"https://golang.org/pkg/image/draw/\"\u003edraw\u003c/a\u003e method from the core image library for various reasons (see below).\n\n### The purpose\n\nThe purpose of color quantization is to reduce the color palette of an image to a fraction of it's initial colors (usually 256), but to preserve it's representative colors and to elliminate visual artifacts at the same time. Even with the best set of 256 colors, there are many images that look bad. They have visible contouring in regions where the color changes slowly. \n\nTo create a smoother transition between colors and to wash out the edges various dithering methods can be plugged in.\n\n### Implementation\n\nThe implementation is mainly based on the article from \u003ca href=\"http://www.leptonica.com/color-quantization.html\"\u003eLeptonica\u003c/a\u003e.\n\nThe reason why I opted for a custom quantization and dithering algorithm are twofold:\n* First, even if the core draw method uses an error quantization algorithm, it does not provide support for the quantization level, which means to how many colors we wish to reduce the original image.\n* Second, the dithering method is based exclusively on Floyd-Steinberg dithering method, but there are other dithering algorithm, which can be used (ex. Burkes, Stucki, Atkinson, Sierra etc.).\n\n### Installation\n\n`go get -u github.com/esimov/colorquant`\n\n### Running\n\nThe library provides a CLI method to generate the quantified images. Type `go run cli.go --help` to check the supported commands.\n\n```\nUsage of commands:\n  -compression int\n    \tJPEG compression. (default 100)\n  -ditherer string\n    \tDithering method. (default \"FloydSteinberg\")\n  -no-dither\n    \tUse image quantizer without dithering.\n  -output string\n    \tOutput directory. (default \"output\")\n  -palette int\n    \tThe number of palette colors. (default 256)\n  -type string\n    \tImage type. Possible options .jpg, .png (default \"jpg\")\n\n```\nThe generated images will be exported into the `output` folder. By default the \u003ci\u003e\u003cstrong\u003eFloyd-Steinberg\u003c/strong\u003e\u003c/i\u003e dithering method is applied, but if you whish to \u003cstrong\u003enot\u003c/strong\u003e use any dithering algorithm use the `--no-dither` flag.\n\n### Usage\n\n#### ➤ Without dithering\nThis is main method to generate a non-dithered quantified image:\n\n```go\ncolorquant.NoDither.Quantize(src, dst, numColors, false, true)\n```\nwhere the last paremeter means either to use the library quantization algorithm (if the parameter is \u003ci\u003etrue\u003c/i\u003e), otherwise use the quantization level provided by the paletted image (if the paramater is \u003ci\u003efalse\u003c/i\u003e).\n\n#### ➤ With dithering\n\n```go\nditherer.Quantize(src, dst, numColors, true, true)\n```\nwhere ditherer is a struct with the form of:\n\n```go\n\"FloydSteinberg\" : colorquant.Dither{\n\t[][]float32{\n\t\t[]float32{ 0.0, 0.0, 0.0, 7.0 / 48.0, 5.0 / 48.0 },\n\t\t[]float32{ 3.0 / 48.0, 5.0 / 48.0, 7.0 / 48.0, 5.0 / 48.0, 3.0 / 48.0 },\n\t\t[]float32{ 1.0 / 48.0, 3.0 / 48.0, 5.0 / 48.0, 3.0 / 48.0, 1.0 / 48.0 },\n\t},\n},\n```\n### Examples\n\nAll the examples below are generated using *Floyd-Steinberg* dithering method with the following command line as an example:\n\n`go run cli.go ../input/treefrog.jpg -compression 100 -ditherer FloydSteinberg -palette 128`\n\n| Number of colors | Without dither | With Dither\n|:--:|:--:|:--:|\n| *128* | \u003cimg src=\"https://cloud.githubusercontent.com/assets/883386/26618632/b0e865b2-45e3-11e7-9312-c66f5d690312.jpg\"\u003e | \u003cimg src=\"https://cloud.githubusercontent.com/assets/883386/26618639/b623c77e-45e3-11e7-8900-2850bb8a0a9d.jpg\"\u003e |\n| *256* | \u003cimg src=\"https://cloud.githubusercontent.com/assets/883386/26618480/2f9b1158-45e3-11e7-9851-742a21e1f8af.jpg\"\u003e | \u003cimg src=\"https://cloud.githubusercontent.com/assets/883386/26618461/229eb626-45e3-11e7-8fa4-9eaeeeb55712.jpg\"\u003e | \n| *512* | \u003cimg src=\"https://cloud.githubusercontent.com/assets/883386/26630928/7f3bb82e-4611-11e7-9a2d-ecaaea11c25b.jpg\" \u003e | \u003cimg src=\"https://cloud.githubusercontent.com/assets/883386/26630921/764a2598-4611-11e7-9c60-3d63cd2759c3.jpg\"\u003e | \n| *1024* | \u003cimg src=\"https://cloud.githubusercontent.com/assets/883386/26619097/a27027de-45e5-11e7-83b3-cb5b9e7d7079.jpg\" \u003e | \u003cimg src=\"https://cloud.githubusercontent.com/assets/883386/26619106/a8ec32b0-45e5-11e7-9642-c0f74a384544.jpg\"\u003e | \n\n## Author\n\n* Endre Simo ([@simo_endre](https://twitter.com/simo_endre))\n\n## License\n\nCopyright © 2017 Endre Simo\n\nThis software is distributed under the MIT license. See the [LICENSE](https://github.com/esimov/colorquant/blob/master/LICENSE) file for the full license text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesimov%2Fcolorquant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fesimov%2Fcolorquant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesimov%2Fcolorquant/lists"}