Example #1
0
        /// <summary>
        /// Nuance de gris, poids de chaque couleur trouve sur internet
        /// </summary>
        /// <returns></returns>
        public MyPixel GreyScale()
        {
            int     grey      = (int)(0.2126 * this.red + 0.7152 * this.green + 0.0722 * this.blue);
            MyPixel GreyPixel = new MyPixel(grey, grey, grey);

            return(GreyPixel);
        }
Example #2
0
        /// <summary>
        /// Applique l'effet d'agrandissement
        /// </summary>
        public void Agrandir(int coef)
        {
            int h = this.Hauteur * coef;

            int l = this.Largeur * coef;

            this.TailleFichier = 54 + (3 * h * l);



            MyPixel[,] nouvelleImage = new MyPixel[h, l];


            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < l; j++)
                {
                    nouvelleImage[i, j] = this.Image[i / coef, j / coef];
                }
            }
            this.Image = new MyPixel[h, l];


            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < l; j++)
                {
                    this.Image[i, j] = nouvelleImage[i, j];
                }
            }
        }
Example #3
0
        /// <summary>
        /// fais tourner l'image d'un certain angle en utilisant une matrice de rotation
        /// </summary>
        /// <param name="angle"></param>
        public void Rotation(double angle)
        {
            double angleRadians = (double)angle * Math.PI / 180;
            int    h            = (Convert.ToInt32(Math.Sin(angleRadians) * this.Largeur + Math.Cos(angleRadians) * this.Hauteur));
            int    l            = (Convert.ToInt32(Math.Cos(angleRadians) * this.Largeur + Math.Sin(angleRadians) * this.Hauteur));

            if (h < 0)
            {
                h *= -1;
            }
            if (l < 0)
            {
                l *= -1;
            }

            MyPixel[,] nouvelleImage = new MyPixel[h, l];



            int coordcentrex = (int)((this.Largeur / 2) - Math.Cos(angleRadians) * (l / 2) - Math.Sin(angleRadians) * (h / 2));
            int coordcentrey = (int)((this.Hauteur / 2) - Math.Cos(angleRadians) * (h / 2) + Math.Sin(angleRadians) * (l / 2));

            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < l; j++)
                {
                    int coordx = Convert.ToInt32(Math.Cos(angleRadians) * (i - coordcentrex) - (Math.Sin(angleRadians) * (j - coordcentrey)));
                    int coordy = Convert.ToInt32(Math.Sin(angleRadians) * (i - coordcentrex) + (Math.Cos(angleRadians) * (j - coordcentrey)));



                    if (coordx <= l && coordx >= 0 && coordy <= h && coordy >= 0)
                    {
                        nouvelleImage[i, j] = this.Image[coordx, coordy];
                    }
                    else
                    {
                        nouvelleImage[i, j] = new MyPixel(0, 0, 0);
                    }
                }
            }


            this.Image         = new MyPixel[h, l];
            this.Hauteur       = h;
            this.Largeur       = l;
            this.TailleFichier = 54 + (3 * l * h);

            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < l; j++)
                {
                    this.Image[i, j] = nouvelleImage[i, j];
                }
            }
        }
Example #4
0
        /// <summary>
        /// applique la suite de mandelbrot en colorant les points selon le nombre d'iterations
        /// </summary>
        public void Fractale(int iterations)
        {
            int h = this.Hauteur;
            int l = this.Largeur;

            MyPixel[,] imageFractale = new MyPixel[h, l];
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < l; j++)
                {
                    double  a        = (double)(i - (l / 2)) / (double)(l / 4);
                    double  b        = (double)(j - (l / 2)) / (double)(l / 4);
                    Complex complex  = new Complex(a, b);
                    Complex z        = new Complex(0, 0);
                    int     compteur = 0;


                    while (compteur < iterations)
                    {
                        z.Carre();
                        z.Addition(complex);
                        if (z.Module() > 2)
                        {
                            break;
                        }
                        compteur++;
                    }
                    if (compteur < iterations)
                    {
                        imageFractale[i, j] = new MyPixel(255, 255, 255);
                    }
                    if (compteur % 3 == 0)
                    {
                        imageFractale[i, j] = new MyPixel(150, 50, 75);
                    }
                    else if (compteur % 10 == 0)
                    {
                        imageFractale[i, j] = new MyPixel(100, 100, 255);
                    }
                    else
                    {
                        imageFractale[i, j] = new MyPixel(20, 25, 255);
                    }
                }
            }
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < l; j++)
                {
                    this.Image[i, j] = imageFractale[i, j];
                }
            }
        }
Example #5
0
        /// <summary>
        /// fais tourner l'image d'un certain angle en utilisant les coordonnees polaires
        /// </summary>
        /// <param name="angle"></param>
        public void Rotation1(int angle)
        {
            double angleRadians = (double)angle * Math.PI / 180;

            int h = (int)(Math.Sin(angleRadians) * this.Image.GetLength(1) + Math.Cos(angleRadians) * this.Image.GetLength(0));
            int l = (int)(Math.Cos(angleRadians) * this.Image.GetLength(1) + Math.Sin(angleRadians) * this.Image.GetLength(0));



            MyPixel[,] nouvelleImageRot = new MyPixel[h, l];

            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < l; j++)
                {
                    double coordx = j;
                    double coordy = h - i - (Math.Sin(angleRadians) * this.Image.GetLength(1));

                    double rho          = Math.Sqrt((coordx * coordx) + (coordy * coordy));
                    double anglePolaire = Math.Atan2(coordy, coordx);

                    double x = rho * Math.Cos(anglePolaire);
                    double y = rho * Math.Sin(anglePolaire);

                    if ((int)(this.Image.GetLength(0) - y) >= 0 && x >= 0 && (int)(this.Image.GetLength(0) - y) < this.Image.GetLength(0) && x < this.Image.GetLength(1))
                    {
                        nouvelleImageRot[i, j] = this.Image[(int)(this.Image.GetLength(0) - y), (int)x];
                    }
                    else
                    {
                        nouvelleImageRot[i, j] = new MyPixel(0, 0, 0);
                    }
                }
            }

            this.Image         = new MyPixel[h, l];
            this.Hauteur       = h;
            this.Largeur       = l;
            this.TailleFichier = 54 + (3 * l * h);

            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < l; j++)
                {
                    this.Image[i, j] = nouvelleImageRot[i, j];
                }
            }
        }
Example #6
0
        /// <summary>
        /// Prend les 4 premiers bits de l'image encodee et rempli de 0
        /// </summary>
        /// <returns></returns>
        public MyPixel DesassemblerPixels()
        {
            MyPixel PixelFinal = new MyPixel(0, 0, 0);

            string R = Convert.ToString(this.PixelR, 2).PadLeft(8, '0');
            string G = Convert.ToString(this.PixelG, 2).PadLeft(8, '0');
            string B = Convert.ToString(this.PixelB, 2).PadLeft(8, '0');

            string Rfinal = R.Substring(4, 4) + "0" + "0" + "0" + "0";
            string Gfinal = G.Substring(4, 4) + "0" + "0" + "0" + "0";
            string Bfinal = B.Substring(4, 4) + "0" + "0" + "0" + "0";

            PixelFinal.PixelR = Convert.ToInt32(Rfinal, 2);
            PixelFinal.PixelG = Convert.ToInt32(Gfinal, 2);
            PixelFinal.PixelB = Convert.ToInt32(Bfinal, 2);

            return(PixelFinal);
        }
Example #7
0
        /// <summary>
        /// Applique l'effet de nuances de gris
        /// </summary>
        public void Greyscale()
        {
            int hauteur = this.Hauteur;
            int largeur = this.Largeur;

            MyPixel[,] nouvelleImage = new MyPixel[hauteur, largeur];
            for (int i = 0; i < hauteur; i++)
            {
                for (int j = 0; j < largeur; j++)
                {
                    nouvelleImage[i, j] = this.image[i, j].GreyScale();
                }
            }
            for (int i = 0; i < hauteur; i++)
            {
                for (int j = 0; j < largeur; j++)
                {
                    this.Image[i, j] = nouvelleImage[i, j];
                }
            }
        }
Example #8
0
        /// <summary>
        /// Applique l'effet mirroir
        /// </summary>
        public void EffetMirroir()
        {
            int hauteur = this.Hauteur;
            int largeur = this.Largeur;

            MyPixel[,] nouvelleImage = new MyPixel[hauteur, largeur];
            for (int i = 0; i < hauteur; i++)
            {
                for (int j = 0; j < largeur; j++)
                {
                    nouvelleImage[i, j] = this.Image[i, largeur - 1 - j];
                }
            }
            for (int i = 0; i < hauteur; i++)
            {
                for (int j = 0; j < largeur; j++)
                {
                    this.Image[i, j] = nouvelleImage[i, j];
                }
            }
        }
Example #9
0
        /// <summary>
        /// Prend les 4 premiers bits de la premiere image et les 4 derniers de la deuxieme image et en fait un seul pixel
        /// </summary>
        /// <param name="pixel"></param>
        /// <returns></returns>
        public MyPixel RassemblerPixels(MyPixel pixel)
        {
            MyPixel PixelFinal = new MyPixel(0, 0, 0);

            string R2 = Convert.ToString(pixel.PixelR, 2).PadLeft(8, '0');
            string G2 = Convert.ToString(pixel.PixelG, 2).PadLeft(8, '0');
            string B2 = Convert.ToString(pixel.PixelB, 2).PadLeft(8, '0');

            string R1 = Convert.ToString(this.PixelR, 2).PadLeft(8, '0');
            string G1 = Convert.ToString(this.PixelG, 2).PadLeft(8, '0');
            string B1 = Convert.ToString(this.PixelB, 2).PadLeft(8, '0');

            string Rfinal = R1.Substring(0, 4) + R2.Substring(0, 4);
            string Gfinal = G1.Substring(0, 4) + G2.Substring(0, 4);
            string Bfinal = B1.Substring(0, 4) + B2.Substring(0, 4);

            PixelFinal.PixelR = Convert.ToInt32(Rfinal, 2);
            PixelFinal.PixelG = Convert.ToInt32(Gfinal, 2);
            PixelFinal.PixelB = Convert.ToInt32(Bfinal, 2);
            return(PixelFinal);
        }
Example #10
0
        /// <summary>
        /// decode l'image passee en variable d'instance, appelle DesassemblerPixels
        /// </summary>
        /// <param name="image2"></param>
        public void DecodageImage()
        {
            int h = this.Hauteur;
            int l = this.Largeur;

            MyPixel[,] nouvelleImage = new MyPixel[h, l];

            for (int i = 0; i < Hauteur; i++)
            {
                for (int j = 0; j < Largeur; j++)
                {
                    nouvelleImage[i, j] = this.Image[i, j].DesassemblerPixels();
                }
            }

            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < l; j++)
                {
                    this.Image[i, j] = nouvelleImage[i, j];
                }
            }
        }
Example #11
0
        /// <summary>
        /// code l'image passee en parametre dans celle appelle comme variable d'instance, appelle RassemblerPixels
        /// </summary>
        /// <param name="image2"></param>
        public void CodageImage(MyImage image2)
        {
            int h = this.Hauteur;
            int l = this.Largeur;

            MyPixel[,] nouvelleImage = new MyPixel[h, l];

            for (int i = 0; i < Hauteur; i++)
            {
                for (int j = 0; j < Largeur; j++)
                {
                    nouvelleImage[i, j] = this.image[i, j].RassemblerPixels(image2.image[i, j]);
                }
            }

            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < l; j++)
                {
                    this.Image[i, j] = nouvelleImage[i, j];
                }
            }
        }