[déplacé Bar -> JAVA] génération de l'histogramme d'une image
rihabj
Messages postés4Date d'inscriptionmercredi 19 novembre 2008StatutMembreDernière intervention17 décembre 2008
-
14 déc. 2008 à 17:56
Flachy Joe
Messages postés2103Date d'inscriptionjeudi 16 septembre 2004StatutMembreDernière intervention21 novembre 2023
-
14 déc. 2008 à 18:41
slt, je suis une débutante dans le traitement d'image avec java, et je veux générer un histogramme d'une image j'ai essayé avec ce code source mais sans vain.Est ce qu'il ya qu'elqu'un qui peut m'aider et me dire ou est l'erreur
je travail avec eclipse et avec l'API JAI
******voiçi mon code source*********
public class Creation {
public static void main(String args[]){
System.out.println("Creation de l'image");
ImageIcon imageIcon = new ImageIcon("signature.JPG");
Image imageTemp = imageIcon.getImage();
BufferedImage image = new BufferedImage(imageTemp.getWidth(null), imageTemp.getHeight(null), BufferedImage.TYPE_BYTE_GRAY);
image.getGraphics().drawImage(imageTemp, 0, 0, null);
// int[] valeur = image.getData().getPixel(x, y, (int[])null);
/* int[] pixels = new int[image.getWidth() * image.getHeight()];
PixelGrabber pg = new PixelGrabber(image, 0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());
try {
pg.grabPixels();
} catch (InterruptedException e) {
System.err.println("interrupted waiting for pixels!");
}
// Set up the parameters for the Histogram object.
int[] bins = {256, 256, 256}; // The number of bins.
double[] low = {0.0D, 0.0D, 0.0D}; // The low value.
double[] high = {256.0D, 256.0D, 256.0D}; // The high value.
// Construct the Histogram object.
Histogram hist = new Histogram(bins, low, high);
// Create the parameter block.
ParameterBlock pb = new ParameterBlock();
pb.addSource(image); // Specify the source image
pb.add(hist); // Specify the histogram
pb.add(null); // No ROI
pb.add(1); // Sampling
pb.add(1); // periods
// Perform the histogram operation.
dst = (PlanarImage)JAI.create("histogram", pb, null);
// Retrieve the histogram data.
hist = (Histogram) dst.getProperty("histogram");