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

C# Discussion :

L'algo de Sobel en C#


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    102
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 102
    Par défaut L'algo de Sobel en C#
    bonjour,
    jai fait l'algo de Sobel ,voici le 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
    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
     
                Bitmap myBitmap = new Bitmap(pictureBox1.Image);
                int width = myBitmap.Width;
                int height = myBitmap.Height;
                unsafe
                {
                    BitmapData bmpData = myBitmap.LockBits(new Rectangle(0, 0, width,
                    height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
     
                    byte* newPixel = (byte*)(void*)bmpData.Scan0;                
                    //syntaxe equivalente
                    //byte* pixel = (byte*)bmpData.Scan0.ToPointer();
     
                    //creation de la matrice de NDG.
     
                    byte[,] image = new byte[width, height];                
                    for (int y = 0; y < height; y++)
                        for (int x = 0; x < width; x++)
                        {
                            image[x, y] = newPixel[0];                                          
                            newPixel += 4;                       
                        }
                    myBitmap.UnlockBits(bmpData);
     
                    // une cpoier de la matrice de ND.
     
                    byte[,]image1 =new byte[width,height];
                    for (int y = 0; y < height; y++)
                        for (int x = 0; x < width; x++)
                        {
                            image1[x, y] = image[x,y];                        
                        }
     
                    int npix;
     
                    // calcule de filtre de soble Gx
                    /* _______
                     * -1|0|1
                     * -------
                     * -2|0|2
                     * -------
                     * -1|0|1                                   
                     * _______
                     */
     
                    for (int j = 1; j < height-1; j++)
                        for (int i = 1; i < width-1; i++)
                        {
     
                            npix = image[i - 1, j - 1] * (-1) + image[i + 1, j - 1] + image[i - 1, j] * (-2) +
                                image[i + 1, j] * (2) + image[i - 1, j + 1] * (-1) + image[i + 1, j + 1];
                           if (npix > 255) npix = 255;
                           if (npix < 0) npix = 0;
                            image[i, j] = (byte)npix;
     
                        }
     
                    // calcule de filtre de soble Gy
                    /* ________
                     *  1|2|1
                     * --------
                     *  0|0|0
                     * --------
                     * -1|-2|-1                                   
                     * ________
                     */
     
                    for (int j = 1; j < height - 1; j++)
                        for (int i = 1; i < width - 1; i++)
                        {
                             npix =image1[i - 1, j - 1]+ image1[i, j - 1]*(2)+image1[i + 1, j - 1] + image1[i - 1, j+1]*(-1)
                                +image1[i,j+1] * (-2) + image1[i +1, j + 1] * (-1);
                            if (npix > 255) npix = 255;
                            if (npix < 0) npix = 0;                        
                            image1[i, j] = (byte)npix;
                        }
                    // Construction de l'image filtrer
     
                    BitmapData bmp= myBitmap.LockBits(new Rectangle(0, 0, width,
                    height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
                    byte* Pixel = (byte*)(void*)bmp.Scan0;
                    int x1;
                    byte x2;
                    for (int y = 0; y < height; y++)
                        for (int x = 0; x < width; x++)
                        {
                            x1 = (int)Math.Sqrt((image1[x, y] *image1[x, y]) + (image[x, y]*image[x, y]));
                            if (x1 > 255) x1 = 255;
                            if (x1 < 0 ) x1 = 0;
                            x2 = (byte)x1;
                            Pixel[0] = x2;
                            Pixel[1] = x2;
                            Pixel[2] = x2; 
                            Pixel += 4;
                        }              
                             myBitmap.UnlockBits(bmp);
                }
                pictureBox2.Image = myBitmap;
    mais le résultat est mauvais ,voici les images que jai eu(voir piece joint)
    svp vous pouvez m'aidee
    Merci
    Images attachées Images attachées   

  2. #2
    Expert confirmé

    Homme Profil pro
    Chef de projet NTIC
    Inscrit en
    Septembre 2006
    Messages
    3 580
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Septembre 2006
    Messages : 3 580
    Par défaut
    salut

    sur www.codeproject.com tu trouveras un exemple ou il le fait en C# ainsi que d'autres algo de traitement d'image !!!

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    102
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 102
    Par défaut
    Le problème c'ete de ne pas touche la matrice maire il faut pas la modier et pour faire le traitement if faut consedere la matrice maire pa touche

  4. #4
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Par défaut
    Citation Envoyé par sali lala Voir le message
    Le problème c'ete de ne pas touche la matrice maire il faut pas la modier et pour faire le traitement if faut consedere la matrice maire pa touche
    euh ... j'ai rien compris à ta phrase
    mais bon, apparemment le problème est résolu de toutes façons...

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. cherche algos Delphi pour : Huffman, R.S.A, D.E.S.
    Par X-Delphi dans le forum Débuter
    Réponses: 3
    Dernier message: 24/08/2002, 18h51
  2. Cherche l'algo crc 16 bits
    Par icepower dans le forum Algorithmes et structures de données
    Réponses: 2
    Dernier message: 21/08/2002, 13h27
  3. Algo de calcul de FFT
    Par djlex03 dans le forum Traitement du signal
    Réponses: 15
    Dernier message: 02/08/2002, 17h45
  4. Algo de Hough et ou de Radon
    Par victorracine dans le forum Algorithmes et structures de données
    Réponses: 9
    Dernier message: 29/07/2002, 11h09
  5. Recherche algo tree
    Par Anonymous dans le forum Algorithmes et structures de données
    Réponses: 10
    Dernier message: 24/05/2002, 13h44

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