Comments (5)
i added an option to disable palette sorting, by default it is ordered by highest to lowest occurrence counts: .palette(tuples, noSort)
. you can get the palette histogram like this, for example:
var pal = quant.palette(false, true);
var palHist = [];
quant.idxi32.forEach(function(i32) {
palHist.push({color: quant.i32rgb[i32], count: quant.histogram[i32]});
});
console.log(palHist);
or
// called with no arguments (auto-sorted)
var pal = quant.palette();
var palHist = [];
quant.idxi32.forEach(function(i32) {
palHist.push({color: quant.i32rgb[i32], count: quant.histogram[i32]});
});
// sort it yourself
palHist.sort(function(a,b) {
return a.count == b.count ? 0 : a.count < b.count ? 1 : -1;
});
console.log(palHist);
fixed by a397b7e
from rgbquant.js.
Ah ok I didn't know that the color output palette is ordered. Thank you very much!
Edit: I just want to say that the output is not sorted. Here is an example that is in my code:
[
{
"color": [
255,
255,
255
],
"count": 630611
},
{
"color": [
207,
201,
188
],
"count": 1170
},
{
"color": [
30,
37,
63
],
"count": 3
},
{
"color": [
81,
98,
118
],
"count": 95290
}
]
This isn't ordered... but now I know how to order it, thank you...
from rgbquant.js.
since last commit, it should be ordered by counts if you disable sorting by using quant.palette(false, true)
instead of quant.palette()
it will still sort by default if you did not change the way the palette generation is called.
from rgbquant.js.
Ok thank you!
from rgbquant.js.
in your case it may be quant.palette(true, true)
, if you're wanting ordered tuples.
from rgbquant.js.
Related Issues (20)
- What is your License ? ( The MIT License (MIT) ?) HOT 1
- Make it async HOT 8
- Question: how do I use this library to save the quantized image as a file? HOT 2
- Demo site has 404 error HOT 4
- palette length for GIF HOT 1
- Question on usage HOT 1
- Rebuilding the palette HOT 2
- Visual artifacts HOT 2
- inconsistent sampling for population by palette size HOT 4
- Add LICENSE file to repo HOT 1
- Does not work for tiny images HOT 1
- dithSerp palette issue HOT 10
- test alternative color distance strategies HOT 1
- Ordered Dithering HOT 3
- Uint8Array image and serpentine dithering not supported? HOT 6
- Description of algorithm? HOT 10
- NPM package metadata does not include license
- Predefined palettes with 512 colors error with `Nothing has been sampled, palette cannot be built.` on `reduce`
- P5js HOT 1
- RGBA?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rgbquant.js.