[Info][Graphisme]histogramme à partir d'une image
Bonjour,
A partir d'une image jpeg, je souhaiterais créer les histogrammes correspondant aux 3 couleurs RGB. J'ai créé le code suivant mais cela prend beaucoup de temps pour une image de 1000 * 1000.
Y aurait-il une fonction spécifique pour obtenir cet histogramme.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
/** Lecture de tous les pixels : */
int w = bufferedImage.getWidth();
int h = bufferedImage.getHeight();
int[] rgbs = new int[w*h]; /** on crée l'espace néccessaire */
bufferedImage.getRGB(0,0,w,h,rgbs,0,w);
/** Lecture manuelle des composantes : */
for (int i = 0; i < rgbs.length; i++) {
int rouge = (rgbs[i] >>16 ) & 0xFF;
int vert = (rgbs[i] >> 8 ) & 0xFF;
int bleu = rgbs[i] & 0xFF;
histoRouge.add(rouge, Integer.toString(Integer.parseInt(histoRouge.get(rouge).toString()) + 1));
histoVert.add(vert, Integer.toString(Integer.parseInt(histoRouge.get(vert).toString()) + 1));
histoBleu.add(bleu, Integer.toString(Integer.parseInt(histoRouge.get(bleu).toString()) + 1));
} |
Merci d'avance
Yannick
Modéré par Thibaut ajout balises [Code], titre.