Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

jcmellado/dart-neuquant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Port to Dart of NeuQuant algorithm by Anthony Dekker, 1994:
http://members.ozemail.com.au/~dekker/NEUQUANT.HTML

Example

To the left a 32 bits RGBA image with 68,289 unique colors. To the right the same image with just 256 colors after quantization:

Neuquant

Usage

The algorithm performs quantization of a 32-bit RGBA image to 8-bit colour. By adjusting a sampling factor, the algorithm can either produce extremely high-quality images slowly, or produce good images in reasonable times. A sampling factor of 10 gives a substantial speed-up, with a small quality penalty.

import "dart:html";
import "package:neuquant/neuquant.dart";

void main() {
  var image = query("#image") as ImageElement;
  var canvas = query("#canvas") as CanvasElement;
  var context = canvas.context2D;

  context.drawImage(image, 0, 0);

  var imageData = context.getImageData(0, 0, canvas.width, canvas.height);

  neuquant(imageData.data, 10);

  context.putImageData(imageData, 0, 0);
}

About

Neural network image quantization

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages