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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
| package STAGE;
public class Histogrammebilineaire extends JPanel
{
BufferedImage monImage;
BufferedImage monImage2;
//public Histogrammebilineaire(){
/* try {
File input = new File("d:/bordd.JPG");
File input2 = new File("d:/bor.JPG");
monImage = ImageIO.read(input);
monImage2 = ImageIO.read(input);
int max=0;
int nbpts=0;
int M=1;
for (int i = 0; i < monImage.getHeight() ; i++) {
for (int j = 0 ; j < monImage.getWidth() ; j++) {
for (int k = 0; k < monImage2.getHeight(); k++) {
for (int l = 0; l <monImage2.getWidth(); l++) {
int pixel = monImage.getRGB(j + k, i + l);
int gray = (pixel >> 16) & 0xff;
if (max<M){
max=M;
nbpts++;
}
}}}}
} catch (Exception e) {
e.printStackTrace();
}
} */
public static void Fenetre()
{
JFrame fenetre = new JFrame();
fenetre.setSize(273, 295);
fenetre.setTitle("Histogramme Bilinéaire");
JPanel panneau = new Histogrammebilineaire();
panneau.setBackground(Color.WHITE);
fenetre.add(panneau);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.setVisible(true);
}
@Override
public void paintComponent(Graphics g)
{
File input = new File("d:/courbure.jpg");
File input2 = new File("d:/test.bmp");
try {
monImage = ImageIO.read(input);
monImage2 = ImageIO.read(input2);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
super.paintComponent(g);
int larg = getWidth();
int haut = getHeight();
int dim = 8; //dimension d'une case de la grille
// La grille:
for(int i = 0; i < dim*33; i +=dim)
{
g.drawLine(i,0,i, haut); // Les lignes verticales de la grille
g.drawLine(0,i,larg, i); // Les lignes horizontales de la grille
// System.out.println(i);
}
for(int j = 0; j < dim*32; j +=dim)
{
// Remplir les cases:
for(int i = 0; i < dim*32; i +=dim)
{
for ( i = 0; i < monImage.getHeight() ; i++) {
for ( j = 0 ; j < monImage.getWidth() ; j++) {
for (i = 0; i < monImage2.getHeight(); i++) {
for (j = 0; j <monImage2.getWidth(); j++) {
int pixel = monImage.getRGB(j , i );
int gray = (pixel >> 16) ;
int pixel2= monImage2.getRGB(j, i);
int gray2 = (pixel2 >> 16) ;
int valeur = (gray+gray2)>>1;
g.setColor(new Color(valeur, valeur, valeur));
g.setColor(Color.blue); // couleur de remplissage
g.fillRect(i*8, j*8, 8, 8); // remplissage (fill)
g.setColor(Color.green); // couleur du panel
}
} }
}}}
}
public static void main (String [] arg)
{
Fenetre();
}
} |
Partager