Ejemplo n.º 1
0
 private void posterizationToolStripMenuItem_Click(object sender, EventArgs e)
 {
     valueForm = new ValueForm(0, 255, "Liczba poziomów szarości:");
     if (valueForm.ShowDialog() == DialogResult.OK)
     {
         ImageHelper.Posterize(((ImageForm)ActiveMdiChild).Image, valueForm.Value);
         ((ImageForm)ActiveMdiChild).Refresh();
         ((ImageForm)ActiveMdiChild).Changed = true;
     }
 }
Ejemplo n.º 2
0
 private void gammaToolStripMenuItem_Click(object sender, EventArgs e)
 {
     valueForm = new ValueForm(1, 20, "Podaj wartość:");
     if (valueForm.ShowDialog() == DialogResult.OK)
     {
         ImageHelper.GammaCorrect(((ImageForm)ActiveMdiChild).Image, valueForm.Value);
         ((ImageForm)ActiveMdiChild).Refresh();
         ((ImageForm)ActiveMdiChild).Changed = true;
     }
 }
Ejemplo n.º 3
0
 private void rozciaganieToolStripMenuItem_Click(object sender, EventArgs e)
 {
     valueForm = new ValueForm(0, 255, "Podaj dolną wartość:");
     if (valueForm.ShowDialog() == DialogResult.OK)
     {
         int low = valueForm.Value;
         valueForm = new ValueForm(0, 255, "Podaj górną wartość:");
         if (valueForm.ShowDialog() == DialogResult.OK)
         {
             ImageHelper.Rozciagnij(((ImageForm)ActiveMdiChild).Image, low, valueForm.Value);
             ((ImageForm)ActiveMdiChild).Refresh();
             ((ImageForm)ActiveMdiChild).Changed = true;
         }
     }
 }
Ejemplo n.º 4
0
        private void medianFilteringToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FastBitmap bmp = ((ImageForm)ActiveMdiChild).Image;

            valueForm = new ValueForm(3, 21, "Podaj rozmiar macierzy:", false, true);
            if (valueForm.ShowDialog() == DialogResult.OK)
            {
                int filterSize = valueForm.Value;
                for (int i = 0; i < bmp.Size.Width; ++i)
                {
                    for (int j = 0; j < bmp.Size.Height; ++j)
                    {
                        byte[] neighbours = new byte[filterSize * filterSize];
                        int    a          = 0;
                        for (int k = -filterSize / 2; k <= filterSize / 2; ++k)
                        {
                            for (int l = -filterSize / 2; l <= filterSize / 2; ++l)
                            {
                                neighbours[a++] = bmp[i + k, j + l].R;
                            }
                        }

                        Color color = bmp[i, j];
                        byte  newColor;
                        Array.Sort(neighbours);
                        if (neighbours.Length % 2 == 1)
                        {
                            newColor = neighbours[neighbours.Length / 2];
                        }
                        else
                        {
                            newColor = (byte)((neighbours[neighbours.Length / 2] + neighbours[(neighbours.Length / 2) + 1]) / 2);
                        }
                        bmp[i, j] = Color.FromArgb(color.A, newColor, newColor, newColor);
                    }
                }
                ((ImageForm)ActiveMdiChild).Refresh();
                ((ImageForm)ActiveMdiChild).Changed = true;
            }
        }
Ejemplo n.º 5
0
        private void adaptiveTresholdToolStripMenuItem_Click(object sender, EventArgs e)
        {
            valueForm = new ValueForm(3, 21, "Enter the matrix size", false, true);
            if (valueForm.ShowDialog() == DialogResult.OK)
            {
                FastBitmap bmp  = ((ImageForm)ActiveMdiChild).Image;
                int        size = valueForm.Value / 2;

                for (int i = size; i < bmp.Width - size; ++i)
                {
                    for (int j = size; j < bmp.Height - size; ++j)
                    {
                        int mean = 0;

                        for (int k = i - size; k < i + size + 1; ++k)
                        {
                            for (int l = j - size; l < j + size + 1; ++l)
                            {
                                mean += bmp[k, l].R;
                            }
                        }

                        mean /= (2 * size + 1) * (2 * size + 1);

                        if (bmp[i, j].R >= mean)
                        {
                            bmp[i, j] = Color.FromArgb(255, 255, 255, 255);
                        }
                        else
                        {
                            bmp[i, j] = Color.FromArgb(255, 0, 0, 0);
                        }
                    }
                }
            }
            ((ImageForm)ActiveMdiChild).Refresh();
            ((ImageForm)ActiveMdiChild).Changed = true;
        }
Ejemplo n.º 6
0
        private void compressBlockToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FastBitmap bitmap = ((ImageForm)ActiveMdiChild).Image;

            valueForm = new ValueForm(1, 100, "Enter the block size");
            if (valueForm.ShowDialog() == DialogResult.OK)
            {
                int size = valueForm.Value;

                int   color = 0;
                float avg;
                float avgUP;
                float avgDOWN;
                int   countUP;
                int   countDOWN;
                int   countAVG;
                int   sizeAfter = 0;
                for (int y = 0; y < bitmap.Size.Height; y += size)
                {
                    for (int x = 0; x < bitmap.Size.Width; x += size)
                    {
                        avg      = 0;
                        countAVG = 0;
                        for (int yy = 0; yy < size; ++yy)
                        {
                            for (int xx = 0; xx < size; ++xx)
                            {
                                if (x + xx < bitmap.Size.Width && y + yy < bitmap.Size.Height)
                                {
                                    color = bitmap[x + xx, y + yy].R;
                                    avg  += color;
                                    ++countAVG;
                                }
                            }
                        }

                        avg /= countAVG;
                        avg  = (int)avg;

                        avgUP     = 0;
                        avgDOWN   = 0;
                        countDOWN = 0;
                        countUP   = 0;
                        for (int yy = 0; yy < size; ++yy)
                        {
                            for (int xx = 0; xx < size; ++xx)
                            {
                                if (x + xx < bitmap.Size.Width && y + yy < bitmap.Size.Height)
                                {
                                    color = bitmap[x + xx, y + yy].R;
                                    if (color >= avg)
                                    {
                                        avgUP += color; ++countUP;
                                    }
                                    else
                                    {
                                        avgDOWN += color; ++countDOWN;
                                    }
                                }
                            }
                        }
                        avgUP   /= countUP;
                        avgDOWN /= countDOWN;
                        avgUP    = (int)avgUP;
                        avgDOWN  = (int)avgDOWN;

                        for (int yy = 0; yy < size; ++yy)
                        {
                            for (int xx = 0; xx < size; ++xx)
                            {
                                if (x + xx < bitmap.Size.Width && y + yy < bitmap.Size.Height)
                                {
                                    color = bitmap[x + xx, y + yy].R;
                                    if (color >= avg)
                                    {
                                        bitmap[x + xx, y + yy] = Color.FromArgb(255, (int)avgUP, (int)avgUP, (int)avgUP);
                                    }
                                    else
                                    {
                                        bitmap[x + xx, y + yy] = Color.FromArgb(255, (int)avgDOWN, (int)avgDOWN, (int)avgDOWN);
                                    }
                                }
                            }
                        }

                        sizeAfter += size * size + 16;
                    }
                }

                int sizeBefore = bitmap.Size.Width * bitmap.Size.Height * 8;

                ((ImageForm)ActiveMdiChild).Refresh();
                ((ImageForm)ActiveMdiChild).Changed = true;
                MessageBox.Show("Original size: " + sizeBefore + "\nNew size: " + sizeAfter + "\nCompression level: " + (float)sizeBefore / (float)sizeAfter, "Compression results");
            }
        }