I have three different images (jpeg or bmp). I'm trying to predict the complexity of each image based on the number of color of each. How could I make it possible with Java? Thank you.
UPDATE: These codes doesn't work .. the output shows 1312 colors even it only plain red and white
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.ArrayList;
import javax.imageio.ImageIO;
public class clutters {
public static void main(String[] args) throws IOException {
ArrayList<Color> colors = new ArrayList<Color>();
BufferedImage image = ImageIO.read(new File("1L.jpg"));
int w = image.getWidth();
int h = image.getHeight();
for(int y = 0; y < h; y++) {
for(int x = 0; x < w; x++) {
int pixel = image.getRGB(x, y);
int red = (pixel & 0x00ff0000) >> 16;
int green = (pixel & 0x0000ff00) >> 8;
int blue = pixel & 0x000000ff;
Color color = new Color(red,green,blue);
//add the first color on array
if(colors.size()==0)
colors.add(color);
//check for redudancy
else {
if(!(colors.contains(color)))
colors.add(color);
}
}
}
system.out.printly("There are "+colors.size()+"colors");
}
}