Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can palette shows up color occurence amount #5

Closed
frankred opened this issue Aug 13, 2014 · 5 comments
Closed

Can palette shows up color occurence amount #5

frankred opened this issue Aug 13, 2014 · 5 comments

Comments

@frankred
Copy link

Is there a possibility to get information about the occurence amount of the final colors? My intention is to sort the palette by occurence amount.

@frankred frankred changed the title Palette shows up color occurence amount Can palette shows up color occurence amount Aug 13, 2014
@leeoniya
Copy link
Owner

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

@frankred
Copy link
Author

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...

@leeoniya
Copy link
Owner

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.

@frankred
Copy link
Author

Ok thank you!

@leeoniya
Copy link
Owner

in your case it may be quant.palette(true, true), if you're wanting ordered tuples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants