Bonjour,

J'essaye d'appliquer un filtre sobel à mon image pour détecter les contours.
Je travaille sur une image en niveau de gris et lorsque je clique sur mon bouton rien ne s'affiche dans mon label.
Voici mon code :

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
private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {                                           
 
        int x1 = jLabel1.getWidth();
        int y1 = jLabel1.getHeight();
 
        int w = imgglobal.getWidth();
        int h = imgglobal.getHeight();
 
        BufferedImage imageBord = new BufferedImage(imgglobal.getWidth(),imgglobal.getHeight(), imgglobal.getType());
 
        //****************************
        int sobel_x[][] = { {-1,0,1},
                            {-2,0,2},
                            {-1,0,1}};
 
        int sobel_y[][] = {{-1,-2,-1},
                            {0,0,0},
                            {1,2,1}};
 
        int pixel_x;
        int pixel_y;
 
 
        for (int x=1; x < w-2; x++) {
            for (int y=1; y < h-2; y++) {
 
 
                pixel_x = (sobel_x[0][0] * imgglobal.getRGB(x-1,y-1)) + (sobel_x[0][1] * imgglobal.getRGB(x,y-1)) + (sobel_x[0][2] * imgglobal.getRGB(x+1,y-1)) +
                    (sobel_x[1][0] * imgglobal.getRGB(x-1,y))   + (sobel_x[1][1] * imgglobal.getRGB(x,y))   + (sobel_x[1][2] * imgglobal.getRGB(x+1,y)) +
                    (sobel_x[2][0] * imgglobal.getRGB(x-1,y+1)) + (sobel_x[2][1] * imgglobal.getRGB(x,y+1)) + (sobel_x[2][2] * imgglobal.getRGB(x+1,y+1));
 
                pixel_y = (sobel_y[0][0] * imgglobal.getRGB(x-1,y-1)) + (sobel_y[0][1] * imgglobal.getRGB(x,y-1)) + (sobel_y[0][2] * imgglobal.getRGB(x+1,y-1)) +
                    (sobel_y[1][0] * imgglobal.getRGB(x-1,y))   + (sobel_y[1][1] * imgglobal.getRGB(x,y))   + (sobel_y[1][2] * imgglobal.getRGB(x+1,y)) +
                    (sobel_y[2][0] * imgglobal.getRGB(x-1,y+1)) + (sobel_y[2][1] * imgglobal.getRGB(x,y+1)) + (sobel_x[2][2] * imgglobal.getRGB(x+1,y+1));
 
                int val = (int)Math.sqrt((pixel_x * pixel_x) + (pixel_y * pixel_y));
 
                if(val < 0)
                {
                   val = 0;
                }
 
                if(val > 255)
                {
                   val = 255;
                }
 
                imageBord.setRGB(x,y,val);
            }
        }
        //****************************
                imgglobal = imageBord;
 
                imagelabel = imgglobal.getScaledInstance(x1,y1,Image.SCALE_DEFAULT);
                //pour recadrer mon image dans mon label
 
                convol = new ImageIcon(imagelabel);
 
                jLabel1.setIcon(convol);
    }
Avez-vous une idée ? merci beaucoup