示例#1
0
        /// <summary>
        /// Cette fonction crée une nouvelle matrice de pixel contenant une image convulutionnée selon le choix de l'utilisateur (il y a différents choix de Kernek, flou, détection de contour etc...)
        /// </summary>
        /// <returns>
        /// Elle retourne une matrice de pixel de l'image convolutionnée.
        /// </returns>
        public Pixel[,] Convolution()
        {
            int[,] Kernel = null;
            Console.WriteLine("Choississez votre type de convolution ==> \n"
                              + " 1 : Détetection de contour°\n"
                              + " 2 : Flou\n"
                              + " 3 : Repoussage\n"
                              + " 4 : Renforcement\n");

            string choix = Convert.ToString(Console.ReadLine());

            switch (choix)
            {
            case "1":
                int[,] MatricedétectionContour = { { 0,  1, 0 },
                                                   { 1, -4, 1 },
                                                   { 0,  1, 0 } };
                Kernel = MatricedétectionContour;
                break;

            case "2":
                int[,] MatriceFlou = { { 1, 1, 1 },
                                       { 1, 1, 1 },
                                       { 1, 1, 1 } };
                Kernel = MatriceFlou;
                break;

            case "3":
                int[,] MatriceRepoussage = { { -2, -1, 0 },
                                             { -1,  1, 1 },
                                             {  0,  1, 2 } };
                Kernel = MatriceRepoussage;
                break;

            case "4":
                int[,] MatriceRenforcement = { {  0, 0, 0 },
                                               { -1, 1, 0 },
                                               {  0, 0, 0 } };
                Kernel = MatriceRenforcement;
                break;
            }

            Pixel[,] ImageConvolue = new Pixel[image.GetLength(0), image.GetLength(1)];
            //Met la 1ère colonne et la dernière colonne en blanc
            for (int i = 0; i < image.GetLength(0); i++)
            {
                ImageConvolue[i, 0] = new Pixel(255, 255, 255);
                ImageConvolue[i, (image.GetLength(1) - 1)] = new Pixel(255, 255, 255);
            }
            //Idem avec les lignes
            for (int j = 0; j < image.GetLength(1); j++)
            {
                ImageConvolue[0, j] = new Pixel(255, 255, 255);
                ImageConvolue[(image.GetLength(0) - 1), j] = new Pixel(255, 255, 255);
            }

            int moyenneR = 0;
            int moyenneV = 0;
            int moyenneB = 0;

            for (int i = 1; i < image.GetLength(0) - 1; i++)
            {
                for (int j = 1; j < image.GetLength(1) - 1; j++)
                {
                    for (int k = -1; k < 2; k++)
                    {
                        for (int l = -1; l < 2; l++)
                        {
                            moyenneR += image[i + k, j + l].GetR * Kernel[k + 1, l + 1];
                            moyenneV += image[i + k, j + l].GetV * Kernel[k + 1, l + 1];
                            moyenneB += image[i + k, j + l].GetB * Kernel[k + 1, l + 1];
                        }
                    }
                    if (choix == "2")
                    {
                        moyenneR /= 9;
                        moyenneV /= 9;
                        moyenneB /= 9;
                    }
                    if (moyenneR > 255 || moyenneR < 0)
                    {
                        moyenneR = 0;
                    }
                    if (moyenneV > 255 || moyenneV < 0)
                    {
                        moyenneV = 0;
                    }
                    if (moyenneB > 255 || moyenneB < 0)
                    {
                        moyenneB = 0;
                    }
                    ImageConvolue[i, j] = new Pixel(moyenneR, moyenneV, moyenneB);
                    moyenneR            = 0;
                    moyenneV            = 0;
                    moyenneB            = 0;
                }
            }
            return(ImageConvolue);
        }
示例#2
0
        /// <summary>
        /// Cette fonction vient créer un histogramme d'une des couleurs primaires R, V ou B d'une image,
        /// l'ordonnée varie selon le nombre d'occurence d'une nuance de couleur, tandis que l'abscisse varie de 0 à 255
        /// (pour toutes les nuances possibles d'une couleur codée sur 8 bits).
        /// </summary>
        /// <returns>
        /// Elle retourne une matrice de pixel contenant l'histogramme d'une des trois couleurs RVB.
        /// </returns>
        public Pixel[,] HistogrammeRVB()
        {
            Console.WriteLine("Choisissez l'histogramme que vous voulez. Tapez : \n 1 pour le rouge. \n 2 pour le vert. \n 3 pour le bleu. ");
            string choix = Convert.ToString(Console.ReadLine());
            int    max_r = 0;
            int    max_v = 0;
            int    max_b = 0;

            int[] TabRouge    = new int[256];
            int[] TabBleu     = new int[256];
            int[] TabVert     = new int[256];
            int   valeurRouge = 0;
            int   valeurVert  = 0;
            int   valeurBleu  = 0;

            for (int i = 0; i < 256; i++)
            {
                TabRouge[i] = 0;
                TabVert[i]  = 0;
                TabBleu[i]  = 0;
            }

            for (int i = 0; i < image.GetLength(0); i++)
            {
                for (int j = 0; j < image.GetLength(1); j++)
                {
                    valeurRouge           = image[i, j].GetR;
                    valeurVert            = image[i, j].GetV;
                    valeurBleu            = image[i, j].GetB;
                    TabRouge[valeurRouge] = TabRouge[valeurRouge] + 1;
                    TabBleu[valeurBleu]   = TabBleu[valeurBleu] + 1;
                    TabVert[valeurVert]   = TabVert[valeurVert] + 1;
                }
            }

            for (int i = 0; i < 256; i++)
            {
                if (TabRouge[i] > max_r)
                {
                    max_r = TabRouge[i];
                }
                if (TabBleu[i] > max_b)
                {
                    max_b = TabBleu[i];
                }
                if (TabVert[i] > max_v)
                {
                    max_v = TabVert[i];
                }
            }
            int max = 0;

            if (choix == "1")
            {
                max = max_r;
            }
            if (choix == "2")
            {
                max = max_v;
            }
            if (choix == "3")
            {
                max = max_b;
            }

            Pixel[,] Histo = new Pixel[(max / 10 + 1), 256];
            //on initialise en blanc
            for (int i = 0; i < max / 10 + 1; i++)
            {
                for (int j = 0; j < 256; j++)
                {
                    Histo[i, j] = new Pixel(255, 255, 255);
                }
            }

            switch (choix)
            {
            case "1":    //histo rouge
                for (int i = 0; i < 256; i++)
                {
                    int Compteur = TabRouge[i] / 10;
                    for (int x = 0; x < Compteur; x++)
                    {
                        Histo[x, i] = new Pixel(255, 0, 0);
                    }
                }
                break;

            case "2":    //histo vert
                for (int i = 0; i < 256; i++)
                {
                    int Compteur = TabVert[i] / 10;
                    for (int x = 0; x < Compteur; x++)
                    {
                        Histo[x, i] = new Pixel(0, 255, 0);
                    }
                }
                break;

            case "3":    //histo bleu
                for (int i = 0; i < 256; i++)
                {
                    //on divise par 10 pour pas avoir un histogramme trop grand
                    int Compteur = TabBleu[i] / 10;
                    for (int x = 0; x < Compteur; x++)
                    {
                        Histo[x, i] = new Pixel(0, 0, 255);
                    }
                }
                break;
            }
            return(Histo);
        }
示例#3
0
        /// <summary>
        /// Cette fonction crée une nouvelle matrice de pixel contenant soit une fractale de Mandelbrot soit de Julia.
        /// </summary>
        /// <returns>
        /// Elle retourne une matrice de pixel de la fractale.
        /// </returns>
        public Pixel[,] Fractale()
        {
            Console.WriteLine("Quelle fractale voulez vous affichez? Tapez 1 pour la fractale de Mandelbrot, 2 pour celle de Julia ");
            string choix = Convert.ToString(Console.ReadLine());
            double x_min = 0;
            double x_max = 0;
            double y_min = 0;
            double y_max = 0;
            double c_x   = 0;
            double c_y   = 0;
            double x_n   = 0;
            double y_n   = 0;

            Console.WriteLine("Saisissez la hauteur de votre fractale (entre 0 et 1000) ==>");
            int hauteur = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Saisissez la largeur de votre fractale (entre 0 et 1000) ==>");
            int largeur = Convert.ToInt32(Console.ReadLine());

            Pixel[,] Image_fractale = new Pixel[largeur, hauteur];
            int iteration_max = 50;

            if (choix == "1")
            {
                x_min = -2;
                x_max = 0.5;
                y_min = -1.25;
                y_max = 1.25;
            }
            if (choix == "2")
            {
                x_min = -1.25;
                x_max = 1.25;
                y_min = -1.25;
                y_max = 1.25;
            }

            for (int y = 0; y < Image_fractale.GetLength(1); y++)
            {
                for (int x = 0; x < Image_fractale.GetLength(0); x++)
                {
                    if (choix == "1")
                    {
                        c_x = (x * (x_max - x_min) / Image_fractale.GetLength(0) + x_min);
                        c_y = (y * (y_min - y_max) / Image_fractale.GetLength(1) + y_max);
                        x_n = 0;
                        y_n = 0;
                    }
                    if (choix == "2")
                    {
                        c_x = 0.285;
                        c_y = 0.01;
                        x_n = (x * (x_max - x_min) / Image_fractale.GetLength(1) + x_min);
                        y_n = (y * (y_min - y_max) / Image_fractale.GetLength(0) + y_max);
                    }
                    int compteur = 0;

                    while ((x_n * x_n + y_n * y_n) < 4 && compteur < iteration_max)
                    {
                        double temporaire_x = x_n;
                        double temporaire_y = y_n;
                        x_n      = temporaire_x * temporaire_x - temporaire_y * temporaire_y + c_x;
                        y_n      = 2 * temporaire_x * temporaire_y + c_y;
                        compteur = compteur + 1;
                    }
                    if (compteur == iteration_max)
                    {
                        Image_fractale[x, y] = new Pixel(0, 0, 0);
                    }
                    else
                    {
                        //amélioration trouvée sur Internet pour rendre l'image plus agréable à regarder.
                        Image_fractale[x, y] = new Pixel((3 * compteur) % 256, (1 * compteur) % 256, (10 * compteur) % 256);
                    }
                }
            }
            return(Image_fractale);
        }