private Bitmap Median(Image image)
        {
            Bitmap bimage = new Bitmap(image);

            int[,,] rgbImg = new int[image.Height, image.Width, 3];
            int[] pixel = new int[this.filterSize * this.filterSize];

            RGBExtraTrans rgbObj = new RGBExtraTrans(this.tabControl1);

            rgbImg = rgbObj.ColorExtractionRGB(bimage);

            for (int y = 1; y < image.Height - 1; y++)
            {
                for (int x = 1; x < image.Width - 1; x++)
                {
                    pixel = Neighbor(rgbImg, x, y, 0);
                    int invR = pixel[4];
                    pixel = Neighbor(rgbImg, x, y, 1);
                    int invG = pixel[4];
                    pixel = Neighbor(rgbImg, x, y, 2);
                    int invB = pixel[4];
                    bimage.SetPixel(x, y, Color.FromArgb(invR, invG, invB));
                }
            }
            return(bimage);
        }
        private Bitmap Mean(Image image)
        {
            Bitmap bimage = new Bitmap(image);

            int[,,] rgbImg = new int[image.Height, image.Width, 3];

            RGBExtraTrans rgbObj = new RGBExtraTrans(this.tabControl1);

            rgbImg = rgbObj.ColorExtractionRGB(bimage);

            for (int y = 1; y < image.Height - 1; y++)
            {
                for (int x = 1; x < image.Width - 1; x++)
                {
                    int invR = 0, invG = 0, invB = 0;
                    foreach (int item in Neighbor(rgbImg, x, y, 0))
                    {
                        invR += item / (this.filterSize * this.filterSize);
                    }
                    foreach (int item in Neighbor(rgbImg, x, y, 1))
                    {
                        invG += item / (this.filterSize * this.filterSize);
                    }
                    foreach (int item in Neighbor(rgbImg, x, y, 2))
                    {
                        invB += item / (this.filterSize * this.filterSize);
                    }
                    bimage.SetPixel(x, y, Color.FromArgb(invR, invG, invB));
                }
            }
            return(bimage);
        }
示例#3
0
 public Form1()
 {
     InitializeComponent();
     this.rgbObj = new RGBExtraTrans(this.tabControl1);
     this.filObj = new SmoothFilter(this.tabControl1);
     this.hieObj = new HistogramEqualization(this.tabControl1);
     this.thrObj = new DefinedThres(this.tabControl1);
     this.dctObj = new EdgeDetect(this.tabControl1);
     this.ovrObj = new EdgeOverlap(this.tabControl1);
     this.rotObj = new Rotate(this.tabControl1);
     this.sihObj = new StretchingInHorizontal(this.tabControl1);
     this.sivObj = new StretchingInVertical(this.tabControl1);
 }
        private Bitmap Combined(Image image)
        {
            Bitmap bimage = new Bitmap(image);

            int[,,] rgbImg = new int[image.Height, image.Width, 3];
            int[,] gx      = new int[, ] {
                { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 }
            };
            int[,] gy = new int[, ] {
                { 1, 2, 1 }, { 0, 0, 0 }, { -1, -2, -1 }
            };

            RGBExtraTrans rgbObj = new RGBExtraTrans(this.tabControl1);

            rgbImg = rgbObj.ColorExtractionRGB(bimage);

            for (int y = 1; y < image.Height - 1; y++)
            {
                for (int x = 1; x < image.Width - 1; x++)
                {
                    for (int z = 0; z < 3; z++)
                    {
                        int Gx = 0, Gy = 0;
                        for (int i = -1; i < 2; i++)
                        {
                            for (int j = -1; j < 2; j++)
                            {
                                Gx += gx[i + 1, j + 1] * rgbImg[y + j, x + i, z];
                                Gy += gy[i + 1, j + 1] * rgbImg[y + j, x + i, z];
                            }
                        }
                        if ((Math.Pow(Gx, 2) + Math.Pow(Gy, 2)) > Math.Pow(128, 2))
                        {
                            bimage.SetPixel(x, y, Color.White);
                        }
                    }
                }
            }
            return(bimage);
        }
        private Bitmap Horizontal(Image image)
        {
            Bitmap bimage = new Bitmap(image);

            int[,,] rgbImg = new int[image.Height, image.Width, 3];
            int[,] gx      = new int[, ] {
                { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 }
            };

            RGBExtraTrans rgbObj = new RGBExtraTrans(this.tabControl1);

            rgbImg = rgbObj.ColorExtractionRGB(bimage);

            for (int y = 1; y < image.Height - 1; y++)
            {
                for (int x = 1; x < image.Width - 1; x++)
                {
                    for (int z = 0; z < 3; z++)
                    {
                        int G = 0;
                        for (int i = -1; i < 2; i++)
                        {
                            for (int j = -1; j < 2; j++)
                            {
                                G += gx[i + 1, j + 1] * rgbImg[y + j, x + i, z];
                            }
                        }
                        if (G > 128)
                        {
                            bimage.SetPixel(x, y, Color.White);
                        }
                    }
                }
            }
            return(bimage);
        }