예제 #1
0
        private void Median_btn_Click(object sender, EventArgs e)
        {
            //Median
            int Window_Size = vScrollBar1.Value;

            int[] Median_Vector_R = new int[Window_Size * Window_Size];
            int[] Median_Vector_G = new int[Window_Size * Window_Size];
            int[] Median_Vector_B = new int[Window_Size * Window_Size];

            int frame = Window_Size / 2;
            int V     = 0;

            for (int x = frame; x < Source_Image.Width - frame; x++)
            {
                for (int y = frame; y < Source_Image.Height - frame; y++)
                {
                    V = 0;
                    //1-Get vectors
                    for (int i = 0; i < Window_Size; i++)
                    {
                        for (int j = 0; j < Window_Size; j++)
                        {
                            Median_Vector_R[V] = Source_Image.GetPixel(x + i - frame, y + j - frame).R;
                            Median_Vector_G[V] = Source_Image.GetPixel(x + i - frame, y + j - frame).G;
                            Median_Vector_B[V] = Source_Image.GetPixel(x + i - frame, y + j - frame).B;
                            V++;
                        }
                    }

                    //2-Sort vectors

                    Bubble_Sort(ref Median_Vector_R, Window_Size * Window_Size);
                    Bubble_Sort(ref Median_Vector_G, Window_Size * Window_Size);
                    Bubble_Sort(ref Median_Vector_B, Window_Size * Window_Size);


                    //3-pic mid point of sorted vector and assign it to DESTINATION_IMAGE
                    int RR = Median_Vector_R[Window_Size * Window_Size / 2 + 1];
                    int GG = Median_Vector_R[Window_Size * Window_Size / 2 + 1];
                    int BB = Median_Vector_R[Window_Size * Window_Size / 2 + 1];

                    Destination_Image.SetPixel(x, y, Color.FromArgb((int)RR, (int)GG, (int)BB));
                }
            }

            //Convolution(Source_Image, ref Destination_Image, Kernel, Window_Size);

            pictureBox_Destination.Image = Destination_Image;
        }
예제 #2
0
        private void GrayScale_btn_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < Source_Image.Width; i++)
            {
                for (int j = 0; j < Source_Image.Height; j++)
                {
                    int RR = Source_Image.GetPixel(i, j).R;
                    int GG = Source_Image.GetPixel(i, j).G;
                    int BB = Source_Image.GetPixel(i, j).B;

                    int Gray = (RR + GG + BB) / 3;
                    Destination_Image.SetPixel(i, j, Color.FromArgb(Gray, Gray, Gray));
                }
            }
            pictureBox_Destination.Image = Destination_Image;
        }
예제 #3
0
        private void Contrast_btn_Click(object sender, EventArgs e)
        {
            //Contrast
            int    Contrast_Value = vScrollBar3.Value;
            double F = (259 * (Contrast_Value + 255)) / (255 * (259 - Contrast_Value));

            for (int x = 0; x < Source_Image.Width; x++)
            {
                for (int y = 0; y < Source_Image.Height; y++)
                {
                    int result_R = (int)Math.Round(F * (Source_Image.GetPixel(x, y).R - 128) + 128);
                    int result_G = (int)Math.Round(F * (Source_Image.GetPixel(x, y).G - 128) + 128);
                    int result_B = (int)Math.Round(F * (Source_Image.GetPixel(x, y).B - 128) + 128);

                    if (result_R > 255)
                    {
                        result_R = 255;
                    }
                    else if (result_R < 0)
                    {
                        result_R = 0;
                    }
                    if (result_G > 255)
                    {
                        result_G = 255;
                    }
                    else if (result_G < 0)
                    {
                        result_G = 0;
                    }
                    if (result_B > 255)
                    {
                        result_B = 255;
                    }
                    else if (result_B < 0)
                    {
                        result_B = 0;
                    }

                    Destination_Image.SetPixel(x, y, Color.FromArgb((int)result_R, (int)result_G, (int)result_B));
                }
            }

            pictureBox_Destination.Image = Destination_Image;
        }
예제 #4
0
        private void Brightness_btn_Click(object sender, EventArgs e)
        {
            //Brightness
            int Brigthness_Value = vScrollBar2.Value;

            for (int x = 0; x < Source_Image.Width; x++)
            {
                for (int y = 0; y < Source_Image.Height; y++)
                {
                    int result_R = Source_Image.GetPixel(x, y).R + Brigthness_Value;
                    int result_G = Source_Image.GetPixel(x, y).G + Brigthness_Value;
                    int result_B = Source_Image.GetPixel(x, y).B + Brigthness_Value;

                    if (result_R > 255)
                    {
                        result_R = 255;
                    }
                    else if (result_R < 0)
                    {
                        result_R = 0;
                    }
                    if (result_G > 255)
                    {
                        result_G = 255;
                    }
                    else if (result_G < 0)
                    {
                        result_G = 0;
                    }
                    if (result_B > 255)
                    {
                        result_B = 255;
                    }
                    else if (result_B < 0)
                    {
                        result_B = 0;
                    }

                    Destination_Image.SetPixel(x, y, Color.FromArgb((int)result_R, (int)result_G, (int)result_B));
                }
            }

            pictureBox_Destination.Image = Destination_Image;
        }
예제 #5
0
        private void Gama_btn_Click(object sender, EventArgs e)
        {
            //Gama Correction
            double Gama_Value = vScrollBar4.Value / 10.0;

            for (int x = 0; x < Source_Image.Width; x++)
            {
                for (int y = 0; y < Source_Image.Height; y++)
                {
                    int result_R = (int)Math.Round(255 * Math.Pow(Source_Image.GetPixel(x, y).R / 255.0, 1 / Gama_Value));
                    int result_G = (int)Math.Round(255 * Math.Pow(Source_Image.GetPixel(x, y).G / 255.0, 1 / Gama_Value));
                    int result_B = (int)Math.Round(255 * Math.Pow(Source_Image.GetPixel(x, y).B / 255.0, 1 / Gama_Value));

                    Destination_Image.SetPixel(x, y, Color.FromArgb((int)result_R, (int)result_G, (int)result_B));
                }
            }

            pictureBox_Destination.Image = Destination_Image;
        }