Bonjour à toutes et à tous
j'ai un petit souci avec mon bout de code.
j'essaie d'écrire le code java pour segmenter une image avec l'approche croissance de région.
quand j'exécute le code il m'affiche des exceptions.
est ce que qlq peut m'aider s'il vous plait
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
//************************Growing****************************
 /**
  * This method performs the bulk of the processing. It runs a classic stack-based
  * region growing algorithm:
  * 1 - Find a pixel which is not labeled. Label it and store its coordinates on a
  *     stack.
  * 2 - While there are pixels on the stack, do:
  *   3 - Get a pixel from the stack (the pixel being considered).
  *   4 - Check its neighboors to see if they are unlabeled and close to the
  *       considered pixel; if are, label them and store them on the stack.
  * 5 - Repeat from 1) until there are no more pixels on the image.
le code est pour une image en entré noir et blanc
  */
 
 private int width,height;
 private int[][] labels;
 
 private void Growing(BufferedImage image){
	 width=image.getWidth();
	 height=image.getHeight();
	 labels = new int[width][height];
	 Stack<Point> mustDo = new Stack<Point>();
 
      for(int h=0;h<height;h++)
          for(int w=0;w<width;w++)
         {labels[w][h] = 0;}
//pour simplifier le code j'ai fixer le  germe(seed) de départ à mon choix (x=5,y=8)
      int x=5;
      int y=8;   
      labels[x][y]=1;
      mustDo.add(new Point(x,y));
      while(mustDo.size() > 0)
           {
           Point thisPoint = mustDo.get(0); mustDo.remove(0);
           // Check 8-neighborhood
            for(int th=-1;th<=1;th++)
              for(int tw=-1;tw<=1;tw++)
                {
                int rx = thisPoint.x+tw;
                int ry = thisPoint.y+th;
 
                if ((rx < 0) || (ry < 0) || (ry>=height) || (rx>=width)) continue;
                int rgb1 = buffeurActuel.getRGB(rx, ry);
		        int rgb2=buffeurActuel.getRGB(thisPoint.x,thisPoint.y);
			    if (labels[rx][ry] < 0) {            	    
			       if (rgb1 == rgb2){ 
                   mustDo.add(new Point(rx,ry));
                   labels[rx][ry] = 1;
 
                   }
                } 
             } 
          } 
 
     int [] output = new int [width*height];
     int count =0;
     for (int h=0;h<=height;h++)
    	 for(int w=0;w<=width;w++)
    		 output[count++]=labels[w][h];
 
 
 
 
    image2 = createImage (new MemoryImageSource( larg,haut, output, 0 ,larg));
	arriere.removeAll();
	zoneImage=new PanneauImage(image2,larg,haut);
	arriere.add("Center",zoneImage);
}
il m'affiche l'ecxeption
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 384
at Growing.ClasseMenu.Growing(ClasseMenu.java:209)
sur la ligne suivant
output[count++]=labels[w][h];
j'utilise un tableau à 1 dimension "output" pour stocker les valeurs du "labels"(matrice) et puis je passe "output" comme argument dans
Code : Sélectionner tout - Visualiser dans une fenêtre à part
image2 = createImage (new MemoryImageSource( larg,haut, output, 0 ,larg));
pour créer mon image résultat.
Alors quand j'essaie d'afficher la taille de chaque tableau en utilisant:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
System.out.println(width);
System.out.println(height);
System.out.println(labels.length);
System.out.println(output.length);
il m'affiche le résultat suivant:
width
384
height
294
labels
384
output
112896
la taille du labels < taille du output!!!!!!
aide moi s'il vous plait
merci d'avance.