Exemplo n.º 1
0
        /// <summary>
        /// de 2 à 10
        /// </summary>
        /// <param name="multiplicateur"></param>
        public Pixel[,] Agrandir(int multiplicateur)
        {
            hauteurI = hauteurI * multiplicateur;
            largeurI = largeurI * multiplicateur;



            Pixel[,] matRGBR = new Pixel[(matRGB.GetLength(0) * multiplicateur), (matRGB.GetLength(1) * multiplicateur)];

            Pixel[,] matdouble = new Pixel[(matRGB.GetLength(0) * multiplicateur), (matRGB.GetLength(1) * multiplicateur)];

            for (int i = 0; i < matRGBR.GetLength(0); i++)
            {
                for (int j = 0; j < matRGBR.GetLength(1); j++)
                {
                    matRGBR[i, j] = new Pixel(255, 255, 255);
                }
            }



            for (int i = 0; i < matRGB.GetLength(0); i++)

            {
                for (int j = 0; j < matRGB.GetLength(1); j++)

                {
                    Pixel a = matRGB[i, j];
                    for (int x = i * multiplicateur; x < multiplicateur + i * multiplicateur; x++)
                    {
                        matRGBR[x, j] = a;
                    }
                }
            }

            for (int i = 0; i < matRGBR.GetLength(0); i++)
            {
                for (int j = 0; j < matRGBR.GetLength(1); j++)
                {
                    matdouble[i, j] = matRGBR[i, j];
                }
            }


            for (int j = 0; j < matRGB.GetLength(1); j++)

            {
                for (int i = 0; i < matdouble.GetLength(0); i++)

                {
                    Pixel a = matdouble[i, j];
                    for (int x = j * multiplicateur; x < multiplicateur + j * multiplicateur; x++)
                    {
                        matRGBR[i, x] = a;
                    }
                }
            }

            return(matRGBR);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Permet d'effectuer la rotation d'une image d'un angle definit par l'utilisateur
        /// </summary>
        /// <param name="angle"> entier de 0 à 360</param>
        /// <returns>retourne la matrice de pixel rotationer </returns>
        public Pixel[,] Rotation(int angle) // il faut centrer l'image (i-hauteur de l'image divisée par deux ) pareil pour la largeur
        {
            hauteurI = hauteurI * 4;
            largeurI = largeurI * 4;
            int    centrex  = hauteurI / 2;
            int    centrey  = largeurI / 2;
            int    a        = 0;
            int    b        = 0;
            double anglerad = Convert.ToDouble(angle * (3.14 / 180));
            int    x        = 0;
            int    y        = 0;

            Pixel[,] matRGBR = new Pixel[hauteurI, largeurI];


            for (int i = 0; i < matRGBR.GetLength(0); i++)
            {
                for (int j = 0; j < matRGBR.GetLength(1); j++)
                {
                    matRGBR[i, j] = new Pixel(255, 255, 255);
                }
            }


            for (int i = centrex - matRGB.GetLength(0) / 2; i < centrex + matRGB.GetLength(0) / 2; i++)
            {
                for (int j = centrey - matRGB.GetLength(1) / 2; j < centrey + matRGB.GetLength(1) / 2; j++)
                {
                    x = Convert.ToInt32((i - centrex) * Math.Cos(anglerad) + (j - centrey) * Math.Sin(anglerad) + centrex);
                    y = Convert.ToInt32(-(i - centrex) * Math.Sin(anglerad) + (j - centrey) * Math.Cos(anglerad) + centrey);

                    matRGBR[x, y] = matRGB[a, b];
                    if (angle != 90 && angle != 180 && angle != 280 && angle != 360) // ne pas faire pour image a rotation angle droit
                    {
                        matRGBR[x + 1, y] = matRGB[a, b];                            // eviter les trou blancs en remplissant les cases à proximiter
                    }
                    b++;
                }
                b = 0;
                a++;
            }

            return(matRGBR);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Rertrecit l'image par le nombre du multiplicateur exemple : par 2 si multiplicateur = 2
        /// </summary>
        /// <param name="multiplicateur">un entier car le multiplicateur ne peut pas être un nobmre a virgule </param>
        /// <returns> retourne la matrice de pixel retrecit </returns>
        public Pixel[,] retrecir(int multiplicateur)
        {
            int x = 0;
            int y = 0;

            Pixel[,] matRGBR = new Pixel[(matRGB.GetLength(0)), (matRGB.GetLength(1))];

            Pixel[,] matdouble = new Pixel[(matRGB.GetLength(0)), (matRGB.GetLength(1))];

            for (int i = 0; i < matRGBR.GetLength(0); i++)
            {
                for (int j = 0; j < matRGBR.GetLength(1); j++)
                {
                    matRGBR[i, j] = new Pixel(255, 255, 255);
                }
            }
            for (int i = 0; i < matRGBR.GetLength(0); i++)
            {
                for (int j = 0; j < matRGBR.GetLength(1); j++)
                {
                    matdouble[i, j] = new Pixel(255, 255, 255);
                }
            }


            for (int i = 0; i < matRGBR.GetLength(0); i = i + multiplicateur)
            {
                for (int j = 0; j < matRGBR.GetLength(1); j++)
                {
                    matRGBR[x, y] = matRGB[i, j];
                    y++;
                }
                y = 0;
                x++;
            }

            x = 0;
            y = 0;

            for (int j = 0; j < matRGBR.GetLength(1); j = j + multiplicateur)
            {
                for (int i = 0; i < matRGBR.GetLength(0); i++)
                {
                    matdouble[x, y] = matRGBR[i, j];
                    x++;
                }
                x = 0;
                y++;
            }


            return(matdouble);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Permet de coder une image dans une image puis de la décoder dans le second temps
        /// </summary>
        /// <param name="a"> l'image selectionner par l'utilisateur</param>
        public void ImageCoderetDecoder(MyImage a)
        {
            Pixel[,] matcache = ImageCache(a);

            Pixel[,] mat = new Pixel[a.matRGB.GetLength(0), a.matRGB.GetLength(1)];
            int[] binaireR = new int[8];
            int[] binaireG = new int[8];
            int[] binaireB = new int[8];


            int[] ConcatenationR = new int[8];
            int[] ConcatenationG = new int[8];
            int[] ConcatenationB = new int[8];

            for (int i = 0; i < mat.GetLength(0); i++)
            {
                for (int j = 0; j < mat.GetLength(1); j++)
                {
                    mat[i, j] = new Pixel(255, 255, 255);
                }
            }

            for (int i = 0; i < a.matRGB.GetLength(0); i++)
            {
                for (int j = 0; j < a.matRGB.GetLength(1); j++)
                {
                    binaireR = ConvertisseurDecenBinaire(matcache[i, j].red);
                    binaireG = ConvertisseurDecenBinaire(matcache[i, j].green);
                    binaireB = ConvertisseurDecenBinaire(matcache[i, j].blue);


                    for (int x = 0; x < 8; x++) // on vient chercher le sbits cachés de 4 à 8 qu'on met en 0 à 4
                    {
                        if (x < 4)
                        {
                            ConcatenationR[x] = binaireR[x + 4];
                            ConcatenationG[x] = binaireG[x + 4];
                            ConcatenationB[x] = binaireB[x + 4];
                        }
                        else if (4 <= x)
                        {
                            ConcatenationR[x] = 0; // on remplit le reste à 0 puisqu'on à plus le reste de 4 à 8
                            ConcatenationG[x] = 0;
                            ConcatenationB[x] = 0;
                        }
                    }
                    mat[i, j].red   = ConvertisseurBinaireenDec(ConcatenationR);
                    mat[i, j].green = ConvertisseurBinaireenDec(ConcatenationG);
                    mat[i, j].blue  = ConvertisseurBinaireenDec(ConcatenationB);
                }
            }

            for (int i = 0; i < matRGB.GetLength(0); i++) // on met l'image en blanc
            {
                for (int j = 0; j < matRGB.GetLength(1); j++)
                {
                    matRGB[i, j] = new Pixel(255, 255, 255);
                }
            }
            for (int i = 0; i < mat.GetLength(0); i++) // on remplit avec ce qu'on à récuperé juste avant
            {
                for (int j = 0; j < mat.GetLength(1); j++)
                {
                    matRGB[i, j] = mat[i, j];
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Permet d'appliquer un filtre en choisissant le noyau correspondant au filtre et l'applique à la matrice de pixel par le procédé de la matrice de convolution
        /// </summary>
        /// <param name="NoyauM"> Matrice d'entier correspondant au noyaux qui applique le filtre à l'image </param>
        public void MatriceConvolution(int[,] NoyauM)
        {
            int AccumRed   = 0;
            int AccumGreen = 0;
            int AccumBlue  = 0;
            int somme      = 0;
            int diviseur   = 0;

            Pixel[,] MatriceRGBcopie   = new Pixel[matRGB.GetLength(0), matRGB.GetLength(1)];
            Pixel[,] MatriceRGBetendue = new Pixel[matRGB.GetLength(0) + 1, matRGB.GetLength(1) + 1];

            // instanciation mat copie
            for (int i = 0; i < MatriceRGBcopie.GetLength(0); i++)
            {
                for (int j = 0; j < MatriceRGBcopie.GetLength(1); j++)
                {
                    MatriceRGBcopie[i, j] = new Pixel(255, 255, 255);
                }
            }
            // instanciation mat etendue
            for (int i = 0; i < MatriceRGBetendue.GetLength(0); i++)
            {
                for (int j = 0; j < MatriceRGBetendue.GetLength(1); j++)
                {
                    MatriceRGBetendue[i, j] = new Pixel(255, 255, 255);
                }
            }

            #region matetendu
            MatriceRGBetendue[0, 0] = matRGB[0, 0];

            MatriceRGBetendue[0, MatriceRGBetendue.GetLength(1) - 1] = matRGB[0, matRGB.GetLength(1) - 1];

            MatriceRGBetendue[MatriceRGBetendue.GetLength(0) - 1, 0] = matRGB[matRGB.GetLength(0) - 1, 0];
            MatriceRGBetendue[MatriceRGBetendue.GetLength(0) - 1, MatriceRGBetendue.GetLength(1) - 1] = matRGB[matRGB.GetLength(0) - 1, matRGB.GetLength(1) - 1]; // on remplit les quatres coins


            for (int j = 1; j < MatriceRGBetendue.GetLength(1) - 1; j++) // on remplit la ligne superieur
            {
                MatriceRGBetendue[0, j] = matRGB[0, j - 1];
            }

            for (int j = 1; j < MatriceRGBetendue.GetLength(1) - 1; j++) // on remplit la ligne inferieur
            {
                MatriceRGBetendue[MatriceRGBetendue.GetLength(0) - 1, j] = matRGB[matRGB.GetLength(0) - 1, j - 1];
            }

            for (int i = 1; i < MatriceRGBetendue.GetLength(0) - 1; i++) // on remplit la ligne superieur
            {
                MatriceRGBetendue[i, 0] = matRGB[i - 1, 0];
            }

            for (int i = 1; i < MatriceRGBetendue.GetLength(0) - 1; i++) // on remplit la ligne superieur
            {
                MatriceRGBetendue[i, MatriceRGBetendue.GetLength(1) - 1] = matRGB[i - 1, matRGB.GetLength(1) - 1];
            }

            //remplissage de toute la matrice (l'interieur )
            for (int i = 1; i < matRGB.GetLength(0); i++)
            {
                for (int j = 1; j < matRGB.GetLength(1); j++)
                {
                    MatriceRGBetendue[i, j] = matRGB[i - 1, j - 1];
                }
            }
            #endregion

            // travail sur somme et diviseur noyau
            for (int i = 0; i < NoyauM.GetLength(0); i++)
            {
                for (int j = 0; j < NoyauM.GetLength(1); j++)
                {
                    somme = somme + NoyauM[i, j];
                }
            }

            if (somme > 0)
            {
                diviseur = somme;
            }
            else
            {
                diviseur = 1;
            }



            for (int i = 1; i < matRGB.GetLength(0); i++)
            {
                for (int j = 1; j < matRGB.GetLength(1); j++)      // parcours toute la matrice
                {
                    AccumRed   = 0;
                    AccumGreen = 0;
                    AccumBlue  = 0;
                    int LigneN   = 0;
                    int ColonneN = 0;



                    #region Cas général
                    for (int a = i - 1; a < i + 2; a++)
                    {
                        for (int b = j - 1; b < j + 2; b++)     //parcours le tour du point selectionné
                        {
                            AccumRed   = AccumRed + MatriceRGBetendue[a, b].red * NoyauM[LigneN, ColonneN];
                            AccumGreen = AccumGreen + MatriceRGBetendue[a, b].green * NoyauM[LigneN, ColonneN];
                            AccumBlue  = AccumBlue + MatriceRGBetendue[a, b].blue * NoyauM[LigneN, ColonneN];
                            ColonneN++;
                        }

                        ColonneN = 0;
                        LigneN++;
                    }
                    #endregion



                    if (AccumRed / diviseur > 255)
                    {
                        MatriceRGBcopie[i, j].red         = 255;
                        MatriceRGBcopie[i - 1, j - 1].red = 255;
                    }
                    else if (AccumRed / diviseur < 0)
                    {
                        MatriceRGBcopie[i, j].red         = 0;
                        MatriceRGBcopie[i - 1, j - 1].red = 0;
                    }
                    else
                    {
                        MatriceRGBcopie[i, j].red         = AccumRed / diviseur;
                        MatriceRGBcopie[i - 1, j - 1].red = AccumRed / diviseur;
                    }

                    if (AccumGreen / diviseur > 255)
                    {
                        MatriceRGBcopie[i, j].green         = 255;
                        MatriceRGBcopie[i - 1, j - 1].green = 255;
                    }
                    else if (AccumGreen / diviseur < 0)
                    {
                        MatriceRGBcopie[i, j].green         = 0;
                        MatriceRGBcopie[i - 1, j - 1].green = 0;
                    }
                    else
                    {
                        MatriceRGBcopie[i, j].green         = AccumGreen / diviseur;
                        MatriceRGBcopie[i - 1, j - 1].green = AccumGreen / diviseur;
                    }

                    if (AccumBlue / diviseur > 255)
                    {
                        MatriceRGBcopie[i, j].blue         = 255;
                        MatriceRGBcopie[i - 1, j - 1].blue = 255;
                    }
                    else if (AccumBlue / diviseur < 0)
                    {
                        MatriceRGBcopie[i, j].blue         = 0;
                        MatriceRGBcopie[i - 1, j - 1].blue = 0;
                    }
                    else
                    {
                        MatriceRGBcopie[i, j].blue         = AccumBlue / diviseur;
                        MatriceRGBcopie[i - 1, j - 1].blue = AccumBlue / diviseur;
                    }
                }
            }

            MatriceRGBcopie[MatriceRGBcopie.GetLength(0) - 1, 0] = MatriceRGBcopie[MatriceRGBcopie.GetLength(0) - 1, 1]; // on remplit manuellement LE pixel du coing gauche car ne se remplit pas seul

            for (int i = 0; i < matRGB.GetLength(0); i++)
            {
                for (int j = 0; j < matRGB.GetLength(1); j++)
                {
                    matRGB[i, j].red   = MatriceRGBcopie[i, j].red;
                    matRGB[i, j].green = MatriceRGBcopie[i, j].green;
                    matRGB[i, j].blue  = MatriceRGBcopie[i, j].blue;
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Constructeur MyImage a partir du nom de l'image: myfile
        /// </summary>
        /// <param name="myfile"> string nom de l'image à ouvrir</param>
        public MyImage(string myfile)
        {
            this.myfile = myfile;

            byte[] FileByte = File.ReadAllBytes(myfile);
            byte[] tab      = new byte[4];

            // initialisation des differentes variables en fonctions des différents Bytes
            // les 2 premiers octets si 66 et 77 = format bitmap
            if (FileByte[0] == 66 && FileByte[1] == 77)
            {
                typeI = "bmp";
            }
            else
            {
                typeI = "Autre que bmp";
            }

            for (int i = 2; i < 6; i++)
            {
                tab[i - 2] = FileByte[i]; // taille Fichier
            }
            tailleF = Convertir_endian_to_int(tab);

            for (int i = 10; i < 14; i++)
            {
                tab[i - 10] = FileByte[i]; // taille offset
            }
            tailleO = Convertir_endian_to_int(tab);

            for (int i = 18; i < 22; i++)
            {
                tab[i - 18] = FileByte[i];  // largeur
            }
            largeurI = Convertir_endian_to_int(tab);

            for (int i = 22; i < 26; i++)
            {
                tab[i - 22] = FileByte[i]; // hauteur image
            }
            hauteurI = Convertir_endian_to_int(tab);

            for (int i = 28; i < 30; i++)
            {
                tab[i - 28] = FileByte[i]; // nb bit couleur
            }
            bitC = Convertir_endian_to_int(tab);

            int compteur = 54;

            matRGB = new Pixel[hauteurI, largeurI];
            for (int i = 0; i < matRGB.GetLength(0); i++)
            {
                for (int j = 0; j < matRGB.GetLength(1); j++)
                {
                    int taille = FileByte.Length;
                    int red    = FileByte[compteur];
                    int green  = FileByte[compteur + 1];
                    int blue   = FileByte[compteur + 2];

                    matRGB[i, j] = new Pixel(blue, green, red); // remplissage matrice de pixel BGR (blue green red car inversé);
                    compteur     = compteur + 3;
                }
            }
        }