Extract Colors from images
in
Programming Questions
•
3 years ago
Hi,
I want to achieve something that is simple: Read colors from an image and sort them in an array.
Colors should be sorted from most occurency found to less.
The result should be a string array, each element is a color hex value.
I know that have must be done thousand times but i'm just having fun trying to find an efficient algorithm (so please don't post full source code as a response ;)). That's where i need some help.
Actually, here's my process :
0 | ColorValue#1 | NbrOccurences#2
1 | ColorValue#2 | NbrOccurences#2
I think the ColorValue#n should be a String in the form XXXXXX (hex color value) and the NbrOccurences#n could be an int which is equal to the number of pixels that.
So my question is :
What kind of data should i use ? A class for ColorValue#n | NbrOccurences#n ? ArrayList ? 2-dimensional Array (and set NbreOccurences as a String ?) What kind of optimisation could be use to speed up that stuff ?
If i suceed in something efficient, i might try to make a tool from that idea.
So any help appreciated.
Regards.
I want to achieve something that is simple: Read colors from an image and sort them in an array.
Colors should be sorted from most occurency found to less.
The result should be a string array, each element is a color hex value.
I know that have must be done thousand times but i'm just having fun trying to find an efficient algorithm (so please don't post full source code as a response ;)). That's where i need some help.
Actually, here's my process :
- Load image in memory (i.e loadImage).
- Access image pixels color value (i.e loadPixels()).
- Loop through all image's pixels.
- If the pixel colors is not found in the colors' array add it the colors' array (so it's size should be dynamically set -> Vectors or ArrayList ?). Else (If the pixels colors is found in the array) increment a number that represent the color balance count (in order to sort the array later).
0 | ColorValue#1 | NbrOccurences#2
1 | ColorValue#2 | NbrOccurences#2
I think the ColorValue#n should be a String in the form XXXXXX (hex color value) and the NbrOccurences#n could be an int which is equal to the number of pixels that.
So my question is :
What kind of data should i use ? A class for ColorValue#n | NbrOccurences#n ? ArrayList ? 2-dimensional Array (and set NbreOccurences as a String ?) What kind of optimisation could be use to speed up that stuff ?
If i suceed in something efficient, i might try to make a tool from that idea.
So any help appreciated.
Regards.
1