Exemplo n.º 1
0
        private void btnEnviar_Click(object sender, EventArgs e)
        {
            int tam = m_Bitmap.Width * m_Bitmap.Height;

            float gamma_ = Int32.Parse(gamma.Text);
            gamma_ = gamma_/100;

            a = (FormPrincipal)MdiParent;
            a_Bitmap = new Bitmap(m_Bitmap.Width, m_Bitmap.Height);

            for (int i = 0; i < m_Bitmap.Width; i++)
            {
                for (int j = 0; j < m_Bitmap.Height; j++)
                {

                    nVal = (int)(Math.Pow((m_Bitmap.GetPixel(i,j).R / 255.0), gamma_) * 255);

                    a_Bitmap.SetPixel(i, j, Color.FromArgb(255, nVal, nVal, nVal));
                }
            }
            FormImagen subImagen = new FormImagen(a_Bitmap, a.lastid);
            a.Imagenes.Add(subImagen);
            a.Imagenes[a.lastid].MdiParent = this.MdiParent;
            a.Imagenes[a.lastid].Show();
            a.lastid++;
        }
Exemplo n.º 2
0
        private void btnEnviar_Click(object sender, EventArgs e)
        {
            a = (FormPrincipal)MdiParent;

            // Get the angle.
            angle = Int32.Parse(grados.Text);

            // Rotate.
            a_Bitmap = RotateBitmap(m_Bitmap, angle);

            // Display the result.
            FormImagen subImagen = new FormImagen(a_Bitmap, a.lastid);

            int wid = subImagen.pictureBox1.Right + subImagen.pictureBox1.Left;
            int hgt = subImagen.pictureBox1.Bottom + subImagen.pictureBox1.Left;
            this.ClientSize = new Size(
                Math.Max(wid, this.ClientSize.Width),
                Math.Max(hgt, this.ClientSize.Height));

            a.Imagenes.Add(subImagen);
            a.Imagenes[a.lastid].MdiParent = this.MdiParent;
            a.Imagenes[a.lastid].Show();
            a.lastid++;
            // Size the form to fit.
        }
Exemplo n.º 3
0
        private void cargarImagenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Show the Open File dialog. If the user clicks OK, load the
            // picture that the user chose.
            /* if (openFileDialog1.ShowDialog() == DialogResult.OK)
             {
                 pictureBox1.Load(openFileDialog1.FileName);
             }*/
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = "c:\\";
            openFileDialog.Filter = "*.*|*.*|Bitmap files (*.bmp)|*.bmp|Jpeg files (*.jpg)|*.jpg|Tiff files (*.tiff)|*.tiff";
            openFileDialog.FilterIndex = 2;
            openFileDialog.RestoreDirectory = true;

            if (DialogResult.OK == openFileDialog.ShowDialog())
            {
                FormImagen image = new FormImagen(openFileDialog.FileName, lastid);
                Imagenes.Add(image);
                Imagenes[lastid].MdiParent = this;
                Imagenes[lastid].Show();
                lastid++;
                this.Invalidate();
            }
        }
Exemplo n.º 4
0
        //   int pixels = 0, aux = 0, auxi = 0;
        //Color[] copia;
        public FormPrincipal()
        {
            InitializeComponent();
            WindowState = FormWindowState.Maximized;
            a = new int[256];
            Imagenes = new List<FormImagen>();

            FormImagen image = new FormImagen(@"C:\Users\Guille\Desktop\a.jpg", lastid);
            Imagenes.Add(image);
            Imagenes[lastid].MdiParent = this;
            Imagenes[lastid].Show();
            lastid++;
        }
Exemplo n.º 5
0
        private void btnEnviar_Click(object sender, EventArgs e)
        {
            a = (FormPrincipal)MdiParent;
            float nalto, nancho;

            if (percen)
            {
                nalto = Int32.Parse(alto.Text);
                nalto = (float)nalto/100 * m_Bitmap.Height;
                nalto = (int)nalto;
                nancho = Int32.Parse(ancho.Text);
                nancho = (float)nancho / 100 * m_Bitmap.Width;
                nancho = (int)nancho;
            }
            else
            {
                nalto = Int32.Parse(alto.Text);
                nancho = Int32.Parse(ancho.Text);
            }
            a_Bitmap = new Bitmap((int)nancho, (int)nalto);

            /*            double x_ratio = m_Bitmap.Width / (double)nancho;
            double y_ratio = m_Bitmap.Height / (double)nalto;
            double px, py; */

            float a1 = ((float)nancho) / (m_Bitmap.Width - 1);
            float b1 = ((float)nalto) / (m_Bitmap.Height - 1);
            float x = 0, y = 0;

            for(int i = 0; i < nancho; i++){
                   for(int j = 0; j < nalto; j++){
                       x = (int)Math.Round((i) / a1);
                       y = (int)Math.Round((j) / b1);

                       a_Bitmap.SetPixel(i, j, m_Bitmap.GetPixel((int)x,(int)y));
                       //colorAux = vecino(newAncho,newAlto,i,j);

                       //outImage.setRGB(i,j,colorAux.getRGB());
                   }
               }
            FormImagen subImagen = new FormImagen(a_Bitmap, a.lastid);
            a.Imagenes.Add(subImagen);
            a.Imagenes[a.lastid].MdiParent = this.MdiParent;
            a.Imagenes[a.lastid].Show();
            a.lastid++;
        }
Exemplo n.º 6
0
        private void btnEnviar_Click(object sender, EventArgs e)
        {
            int tam = m_Bitmap.Width * m_Bitmap.Height;

            for (int i = 0; i < hist.Count(); i++)
                vbrillo += hist[i] * i;

            vbrillo /= tam;

            for (int i = 0; i < hist.Count(); i++)
                vcontraste += hist[i] * (float)Math.Pow(i - vbrillo, 2);

            vcontraste = (float)Math.Sqrt(vcontraste / tam);

            float nbrillo = Int32.Parse(brillo.Text);
            float ncontraste = Int32.Parse(contraste.Text);
            int nVal;

            A = ncontraste / vcontraste;
            B = nbrillo - (A * vbrillo);

            a = (FormPrincipal)MdiParent;
            a_Bitmap = new Bitmap(m_Bitmap.Width, m_Bitmap.Height);

            for (int i = 0; i < m_Bitmap.Width; i++)
            {
                for (int j = 0; j < m_Bitmap.Height; j++)
                {
                    //int nVal = (int)(m_Bitmap.GetPixel(i, j).B + (int)nbrillo);

                    if (A != 0) nVal = ((int)(m_Bitmap.GetPixel(i, j).B * A + B));
                    else nVal= m_Bitmap.GetPixel(i, j).B + (int)B;
                    //red*A+B;
                    if (nVal < 0) nVal = 0;
                    if (nVal > 255) nVal = 255;

                    a_Bitmap.SetPixel(i, j, Color.FromArgb(255, nVal, nVal, nVal));
                }
            }
            FormImagen subImagen = new FormImagen(a_Bitmap, a.lastid);
            a.Imagenes.Add(subImagen);
            a.Imagenes[a.lastid].MdiParent = this.MdiParent;
            a.Imagenes[a.lastid].Show();
            a.lastid++;
        }
Exemplo n.º 7
0
        private void traspuestaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Bitmap trans = new Bitmap(Imagenes.Find(x => x.id == activeid).m_Bitmap.Width, Imagenes.Find(x => x.id == activeid).m_Bitmap.Height);
            Bitmap m_Bitmap = Imagenes.Find(x => x.id == activeid).m_Bitmap;

            if (m_Bitmap.Height != m_Bitmap.Width)
            {
                trans = new Bitmap(Imagenes.Find(x => x.id == activeid).m_Bitmap.Height, Imagenes.Find(x => x.id == activeid).m_Bitmap.Width);

                //trans.Height = m_Bitmap.Width;
                //trans.Width = m_Bitmap.Height;
            }

            for (int i = 0; i < m_Bitmap.Width; i++)
            {
                for (int j = 0; j < m_Bitmap.Height; j++)
                {
                    Color aux = m_Bitmap.GetPixel(i, j);
                    trans.SetPixel(j, i, aux);
                }
            }
            FormImagen image = new FormImagen(trans, lastid);
            Imagenes.Add(image);
            Imagenes[lastid].MdiParent = this;
            Imagenes[lastid].Show();
            lastid++;
            this.Invalidate();
        }
Exemplo n.º 8
0
 private void espejoHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Bitmap trans = new Bitmap(Imagenes.Find(x => x.id == activeid).m_Bitmap.Width, Imagenes.Find(x => x.id == activeid).m_Bitmap.Height);
     Bitmap m_Bitmap = Imagenes.Find(x => x.id == activeid).m_Bitmap;
     int width = m_Bitmap.Width - 1;
     for (int i = 0; i < m_Bitmap.Width; i++)
     {
         for (int j = 0; j < m_Bitmap.Height; j++)
         {
             Color aux = m_Bitmap.GetPixel(i, j);
             trans.SetPixel(width - i, j, aux);
         }
     }
     FormImagen image = new FormImagen(trans, lastid);
     Imagenes.Add(image);
     Imagenes[lastid].MdiParent = this;
     Imagenes[lastid].Show();
     lastid++;
     this.Invalidate();
 }
Exemplo n.º 9
0
 private void escalaDeGrisesToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Bitmap trans = new Bitmap(Imagenes.Find(x => x.id == activeid).m_Bitmap.Width, Imagenes.Find(x => x.id == activeid).m_Bitmap.Height);
     Bitmap m_Bitmap = Imagenes.Find(x => x.id == activeid).m_Bitmap;
     for (int i = 0; i < m_Bitmap.Width; i++)
     {
         for (int j = 0; j < m_Bitmap.Height; j++)
         {
             Color gris = m_Bitmap.GetPixel(i, j);
             int grey = (gris.R + gris.G + gris.B) / 3;
             trans.SetPixel(i, j, Color.FromArgb(gris.A, grey, grey, grey));
             //                        m_Bitmap.SetPixel(i, j,m_Bitmap.GetPixel(j,i));
             //pixels = pixels + 1;
         }
     }
     FormImagen image = new FormImagen(trans, lastid);
     Imagenes.Add(image);
     Imagenes[lastid].MdiParent = this;
     Imagenes[lastid].Show();
     lastid++;
     //        pictureBox1.Image = m_Bitmap;
     this.Invalidate();
 }
Exemplo n.º 10
0
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            if (select)
            {

                MouseEventArgs me = (MouseEventArgs)e;
                Point coordinates = me.Location;
                if (!ROI)
                {
                    Color valor = m_Bitmap.GetPixel(coordinates.X, coordinates.Y);
                    MessageBox.Show(coordinates + " Valor de gris " + valor.G);
                }

                if (ROI)
                {
                    if (segundo)
                    {
                        int aux = 0, auxi = 0;
                        int temp;
                        cx = coordinates.X;
                        cy = coordinates.Y;
                        if (cpx > cx) { temp = cpx; cpx = cx; cx = temp; }
                        if (cpy > cy) { temp = cpy; cpy = cy; cy = temp; }
                        rectx = cx - cpx;
                        recty = cy - cpy;
                        copia = new Color[rectx * recty];
                        //Size tam = new Size(Math.Abs(cx-cpx),Math.Abs(cy-cpy));
                        a_Bitmap = new Bitmap(rectx, recty);
                        for (int i = cpx; i < cx; i++)
                        {
                            for (int j = cpy; j < cy; j++)
                            {
                                copia[aux] = m_Bitmap.GetPixel(i, j);
                                aux++;
                                //                            a_Bitmap.SetPixel(i,j,copia);
                            }
                        }

                        for (int i = 0; i < rectx; i++)
                        {
                            for (int j = 0; j < recty; j++)
                            {
                                a_Bitmap.SetPixel(i, j, copia[auxi]);
                                auxi++;
                            }
                        }
                        /*FormPrincipal*/
                        a = (FormPrincipal)MdiParent;
                        FormImagen subImagen = new FormImagen(a_Bitmap, a.lastid);
                        a.Imagenes.Add(subImagen);
                        a.Imagenes[a.lastid].MdiParent = this.MdiParent;
                        a.Imagenes[a.lastid].Show();
                        a.lastid++;
                        segundo = !segundo;
                    }
                    else
                    {
                        cpx = coordinates.X;
                        cpy = coordinates.Y;
                        segundo = !segundo;
                        MessageBox.Show("Selecciona el segundo pixel");
                    }

                }
            }
        }
Exemplo n.º 11
0
        private void histogramaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = "c:\\";
            openFileDialog.Filter = "Bitmap files (*.bmp)|*.bmp|Jpeg files (*.jpg)|*.jpg|Tiff files (*.tiff)|*.tiff|*.*|*.*";
            openFileDialog.FilterIndex = 2;
            openFileDialog.RestoreDirectory = true;

            if (DialogResult.OK == openFileDialog.ShowDialog())
            {
                FormImagen image = new FormImagen(openFileDialog.FileName,99); // ID 99
                this.acum = new float[256];
                this.acumaux = new float[256];
                this.resul = new float[256];

                int aux = 0;
                for (int i = 0; i < m_Bitmap.Width; i++)
                {
                    for (int j = 0; j < m_Bitmap.Height; j++)
                    {
                        image.hist[m_Bitmap.GetPixel(i, j).B] += 1;
                    }
                }

                for (int i = 0; i < hist.Count(); i++)
                {
                    image.ahist[i] = hist[i] + aux;
                    aux = aux + hist[i];
                }

                float[] acum = convertToScale(image.ahist, 0, image.ahist.Last(), 0, 1);

                float[] acumaux = convertToScale(ahist, 0, ahist.Last(), 0, 1);

                for (int i = 0; i < 256; i++)
                {
                    acum[i] = acumaux[i];
                }

                for (int i = 0; i < m_Bitmap.Width; i++)
                {
                    for (int j = 0; j < m_Bitmap.Height; j++)
                    {
                        aux = m_Bitmap.GetPixel(i, j).B;

                        a_Bitmap.SetPixel(i, j, Color.FromArgb(255, acum[aux], acum[aux], acum[aux]));
                        //                        m_Bitmap.SetPixel(i, j,m_Bitmap.GetPixel(j,i));

                    }
                }

            /*                int sizeo = image.m_Bitmap.Width * image.m_Bitmap.Height;
                int size2 = this.Width * this.Height;

                for (int i = 0; i < 256; i++)
                    this.acumaux[i] = image.ahist[i] / image.ahist.Last();

                for (int i = 0; i < 256; i++)
                    this.acum[i] = ahist[i] / ahist.Last();
                */

                FormImagen image1 = new FormImagen(a_Bitmap, a.lastid);

                a.Imagenes.Add(image1);
                a.Imagenes[a.lastid].MdiParent = this.MdiParent;
                a.Imagenes[a.lastid].Show();
                a.lastid++;
                this.Invalidate();

            }
        }
Exemplo n.º 12
0
        private void diferenciaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = "c:\\";
            openFileDialog.Filter = "*.*|*.*|Bitmap files (*.bmp)|*.bmp|Jpeg files (*.jpg)|*.jpg|Tiff files (*.tiff)|*.tiff";
            openFileDialog.FilterIndex = 2;
            openFileDialog.RestoreDirectory = true;

            if (DialogResult.OK == openFileDialog.ShowDialog())
            {
                FormImagen image = new FormImagen(openFileDialog.FileName, a.lastid);
                FormImagen imaged = new FormImagen(openFileDialog.FileName, a.lastid);

                for (int i = 0; i < image.m_Bitmap.Width; i++)
                {
                    int valor;
                    for (int j = 0; j < image.m_Bitmap.Height; j++)
                    {
                        //Almacenamos el color del píxel
                        //                        valor= image.m_Bitmap.GetPixel(i, j).A
                        //                        this.m_Bitmap.GetPixel(i, j).A
                        valor = Math.Abs(image.m_Bitmap.GetPixel(i, j).B - this.m_Bitmap.GetPixel(i, j).B);

                        imaged.m_Bitmap.SetPixel(i, j, Color.FromArgb(Color.Red.A, valor, valor, valor));

                        if (valor > 0)
                        {

                            //Asignamos el nuevo valor
                            image.m_Bitmap.SetPixel(i, j, Color.FromArgb(Color.Red.A, 255, 0, 0));
                        }
                    }
                }

                a.Imagenes.Add(image);
                a.Imagenes[a.lastid].MdiParent = this.MdiParent;
                a.Imagenes[a.lastid].Show();
                a.lastid++;
                this.Invalidate();

                a.Imagenes.Add(imaged);
                a.Imagenes[a.lastid].MdiParent = this.MdiParent;
                a.Imagenes[a.lastid].Show();
                a.lastid++;
                this.Invalidate();
            }
        }
Exemplo n.º 13
0
        private void btnEnviar_Click(object sender, EventArgs e)
        {
            a = (FormPrincipal)MdiParent;
            float nalto, nancho;

            if (percen)
            {
                nalto = Int32.Parse(alto.Text);
                nalto = (float)nalto / 100 * m_Bitmap.Height;
                nalto = (int)nalto;
                nancho = Int32.Parse(ancho.Text);
                nancho = (float)nancho / 100 * m_Bitmap.Width;
                nancho = (int)nancho;
            }
            else
            {
                nalto = Int32.Parse(alto.Text);
                nancho = Int32.Parse(ancho.Text);
            }

            a_Bitmap = new Bitmap((int)nancho, (int)nalto);

            float a1 = ((float)nancho) / (m_Bitmap.Width - 1);
            float b1 = ((float)nalto) / (m_Bitmap.Height - 1);
            for (int i = 0; i < nancho; i++)
            {
                for (int j = 0; j < nalto; j++)
                {
                    float x = ((float)i) / a1;
                    float y = ((float)j) / b1;

                    int minX = (int)Math.Floor(x);
                    int minY = (int)Math.Floor(y);
                    int maxX = minX + 1;
                    int maxY = minY + 1;

                    double p = Math.Abs(x - minX);
                    double q = Math.Abs(y - minY);

                    Color pA = m_Bitmap.GetPixel(minX, maxY);
                    Color pB = m_Bitmap.GetPixel(maxX, maxY);
                    Color pC = m_Bitmap.GetPixel(minX, minY);
                    Color pD = m_Bitmap.GetPixel(maxX, minY);

                    int valor = (int)(((float)pC.R) + ((float)(pD.R - pC.R)) * p + ((float)(pA.R - pC.R)) * q + ((float)(pB.R + pC.R - pA.R - pD.R)) * p * q);

                    a_Bitmap.SetPixel(i, j, Color.FromArgb(255,valor,valor,valor));
                }
            }

            FormImagen subImagen = new FormImagen(a_Bitmap, a.lastid);
            a.Imagenes.Add(subImagen);
            a.Imagenes[a.lastid].MdiParent = this.MdiParent;
            a.Imagenes[a.lastid].Show();
            a.lastid++;
        }