Algorithm for color quantization/reduced image color palette in JavaScript? [closed]

雨燕双飞 提交于 2019-11-27 19:26:21

With the caveat that I don't claim any expertise at all in any field of image processing: I read over the Wikipedia article you linked, and from there found Dan Bloomberg's Leptonica. From there you can download the sources for the algorithms discussed and explained.

The source code is in C, which hopefully is close enough to JavaScript (at least in the core "formula" parts) to be understandable. The basic ideas behind the "MMCQ" algorithm don't seem super-complicated. It's really just some heuristic tricks for splitting up the 3-dimensional color space into sub-cubes based on the way colors in an image clump together.

I wrote a web app that extracts a color palette from an image. It allows you to load an image, then play around with three different algorithms/approaches for extracting a color palette from it:

  1. Simple histogramming
  2. Median Cut
  3. k-means

You can find a copy of it running here

You can find the code for it on github

It's written 100% in Javascript, and uses Plotly.js for the example plots.

I also wrote a post describing the three approaches/algorithms in more detail - you can find that here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!