http://lokeshdhakar.com/color-thief/
download page:
https://github.com/lokesh/color-thief
demo page
http://lokeshdhakar.com/projects/color-thief
this script is free to use and modify as long as attribution is kept in the code.
I tried to integrate it into my own script, but I get "construction" errors right away and can't figure out how to get the good info to the parts that matter and get the color info for the color palette info as rgb or hexadecimal values that I can actually use since this code was obviously designed to work inside a webpage.
existing js for finding common colors can it be integrated?
-
Mike Hale
existing js for finding common colors can it be integrated?
I don't think you will be able to adapt a web script that uses the browser DOM to Photoshop. Photoshop doesn't have access to the browser DOM and I bet the "construction" errors are where it's trying to create browser DOM objects.
-
christopherjohnson
existing js for finding common colors can it be integrated?
so um there is no way to get accurate results with Photoshop. :-/
I get stuck at "... .getElementById('canvas').getContext('2d');" that I see in this script and related scripts.
it goes on to take that info to get image hight and with and # of pixels which of course is no problem to get in normal scripting, but another part of the image data it seems to get there is an array of rgb+alpha values if I'm reading the code correctly and I have no idea how to get those values to pass on to the rest of the useful code.
I get stuck at "... .getElementById('canvas').getContext('2d');" that I see in this script and related scripts.
it goes on to take that info to get image hight and with and # of pixels which of course is no problem to get in normal scripting, but another part of the image data it seems to get there is an array of rgb+alpha values if I'm reading the code correctly and I have no idea how to get those values to pass on to the rest of the useful code.
-
Mike Hale
existing js for finding common colors can it be integrated?
.getElementById is a browser DOM method and will not work in a Photoshop script.
Here are the problems as I see them in getting an accurate count of common colors in Photoshop via a script, with the keyword being accurate.
1. Unless you are taking about a small image there is too much data for a script to handle and you run into performance problems.
2. Unless you are taking about grayscale, indexMode, or simple graphics there are too many colors to deal with.
3. Anything you do to reduce the numbers of colors such as resample, change to indexMode, mosaic or some other type of averaging changes the colors and some original colors may be lost.
4. What do you mean by color? To me this is the biggest problem. What is pink? Is it just 255,204,204 in sRGB? What about other color modes or profiles? If you want a range of 'pinks', how do you determine what number values are acceptable as pink.
I think the real problem is Photoshop is too accurate when it comes to getting colors. When you tell it to count pixels that are 255,204,204 and it reports that there aren't many pixels with that color doesn't mean it is not accurate just because you 'see' a lot more 'pink' in the image.
Here are the problems as I see them in getting an accurate count of common colors in Photoshop via a script, with the keyword being accurate.
1. Unless you are taking about a small image there is too much data for a script to handle and you run into performance problems.
2. Unless you are taking about grayscale, indexMode, or simple graphics there are too many colors to deal with.
3. Anything you do to reduce the numbers of colors such as resample, change to indexMode, mosaic or some other type of averaging changes the colors and some original colors may be lost.
4. What do you mean by color? To me this is the biggest problem. What is pink? Is it just 255,204,204 in sRGB? What about other color modes or profiles? If you want a range of 'pinks', how do you determine what number values are acceptable as pink.
I think the real problem is Photoshop is too accurate when it comes to getting colors. When you tell it to count pixels that are 255,204,204 and it reports that there aren't many pixels with that color doesn't mean it is not accurate just because you 'see' a lot more 'pink' in the image.
-
christopherjohnson
existing js for finding common colors can it be integrated?
ok, I imagined that it was a web only thing. I'm just surprised that there is no alternative for doing this accurately.
I actually have my own list of RGB to color list comparisons I just need to get the color palette like in this script or on webpages, I need to find a way to use it quickly though either having an external script save text I can open and use per image or integrate it. I've been trying to find a way for several days now trying different things.
The color selector option gave many false positives or many false negatives.
the other script I tried is a little better but would totally skip brighter colors and report gray as being a common color even when it wasn't.
I have trouble thinking that I'm the only one who wants to get a color palette from an image and get the values from the palette sort them and then use them for sorting etc.
I just need something to get the values of the color palette/aka main colors as rgb or hexadecimal in a variable (array) and from there I can do the rest.
I actually have my own list of RGB to color list comparisons I just need to get the color palette like in this script or on webpages, I need to find a way to use it quickly though either having an external script save text I can open and use per image or integrate it. I've been trying to find a way for several days now trying different things.
The color selector option gave many false positives or many false negatives.
the other script I tried is a little better but would totally skip brighter colors and report gray as being a common color even when it wasn't.
I have trouble thinking that I'm the only one who wants to get a color palette from an image and get the values from the palette sort them and then use them for sorting etc.
I just need something to get the values of the color palette/aka main colors as rgb or hexadecimal in a variable (array) and from there I can do the rest.