1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.PixelGrabber;
import java.awt.image.renderable.ParameterBlock;
import javax.media.jai.Histogram;
import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
import javax.swing.ImageIcon;
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");
// Print 3-band histogram.
for (int i=0; i< histogram.getNumBins(); i++) {
System.out.println(hist.getBinSize(0, i) + " " +
hist.getBinSize(1, i) + " " +
hist.getBinSize(2, i) + " " )
}
}
} |
Partager