IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

2D Java Discussion :

Détection de contour d'image Java


Sujet :

2D Java

  1. #1
    Futur Membre du Club
    Femme Profil pro
    Inscrit en
    Décembre 2011
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4
    Points : 5
    Points
    5
    Par défaut Détection de contour d'image Java
    Bonjour
    je suis en cour de réaliser un programme java qui détecte le contour d'une image mais je n'arrive pas ,je trouve dans le site une méthode qui nécessite
    un bafferedImage or je besion d'une methode avec plannarImage
    voici le code d'action performed de boutton de l'inerface:

    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
    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
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    import java.awt.image.BufferedImage;
    import java.awt.image.ConvolveOp;
    import java.awt.image.Kernel;
    import java.awt.image.renderable.ParameterBlock;
    import javax.media.jai.InterpolationBilinear;
    import javax.media.jai.JAI;
    import javax.media.jai.PlanarImage;
    import javax.swing.ImageIcon;
    import javax.swing.JFileChooser;
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /*
     * FENETRE.java
     *
     * Created on 13 déc. 2011, 19:34:42
     */
     
    /**
     *
     * @author Administrateur
     */
    public class FENETRE extends javax.swing.JFrame {
     
        /** Creates new form FENETRE */
        public FENETRE() {
            initComponents();
        }
     
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
     
            jButton1 = new javax.swing.JButton();
            url = new java.awt.TextField();
            img = new javax.swing.JLabel();
            jButton2 = new javax.swing.JButton();
            jLabel1 = new javax.swing.JLabel();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            jButton1.setBackground(new java.awt.Color(102, 102, 255));
            jButton1.setFont(new java.awt.Font("SansSerif", 1, 14));
            jButton1.setText("Parcourir image");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });
     
            img.setText("jLabel1");
     
            jButton2.setBackground(new java.awt.Color(102, 102, 255));
            jButton2.setFont(new java.awt.Font("Serif", 1, 14));
            jButton2.setText("Transformation");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton2ActionPerformed(evt);
                }
            });
     
            jLabel1.setText("jLabel1");
     
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(layout.createSequentialGroup()
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(layout.createSequentialGroup()
                                    .add(93, 93, 93)
                                    .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 147, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .add(layout.createSequentialGroup()
                                    .addContainerGap()
                                    .add(img, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 240, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(layout.createSequentialGroup()
                                    .add(90, 90, 90)
                                    .add(url, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 436, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .add(layout.createSequentialGroup()
                                    .add(270, 270, 270)
                                    .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 262, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                            .add(308, 308, 308))
                        .add(layout.createSequentialGroup()
                            .add(263, 263, 263)
                            .add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 155, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .add(85, 85, 85)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(url, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 33, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 46, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(25, 25, 25)
                    .add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 48, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(23, 23, 23)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(img, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 274, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 261, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(45, Short.MAX_VALUE))
            );
     
            pack();
        }// </editor-fold>                        
     
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            // TODO add your handling code here:
             JFileChooser jf = new JFileChooser ();
            jf.showOpenDialog(null);
            url.setText(jf.getSelectedFile().getPath());
            PlanarImage p=JAI.create("fileload",url.getText());
            img.setIcon(new ImageIcon(p.getAsBufferedImage()));
     
        }                                        
      public static BufferedImage contour(BufferedImage img) {
     
    		BufferedImage dst = new BufferedImage(img.getWidth(), img.getHeight(),
    				BufferedImage.TYPE_INT_ARGB);
    		// Definition du masque de convolution utilisé pour la détéction des contours de
    		// l'image
    		float[] mask = { -0.1F, -0.1F, -0.1F, -0.1F, 0.8F, -0.1F, -0.1F, -0.1F, -0.1F};
    		Kernel kernel = new Kernel(3, 3, mask);
    		// On creer notre outils de convolution
    		ConvolveOp convo = new ConvolveOp(kernel);
    		// On effectue la convolution
    		convo.filter(img, dst);
    		// On retourne l'image convoluée
    		return dst;
    	}
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            // TODO add your handling code here:
            PlanarImage u=JAI.create("fileload",url.getText());
            BufferedImage u = FENETRE.contour(img);
     
     
            dst.setIcon(new ImageIcon(u.getAsBufferedImage()));;
        }                                        
     
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new FENETRE().setVisible(true);
                }
            });
        }
     
        // Variables declaration - do not modify                     
        private javax.swing.JLabel img;
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JLabel jLabel1;
        private java.awt.TextField url;
        // End of variables declaration                   
     
    }

  2. #2
    Membre actif Avatar de Vikisme
    Homme Profil pro
    Développeur Java
    Inscrit en
    Avril 2007
    Messages
    172
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Avril 2007
    Messages : 172
    Points : 228
    Points
    228
    Par défaut
    Bonjour,

    Si j'ai compris ton problème c'est que tu voudrais utiliser méthode de la classe PlannerImage alors que tu n'as qu'une BufferedImage ?

    Est-ce que ceci pourrait marcher ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    PlanarImage plannerImage = PlanarImage.wrapRenderedImage(bufferedImage);
    Tout passe, tout casse
    Le joint le cul lassent...


    http://www.myspace.fr/geampa_raler

  3. #3
    Futur Membre du Club
    Femme Profil pro
    Inscrit en
    Décembre 2011
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4
    Points : 5
    Points
    5
    Par défaut
    merci
    mais mon problème c'est l’inverse je la méthode que j'ai nécessite un baffered image mais je n'ai que plannar image est ce qu'il y a possibilité de convertir l'image ?

  4. #4
    Membre actif Avatar de Vikisme
    Homme Profil pro
    Développeur Java
    Inscrit en
    Avril 2007
    Messages
    172
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Avril 2007
    Messages : 172
    Points : 228
    Points
    228
    Par défaut
    Comme ceci ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    BufferedImage bufferedImage = planarImage.getAsBufferedImage();
    Tout passe, tout casse
    Le joint le cul lassent...


    http://www.myspace.fr/geampa_raler

  5. #5
    Futur Membre du Club
    Femme Profil pro
    Inscrit en
    Décembre 2011
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4
    Points : 5
    Points
    5
    Par défaut solution
    merci a vous l'exécusion a été effectu avec succée

Discussions similaires

  1. Détection du contour d'une image
    Par ILMaGo dans le forum 2D
    Réponses: 0
    Dernier message: 07/12/2013, 00h41
  2. Détection de contours sur image de cellules
    Par salihovic dans le forum Traitement d'images
    Réponses: 14
    Dernier message: 05/11/2009, 11h32
  3. Réponses: 0
    Dernier message: 22/04/2008, 12h49
  4. détection de contours images médicales
    Par twix24 dans le forum Traitement d'images
    Réponses: 12
    Dernier message: 18/12/2007, 12h16
  5. [débutant]traitement image, détection de contour
    Par seerauber dans le forum Traitement d'images
    Réponses: 4
    Dernier message: 13/07/2007, 15h25

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo