Java library to grab color palettes from image.
First of all you need to create an ImageColorAnalyzer object:
ImageColorAnalyzer imageColorAnalyzer = new ImageColorAnalyzer("path/to/image.png");
Available constructors:
public ImageColorAnalyzer();
public ImageColorAnalyzer(String path);
public ImageColorAnalyzer(int ALG_QUALITY);
public ImageColorAnalyzer(String path, int ALG_QUALITY);
After you created object, you can use this methods:
public void getImageData();
public ArrayList<int[]> getPalette(int colors, ANALYZER_ALGORITHM algorithm)
public int getQuality();
public boolean setQuality(int ALG_QUALITY);
public void changeImage(String path);
public int[] getAverageColor();
public int[] getDominantColor();
public void getImageData()
Get image pixels RGB data. You need to call it right before
public ArrayList<int[]> getPalette(int colors);
only one time.
public ArrayList<int[]> getPalette(int colors, ANALYZER_ALGORITHM algorithm)
Get color palettes from BufferedImage. Algorithms you can use:
enum ANALYZER_ALGORITHM { ALG_MEDIAN_CUT, ALG_K_MEANS }
public int getQuality();
Getter for ALG_QUALITY.
public boolean setQuality(int ALG_QUALITY);
Setter for ALG_QUALITY. Range is from
1
to10
. The less numbers - the better results you will get.
public void changeImage(String path);
Used to change image.
public int[] getAverageColor();
Get image average color. First of all you need to call
public void getImageData();
public int[] getDominantColor();
Get image dominant color. First of all you need to call
public ArrayList<int[]> getPalette(int colors, ANALYZER_ALGORITHM algorithm);
Code used for test:
public class Main
{
public static void main(String[] args)
{
ImageColorAnalyzer imageColorAnalyzer = new ImageColorAnalyzer("testImage/1.jpg");
imageColorAnalyzer.setQuality(10);
imageColorAnalyzer.getImageData();
//for (int[] color: imageColorAnalyzer.getPalette(16, ImageColorAnalyzer.ANALYZER_ALGORITHM.ALG_MEDIAN_CUT))
for (int[] color: imageColorAnalyzer.getPalette(12, ImageColorAnalyzer.ANALYZER_ALGORITHM.ALG_K_MEANS))
System.out.println(Arrays.toString(color));
}
}
K-Mean | Median-Cut
[7, 8, 5] | [12, 13, 11]
[12, 12, 10] | [17, 18, 15]
[15, 16, 14] | [21, 19, 17]
[19, 18, 16] | [19, 21, 23]
[13, 21, 29] | [22, 23, 19]
[22, 22, 20] | [34, 22, 22]
[26, 25, 24] | [25, 25, 24]
[48, 25, 25] | [15, 25, 35]
[7, 26, 46] | [31, 28, 26]
[33, 30, 31] | [35, 29, 30]
[3, 34, 66] | [56, 31, 34]
[49, 34, 40] | [5, 32, 59]
[68, 37, 41] | [40, 33, 38]
[87, 48, 51] | [76, 37, 38]
[143, 85, 68] | [68, 42, 50]
[207, 166, 137] | [110, 67, 63]
Dominant color | Average color
[26, 25, 24] | [37, 29, 32]
K-Mean | Median-Cut
[14, 24, 18] | [16, 27, 20]
[20, 30, 24] | [21, 32, 26]
[11, 50, 29] | [27, 34, 27]
[26, 36, 29] | [15, 50, 31]
[34, 44, 36] | [28, 37, 32]
[59, 51, 37] | [32, 44, 34]
[22, 63, 40] | [34, 52, 42]
[40, 67, 50] | [54, 57, 46]
[84, 68, 52] | [31, 71, 47]
[58, 75, 61] | [57, 79, 62]
[74, 84, 73] | [69, 76, 64]
[89, 95, 86] | [86, 76, 62]
[129, 102, 84] | [81, 87, 81]
[110, 117, 109] | [89, 102, 91]
[138, 138, 132] | [121, 117, 107]
[167, 165, 160] | [154, 154, 149]
Dominant color | Average color
[26, 36, 29] | [57, 68, 58]
K-Mean | Median-Cut
[1, 4, 9] | [1, 4, 9]
[0, 5, 9] | [1, 4, 10]
[2, 6, 12] | [1, 6, 10]
[1, 7, 13] | [2, 6, 12]
[23, 8, 13] | [2, 6, 13]
[3, 8, 14] | [2, 9, 15]
[5, 11, 18] | [4, 18, 27]
[14, 16, 26] | [3, 19, 28]
[3, 17, 26] | [11, 19, 29]
[57, 17, 28] | [54, 17, 31]
[103, 3, 29] | [3, 22, 32]
[4, 22, 32] | [5, 23, 33]
[25, 24, 35] | [6, 24, 34]
[6, 27, 38] | [5, 25, 36]
[159, 4, 44] | [5, 27, 38]
[196, 117, 117] | [6, 29, 39]
Dominant color | Average color
[6, 27, 38] | [7, 16, 25]
K-Mean | Median-Cut
[0, 0, 0] | [8, 1, 1]
[3, 0, 0] | [12, 4, 2]
[6, 1, 0] | [17, 4, 4]
[9, 1, 1] | [17, 7, 4]
[13, 3, 2] | [18, 7, 6]
[18, 6, 5] | [21, 7, 6]
[27, 11, 9] | [25, 7, 7]
[54, 22, 4] | [19, 11, 10]
[92, 30, 3] | [27, 10, 10]
[2, 42, 51] | [30, 16, 5]
[138, 53, 14] | [31, 13, 13]
[4, 63, 87] | [48, 19, 4]
[2, 85, 132] | [75, 23, 1]
[206, 101, 40] | [90, 37, 9]
[1, 124, 195] | [0, 80, 118]
[250, 214, 186] | [170, 82, 36]
Dominant color | Average color
[27, 11, 9] | [38, 20, 15]