Пример #1
0
        public CPixels[,] Rotation90SensAntiTrigoPxl()
        {
            // On ne s'occupe pas de savoir si l'image est rectangle ou carré,
            // Si l'algo traite les rectangles il traitera les carrés.
            CPixels[,] matriceRGB_Returned = new CPixels[m_matriceRGB.GetLength(1), m_matriceRGB.GetLength(0)];
            int indexI;
            int indexJ = 0;

            //AffichageMatriceRGB();
            for (int i = 0; i < m_matriceRGB.GetLength(0); i++)
            {
                indexI = 0;
                for (int j = m_matriceRGB.GetLength(1) - 1; j >= 0; j--)
                {
                    //Console.WriteLine("Valeur matriceRGB en (" + i + "," + j + ") : " + m_matriceRGB[i,j].DisplayPixelStr());
                    matriceRGB_Returned[indexI, indexJ] = m_matriceRGB[i, j];
                    //Console.WriteLine("Valeur nouvelle Matrice en (" + indexI + "," + indexJ + ") : " + resultRotateMatrixRGB[indexI, indexJ].DisplayPixelStr());
                    indexI++;
                }
                indexJ++;
            }
            // A partir de la, on a notre nouvelle matrice résultant de m_matriceRGB,

            return(matriceRGB_Returned);
        }
Пример #2
0
 public byte[] RemplissageHEADERNouvelleImageBmp()
 {
     CPixels[,] matricePxl = new CPixels[m_hauteurFichierInt, m_largeurFichierInt];
     // Le HEADER des bmp fait 54 octets (entre l'index 0 et l'index 53), il faut donc le construire "à la main" à l'aide des variables crées ci-dessus et de ce lien : http://www.commentcamarche.net/contents/1200-bmp-format-bmp
     // Initialisation du tableau d'octet
     byte[] tableauImageAAfficherByte = new byte[(matricePxl.GetLength(0) * matricePxl.GetLength(1) * 3) + m_tailleOffSetInt];
     // Remplissage du tableau d'octet pour les 54 premiers octets composants le HEADER
     tableauImageAAfficherByte[0] = 66; //par définition d'un fichier bmp
     tableauImageAAfficherByte[1] = 77; //par définition d'un fichier bmp
     for (int i = 2; i < 6; i++)
     {
         tableauImageAAfficherByte[i] = m_tailleFicherByte[i - 2];
     }
     for (int i = 6; i < 10; i++)
     {
         tableauImageAAfficherByte[i] = 0; // par définition champs réservé voir site internet
     }
     for (int i = 10; i < 14; i++)
     {
         tableauImageAAfficherByte[i] = m_tailleOffSetByte[i - 10];
     }
     byte[] tailleEnteteByte = { 40, 0, 0, 0 }; // fixé pour les fichiers traités
     for (int i = 14; i < 18; i++)
     {
         tableauImageAAfficherByte[i] = tailleEnteteByte[i - 14];
     }
     for (int i = 18; i < 22; i++)
     {
         tableauImageAAfficherByte[i] = m_largeurImageByte[i - 18];
     }
     for (int i = 22; i < 26; i++)
     {
         tableauImageAAfficherByte[i] = m_hauteurImageByte[i - 22];
     }
     tableauImageAAfficherByte[26] = 1;                           // par définition pour les fichiers bmp
     tableauImageAAfficherByte[27] = 0;                           // par définition pour les fichiers bmp
     tableauImageAAfficherByte[28] = m_nombreOctetParCouleurByte; // pour les fichiers que l'on traite c'est toujours 24 bits
     tableauImageAAfficherByte[29] = 0;                           // car l'octet 28 et 29 définissent le nombre de couleur par octet, or cette info est codée en 2 bits
     for (int i = 30; i < 34; i++)
     {
         tableauImageAAfficherByte[i] = 0; // octets pour la compression, ici elle est nulle
     }
     for (int i = 34; i < 38; i++)
     {
         tableauImageAAfficherByte[i] = m_tailleImageByte[i - 34];
     }
     for (int i = 38; i < m_tailleOffSetInt; i++)
     {
         tableauImageAAfficherByte[i] = 0; // défini à 0 cf le lien internet
     }
     //for(int i =0; i < tableauImageAAfficherByte.Length; i++)
     //{
     //    Console.WriteLine("¨Pour i = " + i + " l'octet est égale à :" + tableauImageAAfficherByte[i]);
     //}
     return(tableauImageAAfficherByte);
 }
Пример #3
0
 public void ChangementValeurMatriceRGB()
 {
     for (int i = 0; i < m_hauteurFichierInt; i++)
     {
         for (int j = 0; j < m_largeurFichierInt; j++)
         {
             m_matriceRGB[i, j] = new CPixels(11, 22, 33);
         }
     }
 }
Пример #4
0
        public void RemplissageMatriceRGB() // on donne une valeur à chacun de nos pixels
        {
            // On intègre les octets de m_fileByte dans une matriceRGB de dimension m_hauteurInt et m_largeurInt
            int indexFichierInt = 54;

            for (int i = 0; i < m_hauteurFichierInt; i++)
            {
                for (int j = 0; j < m_largeurFichierInt; j++)
                {
                    m_matriceRGB[i, j] = new CPixels(m_fileByte[indexFichierInt], m_fileByte[indexFichierInt + 1], m_fileByte[indexFichierInt + 2]);
                    indexFichierInt   += 3;
                }
            }
        }
Пример #5
0
        public static CPixels[,] tourner180Pxl(CPixels[,] matrice)
        {
            CPixels memoire = new CPixels();

            for (int i = 0; i < (matrice.GetLength(0) / 2); i++)
            {
                for (int j = 0; j < matrice.GetLength(1); j++)
                {
                    memoire       = matrice[i, j];
                    matrice[i, j] = matrice[(matrice.GetLength(0) - 1 - i), j];
                    matrice[(matrice.GetLength(0) - 1 - i), j] = memoire;
                }
            }
            return(matrice);
        }
Пример #6
0
        public void InitialisationMatriceRGB() // on donne une valeur à chacun de nos pixels
        {
            // On intègre les octets de m_fileByte dans une matriceRGB de dimension m_hauteurInt et m_largeurInt
            int indexFichierInt = m_tailleOffSetInt;

            // On lit le file à l'nevers car c'est une convention du BMP, on remet juste l'image a l'endroit
            // En d'autres termes, la première ligne dans le fichier correspond à la dernière dans l'image
            for (int i = 0; i < m_hauteurFichierInt; i++)
            {
                for (int j = 0; j < m_largeurFichierInt; j++)
                {
                    m_matriceRGB[i, j] = new CPixels(m_fileByte[indexFichierInt + 2], m_fileByte[indexFichierInt + 1], m_fileByte[indexFichierInt]);
                    indexFichierInt   += 3;
                }
            }
        }
Пример #7
0
 public static CPixels[,] MatriceImage2couleurs()
 {
     CPixels[,] matriceImage = new CPixels[6, 8];
     for (int i = 0; i < 3; i++)
     {
         for (int j = 0; j < 8; j++)
         {
             matriceImage[i, j] = new CPixels(255, 0, 0);
         }
     }
     for (int i = 3; i < 6; i++)
     {
         for (int j = 0; j < 8; j++)
         {
             matriceImage[i, j] = new CPixels(0, 0, 0);
         }
     }
     return(matriceImage);
 }
Пример #8
0
        public CPixels[,] FiltreEstampage_Pxl()
        {
            CPixels[,] matriceRGB_Returned = new CPixels[m_matriceRGB.GetLength(0), m_matriceRGB.GetLength(1)];
            // On s'appuie sur le site : http://tavmjong.free.fr/INKSCAPE/MANUAL/html_fr/Filters-Pixel.html

            // La matrice permettant de faire l'estampage est [{-2,0,0};{0,1,0};{0,0,2}]

            // Pour ce filtre, il suffit à partir du pixel initial situé en [i,j] de prendre,
            // Le pixel en [i-1,j-1] et en [i+1,j+1]
            // Donc en [0,0] et en [Get(0),Get(1)] ce calcul sera impossible et égal à 0
            try
            {
                int resultatPixelRougeInt     = Int32.MinValue;
                int pixelRougeEnHautGaucheInt = Int32.MinValue; // car va contenir une valeur négative
                int resultatPixelVertInt      = Int32.MinValue;
                int pixelVertEnHautGaucheInt  = Int32.MinValue; // car va contenir une valeur négative
                int resultatPixelBleuInt      = Int32.MinValue;
                int pixelBleuEnHautGaucheInt  = Int32.MinValue; // car va contenir une valeur négative
                for (int i = 0; i < matriceRGB_Returned.GetLength(0); i++)
                {
                    for (int j = 0; j < matriceRGB_Returned.GetLength(1); j++)
                    {
                        //Pour les frontières on les initialise à 0

                        if (i == 0)
                        {
                            matriceRGB_Returned[i, j] = new CPixels();
                            //Console.WriteLine("Je passe i=0 en [" + i + "," + j + "]");
                        }
                        else if (j == 0)
                        {
                            matriceRGB_Returned[i, j] = new CPixels();
                            //Console.WriteLine("Je passe j = 0 en [" + i + "," + j + "]");
                        }
                        else if (i == matriceRGB_Returned.GetLength(0) - 1)
                        {
                            matriceRGB_Returned[i, j] = new CPixels();
                            //Console.WriteLine("Je passe i = Get(0) en [" + i + "," + j + "]");
                        }
                        else if (j == matriceRGB_Returned.GetLength(1) - 1)
                        {
                            matriceRGB_Returned[i, j] = new CPixels();
                            //Console.WriteLine("Je passe j = Get(1) en [" + i + "," + j + "]");
                        }
                        else
                        {
                            //Pour le pixel Bleu
                            pixelBleuEnHautGaucheInt = m_matriceRGB[i - 1, j - 1].PixelBleuByte * (-2);
                            resultatPixelBleuInt     = (pixelBleuEnHautGaucheInt + m_matriceRGB[i, j].PixelBleuByte + m_matriceRGB[i + 1, j + 1].PixelBleuByte * 2) / 3; //stockage dans le pixel initial

                            //Pour le pixel Vert
                            pixelVertEnHautGaucheInt = m_matriceRGB[i - 1, j - 1].PixelVertByte * (-2);
                            resultatPixelVertInt     = (pixelVertEnHautGaucheInt + m_matriceRGB[i, j].PixelVertByte + m_matriceRGB[i + 1, j + 1].PixelVertByte * 2) / 3; //stockage dans le pixel initial

                            //Pour le pixel Rouge
                            pixelRougeEnHautGaucheInt = m_matriceRGB[i - 1, j - 1].PixelRougeByte * (-2);
                            resultatPixelRougeInt     = (pixelRougeEnHautGaucheInt + m_matriceRGB[i, j].PixelRougeByte + m_matriceRGB[i + 1, j + 1].PixelRougeByte * 2) / 3; //stockage dans le pixel initial

                            // Construction de la nouvelle matrice en lui applicant le nouveau pixel
                            //Console.WriteLine("Pixel bleu : " + resultatPixelBleuInt);
                            //Console.WriteLine("Pixel vert : " + resultatPixelVertInt);
                            //Console.WriteLine("Pixel rouge : " + resultatPixelRougeInt);
                            if (resultatPixelBleuInt < 0)
                            {
                                resultatPixelBleuInt = -1 * resultatPixelBleuInt;
                            }
                            if (resultatPixelVertInt < 0)
                            {
                                resultatPixelVertInt = -1 * resultatPixelVertInt;
                            }
                            if (resultatPixelRougeInt < 0)
                            {
                                resultatPixelRougeInt = -1 * resultatPixelRougeInt;
                            }
                            //Console.WriteLine("Pixel bleu : " + resultatPixelBleuInt);
                            //Console.WriteLine("Pixel vert : " + resultatPixelVertInt);
                            //Console.WriteLine("Pixel rouge : " + resultatPixelRougeInt);
                            matriceRGB_Returned[i, j] = new CPixels(Convertir_Int_To_Byte(resultatPixelBleuInt), Convertir_Int_To_Byte(resultatPixelVertInt), Convertir_Int_To_Byte(resultatPixelRougeInt));
                        }
                        //Console.ReadKey();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("ERREUR dans méthode FiltreEstampage_Pxl()");
                Console.WriteLine(e.Message);
            }
            return(matriceRGB_Returned);
        }
Пример #9
0
 /// <summary>
 /// Cette fonction permet de renforcer les bords d'une image
 /// </summary>
 /// <returns></returns>
 public CPixels[,] RenforcementDesBords_Pxl()
 {
     CPixels[,] matriceRGB_Returned = new CPixels[m_matriceRGB.GetLength(0), m_matriceRGB.GetLength(1)];
     try
     {
         // On s'appuie sur le site : https://docs.gimp.org/fr/plug-in-convmatrix.html
         // La matrice permettant de faire le renforcement des bords est [{0,0,0};{-1,1,0};{0,0,0}]
         // Donc il suffit simplement de multiplier le pixel a gauche du pixel initial par -1 et par 1 le pixel initial,
         // Il y aura donc un problème de frontière que sur la premiere colonne !!!!
         // Dans un premier temps, on s'occupe de toute la matrice sauf la première colonne
         int resultatPixelRougeInt = Int32.MinValue;
         int pixelRougeAGaucheInt  = Int32.MinValue;
         int resultatPixelVertInt  = Int32.MinValue;
         int pixelVertAGaucheInt   = Int32.MinValue;
         int resultatPixelBleuInt  = Int32.MinValue;
         int pixelBleuAGaucheInt   = Int32.MinValue;
         for (int i = 0; i < m_matriceRGB.GetLength(0); i++)
         {
             for (int j = 1; j < m_matriceRGB.GetLength(1); j++)
             {
                 //Pour le pixel Bleu
                 pixelBleuAGaucheInt  = m_matriceRGB[i, j - 1].PixelBleuByte * (-1);               // on multiplie par -1 d'après la matrice de convolution
                 resultatPixelBleuInt = pixelBleuAGaucheInt + m_matriceRGB[i, j].PixelBleuByte;    // ici on a donc appliqué la matrice de convolution pour le renforcement des bords
                 //Pour le pixel Vert
                 pixelVertAGaucheInt  = m_matriceRGB[i, j - 1].PixelVertByte * (-1);               // on multiplie par -1 d'après la matrice de convolution
                 resultatPixelVertInt = pixelVertAGaucheInt + m_matriceRGB[i, j].PixelVertByte;    // ici on a donc appliqué la matrice de convolution pour le renforcement des bords
                 //Pour le pixel Rouge
                 pixelRougeAGaucheInt  = m_matriceRGB[i, j - 1].PixelRougeByte * (-1);             // on multiplie par -1 d'après la matrice de convolution
                 resultatPixelRougeInt = pixelRougeAGaucheInt + m_matriceRGB[i, j].PixelRougeByte; // ici on a donc appliqué la matrice de convolution pour le renforcement des bords
                 // Construction de la nouvelle matrice en lui applicant le nouveau pixel
                 //Console.WriteLine("Pixel bleu : " + resultatPixelBleuInt);
                 //Console.WriteLine("Pixel vert : " + resultatPixelVertInt);
                 //Console.WriteLine("Pixel rouge : " + resultatPixelRougeInt);
                 if (resultatPixelBleuInt <= 0)
                 {
                     resultatPixelBleuInt = -1 * resultatPixelBleuInt;
                 }
                 if (resultatPixelVertInt <= 0)
                 {
                     resultatPixelVertInt = -1 * resultatPixelVertInt;
                 }
                 if (resultatPixelRougeInt <= 0)
                 {
                     resultatPixelRougeInt = -1 * resultatPixelRougeInt;
                 }
                 //Console.WriteLine("Pixel bleu : " + resultatPixelBleuInt);
                 //Console.WriteLine("Pixel vert : " + resultatPixelVertInt);
                 //Console.WriteLine("Pixel rouge : " + resultatPixelRougeInt);
                 matriceRGB_Returned[i, j] = new CPixels(Convertir_Int_To_Byte(resultatPixelBleuInt), Convertir_Int_To_Byte(resultatPixelVertInt), Convertir_Int_To_Byte(resultatPixelRougeInt));
                 //Console.ReadKey();
             }
         }
         for (int i = 0; i < m_matriceRGB.GetLength(0); i++)
         {
             for (int j = 0; j < 1; j++)
             {
                 matriceRGB_Returned[i, j] = new CPixels(); // on initialise à 0
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("ERREUR DANS RenforcementDesBordsPxl() ");
         Console.WriteLine(e.Message);
     }
     return(matriceRGB_Returned);
 }
Пример #10
0
        public static CPixels[,] RemplissageMatriceInitial_M()
        {
            CPixels[,] m_matriceInitialPrenom = new CPixels[240, 240]; // TAILLE Image a choisir, attention largeur doit etre un multiple de 4
            //On parcourt la matrice colonne par colonne
            //On forme un premier rectangle
            for (int j = 0; j < (m_matriceInitialPrenom.GetLength(1) / 5); j++)
            {
                for (int i = 0; i < m_matriceInitialPrenom.GetLength(0); i++)
                {
                    m_matriceInitialPrenom[i, j] = new CPixels(0, 255, 0);
                }
            }
            // On forme la première diagonale descendante de la lettre M
            int decalageInt = 0;

            for (int j = (m_matriceInitialPrenom.GetLength(1) / 5); j < (m_matriceInitialPrenom.GetLength(1) / 2); j++)
            {
                for (int i = 0; i <= decalageInt; i++)
                {
                    m_matriceInitialPrenom[i, j] = new CPixels(0, 0, 0);
                }
                decalageInt++;
                for (int i = decalageInt; i < (decalageInt + (m_matriceInitialPrenom.GetLength(1) / 4)); i++)
                {
                    m_matriceInitialPrenom[i, j] = new CPixels(0, 255, 0);
                }
                for (int i = (decalageInt + (m_matriceInitialPrenom.GetLength(1) / 4)); i < m_matriceInitialPrenom.GetLength(0); i++)
                {
                    m_matriceInitialPrenom[i, j] = new CPixels(0, 0, 0);
                }
                // ICI on parcouru toute une colonne de la matrice
            }
            //ICI on va s'attaquer maintenant à la diagonale montante de la lettre M
            #region 1er jet
            for (int j = (m_matriceInitialPrenom.GetLength(1) / 2); j < (m_matriceInitialPrenom.GetLength(1) - (m_matriceInitialPrenom.GetLength(1) / 5)); j++)
            {
                if (decalageInt != 0)
                {
                    decalageInt--;
                }
                for (int i = 0; i < decalageInt; i++)
                {
                    m_matriceInitialPrenom[i, j] = new CPixels(0, 0, 0);
                }
                for (int i = decalageInt; i < (decalageInt + (m_matriceInitialPrenom.GetLength(1) / 4)); i++)
                {
                    m_matriceInitialPrenom[i, j] = new CPixels(0, 255, 0);
                }
                for (int i = (decalageInt + (m_matriceInitialPrenom.GetLength(1) / 4)); i < m_matriceInitialPrenom.GetLength(0); i++)
                {
                    m_matriceInitialPrenom[i, j] = new CPixels(0, 0, 0);
                }
                #endregion
                //ICI on a parcouru toute une colonne de la matrice
            }
            //ICI on a fini la diagonale montante, on s'attaque au dernier rectangle de la lettre M
            for (int j = (m_matriceInitialPrenom.GetLength(1) - (m_matriceInitialPrenom.GetLength(1) / 5)); j < m_matriceInitialPrenom.GetLength(1); j++)
            {
                for (int i = 0; i < m_matriceInitialPrenom.GetLength(0); i++)
                {
                    m_matriceInitialPrenom[i, j] = new CPixels(0, 255, 0);
                }
            } // On a terminé de parcourir toute notre matrice (image)

            CPixels memoire = new CPixels();
            for (int i = 0; i < m_matriceInitialPrenom.GetLength(0); i++)
            {
                for (int j = 0; j < m_matriceInitialPrenom.GetLength(1); j++)
                {
                    memoire = m_matriceInitialPrenom[i, j];
                    m_matriceInitialPrenom[i, j] = m_matriceInitialPrenom[(m_matriceInitialPrenom.GetLength(0) - 1 - i), j];
                    m_matriceInitialPrenom[(m_matriceInitialPrenom.GetLength(0) - 1 - i), j] = memoire;
                }
            }
            //AfficherMatricePxl(m_matriceInitialPrenom);
            m_matriceInitialPrenom = tourner180Pxl(m_matriceInitialPrenom); // lecture en little endian, besoin de renverser la matrice pour que la lecture se fasse dans le bon sens
            //Console.WriteLine();
            //AfficherMatricePxl(m_matriceInitialPrenom);
            return(m_matriceInitialPrenom);
        }