Beispiel #1
0
        public static Bitmap LaplaceGreyscale(Bitmap b)
        {
            ImagerBitmap i  = new ImagerBitmap(b.Clone() as Bitmap);
            ImagerBitmap i2 = new ImagerBitmap(b.Clone() as Bitmap);

            for (int column = 1; column < i.Bitmap.Width - 1; column++)
            {
                for (int row = 1; row < i.Bitmap.Height - 1; row++)
                {
                    int[,] c = i.GetGrey3x3(row, column);
                    int val = (((c[0, 0] + c[0, 1] + c[0, 2] + c[1, 0] + c[1, 2] + c[2, 0] + c[2, 1]
                                 + c[2, 2]) * -1) + (c[1, 1] * 8)) + 128;
                    if (val >= 128)
                    {
                        val = 0;
                    }
                    else
                    {
                        val = 255;
                    }
                    i2.SetPixel(column, row, Color.FromArgb(val, val, val));
                }
            }
            i.UnlockBitmap();
            i2.UnlockBitmap();
            return(i2.Bitmap.Clone() as Bitmap);
        }
Beispiel #2
0
        /// <summary>
        /// Perform a Bionomial filter using a 3x3 Mask
        /// </summary>
        /// <param name="b">Image to Process</param>
        /// <returns>Filtered Image</returns>
        public static Bitmap Binomial3x3(Bitmap b)
        {
            ImagerBitmap i  = new ImagerBitmap(b.Clone() as Bitmap);
            ImagerBitmap i2 = new ImagerBitmap(b.Clone() as Bitmap);

            for (int column = 1; column < i.Bitmap.Width - 1; column++)
            {
                for (int row = 1; row < i.Bitmap.Height - 1; row++)
                {
                    Color[,] c = i.Get3x3(row, column);
                    int red = ((c[0, 0].R * 1) + (c[0, 1].R * 2) + (c[0, 2].R * 1) + (c[1, 0].R * 2)
                               + (c[1, 1].R * 4) + (c[1, 2].R * 2) + (c[2, 0].R * 1) + (c[2, 1].R * 2)
                               + (c[2, 2].R * 1)) / 16;
                    int green = ((c[0, 0].G * 1) + (c[0, 1].G * 2) + (c[0, 2].G * 1) + (c[1, 0].G * 2)
                                 + (c[1, 1].G * 4) + (c[1, 2].G * 2) + (c[2, 0].G * 1) + (c[2, 1].G * 2)
                                 + (c[2, 2].G * 1)) / 16;
                    int blue = ((c[0, 0].B * 1) + (c[0, 1].B * 2) + (c[0, 2].B * 1) + (c[1, 0].B * 2)
                                + (c[1, 1].B * 4) + (c[1, 2].B * 2) + (c[2, 0].B * 1) + (c[2, 1].B * 2)
                                + (c[2, 2].B * 1)) / 16;
                    i2.SetPixel(column, row, Color.FromArgb(red, green, blue));
                }
            }
            i.UnlockBitmap();
            i2.UnlockBitmap();
            return(i2.Bitmap.Clone() as Bitmap);
        }
Beispiel #3
0
        private void gauss()
        {
            var bmp = pictureBox1.Image as Bitmap;

            using (var img = new ImagerBitmap(bmp))
            {
                int gaussWidth = 5;
                for (int x = gaussWidth; x < img.Width - 5; x++)
                {
                    for (int y = gaussWidth; y < img.Height - 5; y++)
                    {
                        int R = 0, G = 0, B = 0, count = 0;

                        for (int x1 = x - gaussWidth; x1 <= x + gaussWidth; x1++)
                        {
                            for (int y1 = y - gaussWidth; y1 <= y + gaussWidth; y1++)
                            {
                                var c = img.GetPixel(x1, y1);
                                count++;
                                R += c.R;
                                G += c.G;
                                B += c.B;
                            }
                        }
                        img.SetPixel(x, y, Color.FromArgb(R / count, G / count, B / count));
                    }
                }

                pictureBox1.Image = img.Bitmap;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Perform a Median fiter using a 5x5 Mask
        /// </summary>
        /// <param name="b">Image to Process</param>
        /// <returns>Filtered Image</returns>
        public static Bitmap Median5x5(Bitmap b)
        {
            ImagerBitmap i  = new ImagerBitmap(b.Clone() as Bitmap);
            ImagerBitmap i2 = new ImagerBitmap(b.Clone() as Bitmap);

            for (int column = 2; column < i.Bitmap.Width - 2; column++)
            {
                for (int row = 2; row < i.Bitmap.Height - 2; row++)
                {
                    Color[,] c = i.Get5x5(row, column);
                    int red = Median(c[0, 0].R, c[0, 1].R, c[0, 2].R, c[0, 3].R, c[0, 4].R, c[1, 0].R,
                                     c[1, 1].R, c[1, 2].R, c[1, 3].R, c[1, 4].R, c[2, 0].R, c[2, 1].R, c[2, 2].R,
                                     c[2, 3].R, c[2, 4].R, c[3, 0].R, c[3, 1].R, c[3, 2].R, c[3, 3].R, c[3, 4].R,
                                     c[4, 0].R, c[4, 1].R, c[4, 2].R, c[4, 3].R, c[4, 4].R);
                    int green = Median(c[0, 0].G, c[0, 1].G, c[0, 2].G, c[0, 3].G, c[0, 4].G, c[1, 0].G,
                                       c[1, 1].G, c[1, 2].G, c[1, 3].G, c[1, 4].G, c[2, 0].G, c[2, 1].G, c[2, 2].G,
                                       c[2, 3].G, c[2, 4].G, c[3, 0].G, c[3, 1].G, c[3, 2].G, c[3, 3].G, c[3, 4].G,
                                       c[4, 0].G, c[4, 1].G, c[4, 2].G, c[4, 3].G, c[4, 4].G);
                    int blue = Median(c[0, 0].B, c[0, 1].B, c[0, 2].B, c[0, 3].B, c[0, 4].B, c[1, 0].B,
                                      c[1, 1].B, c[1, 2].B, c[1, 3].B, c[1, 4].B, c[2, 0].B, c[2, 1].B, c[2, 2].B,
                                      c[2, 3].B, c[2, 4].B, c[3, 0].B, c[3, 1].B, c[3, 2].B, c[3, 3].B, c[3, 4].B,
                                      c[4, 0].B, c[4, 1].B, c[4, 2].B, c[4, 3].B, c[4, 4].B);
                    i2.SetPixel(column, row, Color.FromArgb(red, green, blue));
                }
            }
            i.UnlockBitmap();
            i2.UnlockBitmap();
            return(i2.Bitmap.Clone() as Bitmap);
        }
Beispiel #5
0
        private void button4_Click(object sender, EventArgs e)
        {
            var bmp = pictureBox1.Image as Bitmap;
            var dst = bmp.Clone() as Bitmap;

            using (var img = new ImagerBitmap(bmp))
                using (var imgDst = new ImagerBitmap(dst))
                {
                    int gaussWidth = 1;
                    for (int x = gaussWidth; x < img.Width - 5; x++)
                    {
                        for (int y = gaussWidth; y < img.Height - 5; y++)
                        {
                            List <MedianPixel> neibourghs = new List <MedianPixel>();

                            for (int x1 = x - gaussWidth; x1 <= x + gaussWidth; x1++)
                            {
                                for (int y1 = y - gaussWidth; y1 <= y + gaussWidth; y1++)
                                {
                                    var c = img.GetPixel(x1, y1);
                                    neibourghs.Add(new MedianPixel(c));
                                }
                            }

                            var newColor = neibourghs.OrderBy(n => n.Intensity).Skip(neibourghs.Count / 2).First().Color;

                            imgDst.SetPixel(x, y, newColor);
                        }
                    }

                    pictureBox1.Image = imgDst.Bitmap;
                }
        }
Beispiel #6
0
        private void button4_Click(object sender, EventArgs e)
        {
            var bmp = pictureBox1.Image as Bitmap;
            var dst = bmp.Clone() as Bitmap;

            using (var img = new ImagerBitmap(bmp))
            using (var imgDst = new ImagerBitmap(dst))
            {
                int gaussWidth = 1;
                for (int x = gaussWidth; x < img.Width - 5; x++)
                    for (int y = gaussWidth; y < img.Height - 5; y++)
                    {
                        List<MedianPixel> neibourghs = new List<MedianPixel>();

                        for (int x1 = x - gaussWidth; x1 <= x + gaussWidth; x1++)
                            for (int y1 = y - gaussWidth; y1 <= y + gaussWidth; y1++)
                            {
                                var c = img.GetPixel(x1, y1);
                                neibourghs.Add(new MedianPixel(c));
                            }

                        var newColor = neibourghs.OrderBy(n => n.Intensity).Skip(neibourghs.Count / 2).First().Color;

                        imgDst.SetPixel(x, y, newColor);
                    }

                pictureBox1.Image = imgDst.Bitmap;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Generate a greyscale histogram chart from the bitmap
        /// </summary>
        /// <param name="b">Image to use</param>
        /// <returns>Histogram chart</returns>

        /*public static Bitmap GenerateGreyscaleHistogram(Bitmap b)
         * {
         *  ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);
         *  double[] histogram = new double[256];
         *  string[] lbls = new string[256];
         *  for (int column = 0; column < i.Bitmap.Width; column++)
         *  {
         *      for (int row = 0; row < i.Bitmap.Height; row++)
         *      {
         *          histogram[i.GetGreyPixel(column, row)]++;
         *      }
         *  }
         *  i.UnlockBitmap();
         *  for (int j = 0; j < 256; j++)
         *  {
         *      if ((j % 30) == 0)
         *      {
         *          lbls[j] = j.ToString();
         *      }
         *      else
         *      {
         *          lbls[j] = string.Empty;
         *      }
         *  }
         *  XYChart c = new XYChart(b.Width + 60, b.Height + 60);
         *  c.setPlotArea(40, 40, b.Width - 20, b.Height - 20);
         *  c.addTitle("Greyscale Historgram", "Arial Bold", 10).setBackground(
         *      Chart.metalColor(0x9999ff), -1, 1);
         *  c.addBarLayer(histogram);
         *  c.xAxis().setLabels(lbls);
         *  return c.makeImage() as Bitmap;
         * }*/
        /// <summary>
        /// Generate a histogram chart from the bitmap
        /// </summary>
        /// <param name="b">Image to use</param>
        /// <returns>Histogram chart</returns>

        /* public static Bitmap GenerateHistogram(Bitmap b)
         * {
         *   ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);
         *   double[] histogram = new double[64];
         *   string[] lbls = new string[64];
         *   for (int column = 0; column < i.Bitmap.Width; column++)
         *   {
         *       for (int row = 0; row < i.Bitmap.Height; row++)
         *       {
         *           histogram[i.GetRGBHistogramValue(column, row)]++;
         *       }
         *   }
         *   i.UnlockBitmap();
         *   for (int j = 0; j < 64; j++)
         *   {
         *       if ((j % 10) == 0)
         *       {
         *           lbls[j] = j.ToString();
         *       }
         *       else
         *       {
         *           lbls[j] = string.Empty;
         *       }
         *   }
         *   XYChart c = new XYChart(b.Width + 60, b.Height + 60);
         *   c.setPlotArea(40, 40, b.Width - 20, b.Height - 20);
         *   c.addTitle("Color Historgram", "Arial Bold", 10).setBackground(
         *       Chart.metalColor(0x9999ff), -1, 1);
         *   c.addBarLayer(histogram);
         *   c.xAxis().setLabels(lbls);
         *   return c.makeImage() as Bitmap;
         * }*/
        /// <summary>
        /// Generate a Chart of a Scan line
        /// </summary>
        /// <param name="b">Image to use</param>
        /// <param name="row">Row to use</param>
        /// <returns>Scan Line Chart</returns>

        /*public static Bitmap GenerateScanLineChart(Bitmap b, int row)
         * {
         *  ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);
         *  double[] luminance = new double[b.Width];
         *  string[] lbls = new string[b.Width];
         *  double max = double.MinValue;
         *  double min = double.MaxValue;
         *  for (int column = 0; column < i.Bitmap.Width; column++)
         *  {
         *      luminance[column] = i.GetGreyPixel(column, row);
         *      if (luminance[column] > max) max = luminance[column];
         *      if (luminance[column] < min) min = luminance[column];
         *      if ((column % 40) == 0)
         *      {
         *          lbls[column] = column.ToString();
         *      }
         *      else
         *      {
         *          lbls[column] = string.Empty;
         *      }
         *  }
         *  i.UnlockBitmap();
         *  XYChart c = new XYChart(b.Width + 60, b.Height + 60);
         *  c.setPlotArea(40, 40, b.Width - 20, b.Height - 20);
         *  c.addTitle(string.Format("Pixel Luminance for Scan Line {0}, STF {1:0.00}",
         *      row.ToString(),
         *      (max - min) / (max + min)), "Arial Bold", 10).setBackground(
         *      Chart.metalColor(0x9999ff), -1, 1);
         *  c.addLineLayer(luminance);
         *  c.xAxis().setLabels(lbls);
         *  return c.makeImage() as Bitmap;
         * }*/
        /// <summary>
        /// Generate a Chart of a Vertical Scan line
        /// </summary>
        /// <param name="b">Image to use</param>
        /// <param name="column">Column to use</param>
        /// <returns>Scan Line Chart</returns>

        /*public static Bitmap GenerateVerticalScanLineChart(Bitmap b, int col)
         * {
         *  ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);
         *  double[] luminance = new double[b.Height];
         *  string[] lbls = new string[b.Height];
         *  for (int row = 0; row < i.Bitmap.Height; row++)
         *  {
         *      luminance[row] = i.GetGreyPixel(col, row);
         *      if ((row % 40) == 0)
         *      {
         *          lbls[row] = row.ToString();
         *      }
         *      else
         *      {
         *          lbls[row] = string.Empty;
         *      }
         *  }
         *  i.UnlockBitmap();
         *  XYChart c = new XYChart(b.Width + 60, b.Height + 60);
         *  c.setPlotArea(40, 40, b.Width - 20, b.Height - 20);
         *  c.addTitle("Pixel Luminance for Vertical Scan Line " + col.ToString(),
         *      "Arial Bold", 10).setBackground(
         *      Chart.metalColor(0x9999ff), -1, 1);
         *  c.addLineLayer(luminance);
         *  c.xAxis().setLabels(lbls);
         *  return c.makeImage() as Bitmap;
         * }*/
        public static void GenerateExcelFile(Bitmap b)
        {
            ImagerBitmap i        = new ImagerBitmap(b.Clone() as Bitmap);
            string       fileName = "output.txt";
            int          f        = 0;

            using (StreamWriter sw = new StreamWriter(fileName, false))
            {
                sw.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}", "Index", "Row", "Column", "Red",
                             "Green", "Blue", "Gray");
                for (int column = 0; column < i.Bitmap.Width; column++)
                {
                    for (int row = 0; row < i.Bitmap.Height; row++)
                    {
                        f++;
                        Color c = i.GetPixel(column, row);
                        int   g = i.GetGreyPixel(column, row);
                        sw.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}", f,
                                     row, column, c.R, c.G, c.B, g);
                    }
                }
            }
            i.UnlockBitmap();
            System.Diagnostics.Process.Start(fileName);
        }
Beispiel #8
0
        private void button2_Click(object sender, EventArgs e)
        {
            var bmp = pictureBox1.Image as Bitmap;

            using (var img = new ImagerBitmap(bmp))
            {
                int gaussWidth = 5;
                for (int x = gaussWidth; x < img.Width-5; x++)
                    for (int y = gaussWidth; y < img.Height-5; y++)
                    {
                        int R = 0, G = 0, B = 0, count = 0;

                        for (int x1 = x - gaussWidth; x1 <= x + gaussWidth;x1++ )
                            for (int y1 = y - gaussWidth; y1 <= y + gaussWidth; y1++)
                            {
                                var c = img.GetPixel(x1, y1);
                                count++;
                                R += c.R;
                                G += c.G;
                                B += c.B;
                            }
                        img.SetPixel(x, y, Color.FromArgb(R/count, G/count, B/count));
                    }

                pictureBox1.Image = img.Bitmap;
            }
        }
Beispiel #9
0
        /// <summary>
        /// Get the green pixels from the image
        /// </summary>
        /// <param name="b">Image to Process</param>
        /// <returns>Filtered Image</returns>
        public static Bitmap GetGreenBitmap(Bitmap b)
        {
            ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);

            for (int column = 0; column < i.Bitmap.Width; column++)
            {
                for (int row = 0; row < i.Bitmap.Height; row++)
                {
                    i.SetPixel(column, row, Color.FromArgb(0, i.GetPixel(column, row).G, 0));
                }
            }
            i.UnlockBitmap();
            return(i.Bitmap.Clone() as Bitmap);
        }
Beispiel #10
0
        /// <summary>
        /// Perform laplace edge detection on the image
        /// </summary>
        /// <param name="b">Source Image</param>
        /// <returns>Edges</returns>
        public static Bitmap Laplace(Bitmap b)
        {
            ImagerBitmap i  = new ImagerBitmap(b.Clone() as Bitmap);
            ImagerBitmap i2 = new ImagerBitmap(b.Clone() as Bitmap);

            for (int column = 1; column < i.Bitmap.Width - 1; column++)
            {
                for (int row = 1; row < i.Bitmap.Height - 1; row++)
                {
                    Color[,] c = i.Get3x3(row, column);
                    int red = (((c[0, 0].R + c[0, 1].R + c[0, 2].R + c[1, 0].R + c[1, 2].R + c[2, 0].R
                                 + c[2, 1].R + c[2, 2].R) * -1) + (c[1, 1].R * 8)) + 128;
                    int green = (((c[0, 0].G + c[0, 1].G + c[0, 2].G + c[1, 0].G + c[1, 2].G
                                   + c[2, 0].G + c[2, 1].G + c[2, 2].G) * -1) + (c[1, 1].G * 8)) + 128;
                    int blue = (((c[0, 0].B + c[0, 1].B + c[0, 2].B + c[1, 0].B + c[1, 2].B + c[2, 0].B
                                  + c[2, 1].B + c[2, 2].B) * -1) + (c[1, 1].B * 8)) + 128;
                    if (red >= 128)
                    {
                        red = 0;
                    }
                    else
                    {
                        red = 255;
                    }
                    if (green >= 128)
                    {
                        green = 0;
                    }
                    else
                    {
                        green = 255;
                    }
                    if (blue >= 128)
                    {
                        blue = 0;
                    }
                    else
                    {
                        blue = 255;
                    }
                    i2.SetPixel(column, row, Color.FromArgb(red, green, blue));
                }
            }
            i.UnlockBitmap();
            i2.UnlockBitmap();
            return(i2.Bitmap.Clone() as Bitmap);
        }
Beispiel #11
0
        private void button1_Click(object sender, EventArgs e)
        {
            var bmp = pictureBox1.Image as Bitmap;

            using(var img = new ImagerBitmap(bmp))
            {
                for (int x = 0; x < img.Width; x++)
                    for (int y = 0; y < img.Height; y++)
                    {
                        var px = img.GetPixel(x, y);
                        var intensity = (int)(px.R*0.16 + px.B*0.6 + px.G*0.24);
                        Color newColor = Color.FromArgb(intensity, intensity, intensity);
                        img.SetPixel(x,y,newColor);
                    }

                pictureBox1.Image = img.Bitmap;
            }
        }
Beispiel #12
0
        private void button6_Click(object sender, EventArgs e)
        {
            var bmp = pictureBox1.Image as Bitmap;

            Random rnd = new Random();

            using (var img = new ImagerBitmap(bmp))
            {
                for (int x = 0; x < img.Width; x++)
                {
                    for (int y = 0; y < img.Height; y++)
                    {
                        var px = img.GetPixel(x, y);
                        var S  = ((px.R * 0.16 + px.G * 0.6 + px.B * 0.24) / 128 - 1) * ((float)trackBar1.Value / 5) + 1;
                        img.SetPixel(x, y, Color.FromArgb(cl(px.R * S), cl(px.G * S), cl(px.B * S)));
                    }
                }
                pictureBox1.Image = img.Bitmap;
            }
        }
Beispiel #13
0
        private void button1_Click(object sender, EventArgs e)
        {
            var bmp = pictureBox1.Image as Bitmap;

            using (var img = new ImagerBitmap(bmp))
            {
                for (int x = 0; x < img.Width; x++)
                {
                    for (int y = 0; y < img.Height; y++)
                    {
                        var   px        = img.GetPixel(x, y);
                        var   intensity = (int)(px.R * 0.16 + px.B * 0.6 + px.G * 0.24);
                        Color newColor  = Color.FromArgb(intensity, intensity, intensity);
                        img.SetPixel(x, y, newColor);
                    }
                }

                pictureBox1.Image = img.Bitmap;
            }
        }
Beispiel #14
0
        public static Bitmap GetBlackAndWhiteBitmap2(Bitmap b)
        {
            ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);

            double[] histogram = new double[256];
            for (int column = 0; column < i.Bitmap.Width; column++)
            {
                for (int row = 0; row < i.Bitmap.Height; row++)
                {
                    histogram[i.GetGreyPixel(column, row)]++;
                }
            }
            double k      = b.Width * b.Height;
            double half   = k / 2;
            int    middle = 0;

            while (k > half)
            {
                k = k - histogram[middle];
                middle++;
            }
            for (int column = 0; column < i.Bitmap.Width; column++)
            {
                for (int row = 0; row < i.Bitmap.Height; row++)
                {
                    int val = (i.GetPixel(column, row).R + i.GetPixel(column, row).G
                               + i.GetPixel(column, row).B) / 3;
                    if (val > middle)
                    {
                        val = 255;
                    }
                    else
                    {
                        val = 0;
                    }
                    i.SetPixel(column, row, Color.FromArgb(val, val, val));
                }
            }
            i.UnlockBitmap();
            return(i.Bitmap.Clone() as Bitmap);
        }
Beispiel #15
0
        /// <summary>
        /// Perform a Binomial filter using a 5x5 Mask
        /// </summary>
        /// <param name="b">Image to Process</param>
        /// <returns>Filtered Image</returns>
        public static Bitmap Binomial5x5(Bitmap b)
        {
            ImagerBitmap i  = new ImagerBitmap(b.Clone() as Bitmap);
            ImagerBitmap i2 = new ImagerBitmap(b.Clone() as Bitmap);

            for (int column = 2; column < i.Bitmap.Width - 2; column++)
            {
                for (int row = 2; row < i.Bitmap.Height - 2; row++)
                {
                    Color[,] c = i.Get5x5(row, column);
                    int red = ((c[0, 0].R * 1) + (c[0, 1].R * 4) + (c[0, 2].R * 6) + (c[0, 3].R * 4)
                               + (c[0, 4].R * 1) + (c[1, 0].R * 4) + (c[1, 1].R * 16) + (c[1, 2].R * 24)
                               + (c[1, 3].R * 16) + (c[1, 4].R * 4) + (c[2, 0].R * 6) + (c[2, 1].R * 24)
                               + (c[2, 2].R * 36) + (c[2, 3].R * 24) + (c[2, 4].R * 6) + (c[3, 0].R * 4)
                               + (c[3, 1].R * 16) + (c[3, 2].R * 24) + (c[3, 3].R * 16) + (c[3, 4].R * 4)
                               + (c[4, 0].R * 1) + (c[4, 1].R * 4) + (c[4, 2].R * 6) + (c[4, 3].R * 4)
                               + (c[4, 4].R * 1)) / 256;
                    int green = ((c[0, 0].G * 1) + (c[0, 1].G * 4) + (c[0, 2].G * 6) + (c[0, 3].G * 4)
                                 + (c[0, 4].G * 1) + (c[1, 0].G * 4) + (c[1, 1].G * 16) + (c[1, 2].G * 24)
                                 + (c[1, 3].G * 16) + (c[1, 4].G * 4) + (c[2, 0].G * 6) + (c[2, 1].G * 24)
                                 + (c[2, 2].G * 36) + (c[2, 3].G * 24) + (c[2, 4].G * 6) + (c[3, 0].G * 4)
                                 + (c[3, 1].G * 16) + (c[3, 2].G * 24) + (c[3, 3].G * 16) + (c[3, 4].G * 4)
                                 + (c[4, 0].G * 1) + (c[4, 1].G * 4) + (c[4, 2].G * 6) + (c[4, 3].G * 4)
                                 + (c[4, 4].G * 1)) / 256;
                    int blue = ((c[0, 0].B * 1) + (c[0, 1].B * 4) + (c[0, 2].B * 6) + (c[0, 3].B * 4)
                                + (c[0, 4].B * 1) + (c[1, 0].B * 4) + (c[1, 1].B * 16) + (c[1, 2].B * 24)
                                + (c[1, 3].B * 16) + (c[1, 4].B * 4) + (c[2, 0].B * 6) + (c[2, 1].B * 24)
                                + (c[2, 2].B * 36) + (c[2, 3].B * 24) + (c[2, 4].B * 6) + (c[3, 0].B * 4)
                                + (c[3, 1].B * 16) + (c[3, 2].B * 24) + (c[3, 3].B * 16) + (c[3, 4].B * 4)
                                + (c[4, 0].B * 1) + (c[4, 1].B * 4) + (c[4, 2].B * 6) + (c[4, 3].B * 4)
                                + (c[4, 4].B * 1)) / 256;
                    i2.SetPixel(column, row, Color.FromArgb(red, green, blue));
                }
            }
            i.UnlockBitmap();
            i2.UnlockBitmap();
            return(i2.Bitmap.Clone() as Bitmap);
        }
Beispiel #16
0
        private void button5_Click(object sender, EventArgs e)
        {
            var bmp = pictureBox1.Image as Bitmap;

            Random rnd = new Random();

            using (var img = new ImagerBitmap(bmp))
            {
                for (int x = 0; x < img.Width; x++)
                {
                    for (int y = 0; y < img.Height; y++)
                    {
                        if (rnd.Next(6000) == 555)
                        {
                            img.SetPixel(x, y, Color.Red);
                        }
                        if (rnd.Next(6000) == 556)
                        {
                            img.SetPixel(x, y, Color.Blue);
                        }
                        if (rnd.Next(6000) == 557)
                        {
                            img.SetPixel(x, y, Color.Green);
                        }
                        if (rnd.Next(6000) == 556)
                        {
                            img.SetPixel(x, y, Color.Black);
                        }
                        if (rnd.Next(6000) == 557)
                        {
                            img.SetPixel(x, y, Color.White);
                        }
                    }
                }

                pictureBox1.Image = img.Bitmap;
            }
        }
Beispiel #17
0
 /// <summary>
 /// Make the image Grey scale
 /// </summary>
 /// <param name="b">Image to Process</param>
 /// <returns>Filtered Image</returns>
 public static Bitmap GetGreyScaleBitmap(Bitmap b)
 {
     ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);
     for (int column = 0; column < i.Bitmap.Width; column++)
     {
         for (int row = 0; row < i.Bitmap.Height; row++)
         {
             int val = i.GetGreyPixel(column, row);
             i.SetPixel(column, row, Color.FromArgb(val, val, val));
         }
     }
     i.UnlockBitmap();
     return i.Bitmap.Clone() as Bitmap;
 }
Beispiel #18
0
 /// <summary>
 /// Get the red pixels from the bitmap
 /// </summary>
 /// <param name="b">Image to Process</param>
 /// <returns>Filtered Image</returns>
 public static Bitmap GetRedBitmap(Bitmap b)
 {
     ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);
     for (int column = 0; column < i.Bitmap.Width; column++)
     {
         for (int row = 0; row < i.Bitmap.Height; row++)
         {
             i.SetPixel(column, row, Color.FromArgb(i.GetPixel(column, row).R, 0, 0));
         }
     }
     i.UnlockBitmap();
     return i.Bitmap.Clone() as Bitmap;
 }
Beispiel #19
0
 /// <summary>
 /// Subtract b2 from b1 and normalize the image
 /// </summary>
 /// <param name="b1">Image</param>
 /// <param name="b2">Image</param>
 /// <returns>Normalized Image</returns>
 public static Bitmap Subtract(Bitmap b1, Bitmap b2)
 {
     if (b1.Width != b2.Width || b1.Height != b2.Height)
         throw new Exception("Images not the same size cannot subtract");
     ImagerBitmap i = new ImagerBitmap(b1.Clone() as Bitmap);
     ImagerBitmap i2 = new ImagerBitmap(b2.Clone() as Bitmap);
     int[,] red = new int[i.Bitmap.Width, i.Bitmap.Height];
     int[,] blue = new int[i.Bitmap.Width, i.Bitmap.Height];
     int[,] green = new int[i.Bitmap.Width, i.Bitmap.Height];
     int redMax = 0;
     int redMin = 0;
     int redRange = 0;
     int blueMax = 0;
     int blueMin = 0;
     int blueRange = 0;
     int greenMax = 0;
     int greenMin = 0;
     int greenRange = 0;
     //fill the arrays with the subtracted values
     //Keep track of the min and max values for later
     for (int column = 0; column < i.Bitmap.Width; column++)
     {
         for (int row = 0; row < i.Bitmap.Height; row++)
         {
             Color c1 = i.GetPixel(column, row);
             Color c2 = i2.GetPixel(column, row);
             red[column, row] = c2.R - c1.R;
             blue[column, row] = c2.B - c1.B;
             green[column, row] = c2.G - c1.G;
             if (red[column, row] > redMax) redMax = red[column, row];
             if (red[column, row] < redMin) redMin = red[column, row];
             if (blue[column, row] > blueMax) blueMax = blue[column, row];
             if (blue[column, row] < blueMin) blueMin = blue[column, row];
             if (green[column, row] > greenMax) greenMax = green[column, row];
             if (green[column, row] < greenMin) greenMin = green[column, row];
         }
     }
     //find the range of the min an max
     redRange = Math.Abs(redMax - redMin);
     blueRange = Math.Abs(blueMax - blueMin);
     greenRange = Math.Abs(greenRange - greenMin);
     //Normalize the values in the arrays and load the result image
     for (int column = 0; column < i.Bitmap.Width; column++)
     {
         for (int row = 0; row < i.Bitmap.Height; row++)
         {
             if (redRange != 0)
                 red[column, row] = 255 - (((redMax - red[column, row]) * 255) / redRange);
             if (blueRange != 0)
                 blue[column, row] = 255 - (((blueMax - blue[column, row]) * 255) / blueRange);
             if (greenRange != 0)
                 green[column, row] = 255 - (((greenMax - green[column, row]) * 255) / greenRange);
             if (red[column, row] < 0)
                 red[column, row] = 0;
             if (blue[column, row] < 0)
                 blue[column, row] = 0;
             if (green[column, row] < 0)
                 green[column, row] = 0;
             i2.SetPixel(column, row, Color.FromArgb(red[column, row], green[column, row],
                 blue[column, row]));
         }
     }
     i.UnlockBitmap();
     i2.UnlockBitmap();
     return i2.Bitmap.Clone() as Bitmap;
 }
Beispiel #20
0
        private void button9_Click(object sender, EventArgs e)
        {
            var bmp = pictureBox1.Image as Bitmap;
            var dst = bmp.Clone() as Bitmap;

            using (var img = new ImagerBitmap(bmp))
            {
                for (int x = 0; x < img.Width; x++)
                    for (int y = 0; y < img.Height; y++)
                    {
                        var px = img.GetPixel(x, y);

                        Color newColor;

                        if (px.B >= 128)
                            newColor = Color.FromArgb(px.R, px.G, 200);
                        else
                            newColor = Color.FromArgb(px.R, px.G, px.B);

                        img.SetPixel(x, y, newColor);
                    }

                pictureBox1.Image = img.Bitmap;
            }
        }
Beispiel #21
0
        private void button5_Click(object sender, EventArgs e)
        {
            var bmp = pictureBox1.Image as Bitmap;

            Random rnd = new Random();

            using (var img = new ImagerBitmap(bmp))
            {
                for (int x = 0; x < img.Width; x++)
                    for (int y = 0; y < img.Height; y++)
                    {
                        if (rnd.Next(6000) == 555)
                            img.SetPixel(x, y, Color.Red);
                        if (rnd.Next(6000) == 556)
                            img.SetPixel(x, y, Color.Blue);
                        if (rnd.Next(6000) == 557)
                            img.SetPixel(x, y, Color.Green);
                        if (rnd.Next(6000) == 556)
                            img.SetPixel(x, y, Color.Black);
                        if (rnd.Next(6000) == 557)
                            img.SetPixel(x, y, Color.White);
                    }

                pictureBox1.Image = img.Bitmap;
            }
        }
Beispiel #22
0
 /// <summary>
 /// Generate a greyscale histogram chart from the bitmap
 /// </summary>
 /// <param name="b">Image to use</param>
 /// <returns>Histogram chart</returns>
 /*public static Bitmap GenerateGreyscaleHistogram(Bitmap b)
 {
     ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);
     double[] histogram = new double[256];
     string[] lbls = new string[256];
     for (int column = 0; column < i.Bitmap.Width; column++)
     {
         for (int row = 0; row < i.Bitmap.Height; row++)
         {
             histogram[i.GetGreyPixel(column, row)]++;
         }
     }
     i.UnlockBitmap();
     for (int j = 0; j < 256; j++)
     {
         if ((j % 30) == 0)
         {
             lbls[j] = j.ToString();
         }
         else
         {
             lbls[j] = string.Empty;
         }
     }
     XYChart c = new XYChart(b.Width + 60, b.Height + 60);
     c.setPlotArea(40, 40, b.Width - 20, b.Height - 20);
     c.addTitle("Greyscale Historgram", "Arial Bold", 10).setBackground(
         Chart.metalColor(0x9999ff), -1, 1);
     c.addBarLayer(histogram);
     c.xAxis().setLabels(lbls);
     return c.makeImage() as Bitmap;
 }*/
 /// <summary>
 /// Generate a histogram chart from the bitmap
 /// </summary>
 /// <param name="b">Image to use</param>
 /// <returns>Histogram chart</returns>
 /* public static Bitmap GenerateHistogram(Bitmap b)
  {
      ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);
      double[] histogram = new double[64];
      string[] lbls = new string[64];
      for (int column = 0; column < i.Bitmap.Width; column++)
      {
          for (int row = 0; row < i.Bitmap.Height; row++)
          {
              histogram[i.GetRGBHistogramValue(column, row)]++;
          }
      }
      i.UnlockBitmap();
      for (int j = 0; j < 64; j++)
      {
          if ((j % 10) == 0)
          {
              lbls[j] = j.ToString();
          }
          else
          {
              lbls[j] = string.Empty;
          }
      }
      XYChart c = new XYChart(b.Width + 60, b.Height + 60);
      c.setPlotArea(40, 40, b.Width - 20, b.Height - 20);
      c.addTitle("Color Historgram", "Arial Bold", 10).setBackground(
          Chart.metalColor(0x9999ff), -1, 1);
      c.addBarLayer(histogram);
      c.xAxis().setLabels(lbls);
      return c.makeImage() as Bitmap;
  }*/
 /// <summary>
 /// Generate a Chart of a Scan line
 /// </summary>
 /// <param name="b">Image to use</param>
 /// <param name="row">Row to use</param>
 /// <returns>Scan Line Chart</returns>
 /*public static Bitmap GenerateScanLineChart(Bitmap b, int row)
 {
     ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);
     double[] luminance = new double[b.Width];
     string[] lbls = new string[b.Width];
     double max = double.MinValue;
     double min = double.MaxValue;
     for (int column = 0; column < i.Bitmap.Width; column++)
     {
         luminance[column] = i.GetGreyPixel(column, row);
         if (luminance[column] > max) max = luminance[column];
         if (luminance[column] < min) min = luminance[column];
         if ((column % 40) == 0)
         {
             lbls[column] = column.ToString();
         }
         else
         {
             lbls[column] = string.Empty;
         }
     }
     i.UnlockBitmap();
     XYChart c = new XYChart(b.Width + 60, b.Height + 60);
     c.setPlotArea(40, 40, b.Width - 20, b.Height - 20);
     c.addTitle(string.Format("Pixel Luminance for Scan Line {0}, STF {1:0.00}",
         row.ToString(),
         (max - min) / (max + min)), "Arial Bold", 10).setBackground(
         Chart.metalColor(0x9999ff), -1, 1);
     c.addLineLayer(luminance);
     c.xAxis().setLabels(lbls);
     return c.makeImage() as Bitmap;
 }*/
 /// <summary>
 /// Generate a Chart of a Vertical Scan line
 /// </summary>
 /// <param name="b">Image to use</param>
 /// <param name="column">Column to use</param>
 /// <returns>Scan Line Chart</returns>
 /*public static Bitmap GenerateVerticalScanLineChart(Bitmap b, int col)
 {
     ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);
     double[] luminance = new double[b.Height];
     string[] lbls = new string[b.Height];
     for (int row = 0; row < i.Bitmap.Height; row++)
     {
         luminance[row] = i.GetGreyPixel(col, row);
         if ((row % 40) == 0)
         {
             lbls[row] = row.ToString();
         }
         else
         {
             lbls[row] = string.Empty;
         }
     }
     i.UnlockBitmap();
     XYChart c = new XYChart(b.Width + 60, b.Height + 60);
     c.setPlotArea(40, 40, b.Width - 20, b.Height - 20);
     c.addTitle("Pixel Luminance for Vertical Scan Line " + col.ToString(),
         "Arial Bold", 10).setBackground(
         Chart.metalColor(0x9999ff), -1, 1);
     c.addLineLayer(luminance);
     c.xAxis().setLabels(lbls);
     return c.makeImage() as Bitmap;
 }*/
 public static void GenerateExcelFile(Bitmap b)
 {
     ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);
     string fileName = "output.txt";
     int f = 0;
     using (StreamWriter sw = new StreamWriter(fileName, false))
     {
         sw.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}", "Index", "Row", "Column", "Red",
             "Green", "Blue", "Gray");
         for (int column = 0; column < i.Bitmap.Width; column++)
         {
             for (int row = 0; row < i.Bitmap.Height; row++)
             {
                 f++;
                 Color c = i.GetPixel(column, row);
                 int g = i.GetGreyPixel(column, row);
                 sw.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}", f,
                     row, column, c.R, c.G, c.B, g);
             }
         }
     }
     i.UnlockBitmap();
     System.Diagnostics.Process.Start(fileName);
 }
Beispiel #23
0
        private void button6_Click(object sender, EventArgs e)
        {
            var bmp = pictureBox1.Image as Bitmap;

            using (var img = new ImagerBitmap(bmp))
            {
                for (int x = 0; x < img.Width; x++)
                    for (int y = 0; y < img.Height; y++)
                    {
                       if (y <= Height/3)
                        {
                            Color newColor = Color.FromArgb(255,255,255);
                            img.SetPixel(x, y, newColor);
                        }

                        else if (y <= 2 * Height / 3 && y >= Height / 3)
                        {
                            Color newColor = Color.FromArgb(0, 0, 255);
                            img.SetPixel(x, y, newColor);
                        }

                        else if (y >= 2 * Height / 3)
                        {
                            Color newColor = Color.FromArgb(255, 0, 0);
                            img.SetPixel(x, y, newColor);
                        }
                    }

                pictureBox1.Image = img.Bitmap;
            }
        }
Beispiel #24
0
 public static Bitmap LaplaceGreyscale(Bitmap b)
 {
     ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);
     ImagerBitmap i2 = new ImagerBitmap(b.Clone() as Bitmap);
     for (int column = 1; column < i.Bitmap.Width - 1; column++)
     {
         for (int row = 1; row < i.Bitmap.Height - 1; row++)
         {
             int[,] c = i.GetGrey3x3(row, column);
             int val = (((c[0, 0] + c[0, 1] + c[0, 2] + c[1, 0] + c[1, 2] + c[2, 0] + c[2, 1]
                 + c[2, 2]) * -1) + (c[1, 1] * 8)) + 128;
             if (val >= 128) val = 0; else val = 255;
             i2.SetPixel(column, row, Color.FromArgb(val, val, val));
         }
     }
     i.UnlockBitmap();
     i2.UnlockBitmap();
     return i2.Bitmap.Clone() as Bitmap;
 }
Beispiel #25
0
        private void button6_Click(object sender, EventArgs e)
        {
            var bmp = pictureBox1.Image as Bitmap;

            using(var img = new ImagerBitmap(bmp))
            {
                for (int x = 0; x < img.Width; x++)
                    for (int y = 0; y < img.Height; y++)
                    {
                        var px = img.GetPixel(x, y);
                        var n = (px.R + px.G + px.B)/6;
                        Color newColor = Color.FromArgb(n, n, px.B);
                        img.SetPixel(x,y,newColor);
                    }

                pictureBox1.Image = img.Bitmap;
            }
        }
Beispiel #26
0
        /// <summary>
        /// Make the image black and white
        /// </summary>
        /// <param name="b">Image to Process</param>
        /// <returns>Filtered Image</returns>
        public static Bitmap GetBlackAndWhiteBitmap(Bitmap b)
        {
            ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);

            double[] histogram = new double[256];
            for (int column = 0; column < i.Bitmap.Width; column++)
            {
                for (int row = 0; row < i.Bitmap.Height; row++)
                {
                    histogram[i.GetGreyPixel(column, row)]++;
                }
            }
            //find the position of the max value on the left
            int leftK = 0;

            for (int k = 0; k < 128; k++)
            {
                if (histogram[k] > histogram[leftK])
                {
                    leftK = k;
                }
            }
            //find the position of the max value on the right
            int rightK = 0;

            for (int k = 128; k < 256; k++)
            {
                if (histogram[k] > histogram[rightK])
                {
                    rightK = k;
                }
            }
            //find the min value between the 2 local maxes
            int localMin = rightK;

            for (int k = leftK; k < rightK; k++)
            {
                if (histogram[k] < histogram[localMin])
                {
                    localMin = k;
                }
            }
            for (int column = 0; column < i.Bitmap.Width; column++)
            {
                for (int row = 0; row < i.Bitmap.Height; row++)
                {
                    int val = (i.GetPixel(column, row).R + i.GetPixel(column, row).G
                               + i.GetPixel(column, row).B) / 3;
                    if (val > localMin)
                    {
                        val = 255;
                    }
                    else
                    {
                        val = 0;
                    }
                    i.SetPixel(column, row, Color.FromArgb(val, val, val));
                }
            }
            i.UnlockBitmap();
            return(i.Bitmap.Clone() as Bitmap);
        }
Beispiel #27
0
 /// <summary>
 /// Perform a Median fiter using a 5x5 Mask
 /// </summary>
 /// <param name="b">Image to Process</param>
 /// <returns>Filtered Image</returns>
 public static Bitmap Median5x5(Bitmap b)
 {
     ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);
     ImagerBitmap i2 = new ImagerBitmap(b.Clone() as Bitmap);
     for (int column = 2; column < i.Bitmap.Width - 2; column++)
     {
         for (int row = 2; row < i.Bitmap.Height - 2; row++)
         {
             Color[,] c = i.Get5x5(row, column);
             int red = Median(c[0, 0].R, c[0, 1].R, c[0, 2].R, c[0, 3].R, c[0, 4].R, c[1, 0].R,
                 c[1, 1].R, c[1, 2].R, c[1, 3].R, c[1, 4].R, c[2, 0].R, c[2, 1].R, c[2, 2].R,
                 c[2, 3].R, c[2, 4].R, c[3, 0].R, c[3, 1].R, c[3, 2].R, c[3, 3].R, c[3, 4].R,
                 c[4, 0].R, c[4, 1].R, c[4, 2].R, c[4, 3].R, c[4, 4].R);
             int green = Median(c[0, 0].G, c[0, 1].G, c[0, 2].G, c[0, 3].G, c[0, 4].G, c[1, 0].G,
                 c[1, 1].G, c[1, 2].G, c[1, 3].G, c[1, 4].G, c[2, 0].G, c[2, 1].G, c[2, 2].G,
                 c[2, 3].G, c[2, 4].G, c[3, 0].G, c[3, 1].G, c[3, 2].G, c[3, 3].G, c[3, 4].G,
                 c[4, 0].G, c[4, 1].G, c[4, 2].G, c[4, 3].G, c[4, 4].G);
             int blue = Median(c[0, 0].B, c[0, 1].B, c[0, 2].B, c[0, 3].B, c[0, 4].B, c[1, 0].B,
                 c[1, 1].B, c[1, 2].B, c[1, 3].B, c[1, 4].B, c[2, 0].B, c[2, 1].B, c[2, 2].B,
                 c[2, 3].B, c[2, 4].B, c[3, 0].B, c[3, 1].B, c[3, 2].B, c[3, 3].B, c[3, 4].B,
                 c[4, 0].B, c[4, 1].B, c[4, 2].B, c[4, 3].B, c[4, 4].B);
             i2.SetPixel(column, row, Color.FromArgb(red, green, blue));
         }
     }
     i.UnlockBitmap();
     i2.UnlockBitmap();
     return i2.Bitmap.Clone() as Bitmap;
 }
Beispiel #28
0
        /// <summary>
        /// Subtract b2 from b1 and normalize the image
        /// </summary>
        /// <param name="b1">Image</param>
        /// <param name="b2">Image</param>
        /// <returns>Normalized Image</returns>
        public static Bitmap Subtract(Bitmap b1, Bitmap b2)
        {
            if (b1.Width != b2.Width || b1.Height != b2.Height)
            {
                throw new Exception("Images not the same size cannot subtract");
            }
            ImagerBitmap i  = new ImagerBitmap(b1.Clone() as Bitmap);
            ImagerBitmap i2 = new ImagerBitmap(b2.Clone() as Bitmap);

            int[,] red   = new int[i.Bitmap.Width, i.Bitmap.Height];
            int[,] blue  = new int[i.Bitmap.Width, i.Bitmap.Height];
            int[,] green = new int[i.Bitmap.Width, i.Bitmap.Height];
            int redMax     = 0;
            int redMin     = 0;
            int redRange   = 0;
            int blueMax    = 0;
            int blueMin    = 0;
            int blueRange  = 0;
            int greenMax   = 0;
            int greenMin   = 0;
            int greenRange = 0;

            //fill the arrays with the subtracted values
            //Keep track of the min and max values for later
            for (int column = 0; column < i.Bitmap.Width; column++)
            {
                for (int row = 0; row < i.Bitmap.Height; row++)
                {
                    Color c1 = i.GetPixel(column, row);
                    Color c2 = i2.GetPixel(column, row);
                    red[column, row]   = c2.R - c1.R;
                    blue[column, row]  = c2.B - c1.B;
                    green[column, row] = c2.G - c1.G;
                    if (red[column, row] > redMax)
                    {
                        redMax = red[column, row];
                    }
                    if (red[column, row] < redMin)
                    {
                        redMin = red[column, row];
                    }
                    if (blue[column, row] > blueMax)
                    {
                        blueMax = blue[column, row];
                    }
                    if (blue[column, row] < blueMin)
                    {
                        blueMin = blue[column, row];
                    }
                    if (green[column, row] > greenMax)
                    {
                        greenMax = green[column, row];
                    }
                    if (green[column, row] < greenMin)
                    {
                        greenMin = green[column, row];
                    }
                }
            }
            //find the range of the min an max
            redRange   = Math.Abs(redMax - redMin);
            blueRange  = Math.Abs(blueMax - blueMin);
            greenRange = Math.Abs(greenRange - greenMin);
            //Normalize the values in the arrays and load the result image
            for (int column = 0; column < i.Bitmap.Width; column++)
            {
                for (int row = 0; row < i.Bitmap.Height; row++)
                {
                    if (redRange != 0)
                    {
                        red[column, row] = 255 - (((redMax - red[column, row]) * 255) / redRange);
                    }
                    if (blueRange != 0)
                    {
                        blue[column, row] = 255 - (((blueMax - blue[column, row]) * 255) / blueRange);
                    }
                    if (greenRange != 0)
                    {
                        green[column, row] = 255 - (((greenMax - green[column, row]) * 255) / greenRange);
                    }
                    if (red[column, row] < 0)
                    {
                        red[column, row] = 0;
                    }
                    if (blue[column, row] < 0)
                    {
                        blue[column, row] = 0;
                    }
                    if (green[column, row] < 0)
                    {
                        green[column, row] = 0;
                    }
                    i2.SetPixel(column, row, Color.FromArgb(red[column, row], green[column, row],
                                                            blue[column, row]));
                }
            }
            i.UnlockBitmap();
            i2.UnlockBitmap();
            return(i2.Bitmap.Clone() as Bitmap);
        }
Beispiel #29
0
 public static Bitmap GetBlackAndWhiteBitmap2(Bitmap b)
 {
     ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);
     double[] histogram = new double[256];
     for (int column = 0; column < i.Bitmap.Width; column++)
     {
         for (int row = 0; row < i.Bitmap.Height; row++)
         {
             histogram[i.GetGreyPixel(column, row)]++;
         }
     }
     double k = b.Width * b.Height;
     double half = k / 2;
     int middle = 0;
     while (k > half)
     {
         k = k - histogram[middle];
         middle++;
     }
     for (int column = 0; column < i.Bitmap.Width; column++)
     {
         for (int row = 0; row < i.Bitmap.Height; row++)
         {
             int val = (i.GetPixel(column, row).R + i.GetPixel(column, row).G
                 + i.GetPixel(column, row).B) / 3;
             if (val > middle)
                 val = 255;
             else
                 val = 0;
             i.SetPixel(column, row, Color.FromArgb(val, val, val));
         }
     }
     i.UnlockBitmap();
     return i.Bitmap.Clone() as Bitmap;
 }
Beispiel #30
0
 /// <summary>
 /// Make the image black and white
 /// </summary>
 /// <param name="b">Image to Process</param>
 /// <returns>Filtered Image</returns>
 public static Bitmap GetBlackAndWhiteBitmap(Bitmap b)
 {
     ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);
     double[] histogram = new double[256];
     for (int column = 0; column < i.Bitmap.Width; column++)
     {
         for (int row = 0; row < i.Bitmap.Height; row++)
         {
             histogram[i.GetGreyPixel(column, row)]++;
         }
     }
     //find the position of the max value on the left
     int leftK = 0;
     for (int k = 0; k < 128; k++)
     {
         if (histogram[k] > histogram[leftK]) leftK = k;
     }
     //find the position of the max value on the right
     int rightK = 0;
     for (int k = 128; k < 256; k++)
     {
         if (histogram[k] > histogram[rightK]) rightK = k;
     }
     //find the min value between the 2 local maxes
     int localMin = rightK;
     for (int k = leftK; k < rightK; k++)
     {
         if (histogram[k] < histogram[localMin]) localMin = k;
     }
     for (int column = 0; column < i.Bitmap.Width; column++)
     {
         for (int row = 0; row < i.Bitmap.Height; row++)
         {
             int val = (i.GetPixel(column, row).R + i.GetPixel(column, row).G
                 + i.GetPixel(column, row).B) / 3;
             if (val > localMin)
                 val = 255;
             else
                 val = 0;
             i.SetPixel(column, row, Color.FromArgb(val, val, val));
         }
     }
     i.UnlockBitmap();
     return i.Bitmap.Clone() as Bitmap;
 }
Beispiel #31
0
 /// <summary>
 /// Perform laplace edge detection on the image
 /// </summary>
 /// <param name="b">Source Image</param>
 /// <returns>Edges</returns>
 public static Bitmap Laplace(Bitmap b)
 {
     ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);
     ImagerBitmap i2 = new ImagerBitmap(b.Clone() as Bitmap);
     for (int column = 1; column < i.Bitmap.Width - 1; column++)
     {
         for (int row = 1; row < i.Bitmap.Height - 1; row++)
         {
             Color[,] c = i.Get3x3(row, column);
             int red = (((c[0, 0].R + c[0, 1].R + c[0, 2].R + c[1, 0].R + c[1, 2].R + c[2, 0].R
                 + c[2, 1].R + c[2, 2].R) * -1) + (c[1, 1].R * 8)) + 128;
             int green = (((c[0, 0].G + c[0, 1].G + c[0, 2].G + c[1, 0].G + c[1, 2].G
                 + c[2, 0].G + c[2, 1].G + c[2, 2].G) * -1) + (c[1, 1].G * 8)) + 128;
             int blue = (((c[0, 0].B + c[0, 1].B + c[0, 2].B + c[1, 0].B + c[1, 2].B + c[2, 0].B
                 + c[2, 1].B + c[2, 2].B) * -1) + (c[1, 1].B * 8)) + 128;
             if (red >= 128) red = 0; else red = 255;
             if (green >= 128) green = 0; else green = 255;
             if (blue >= 128) blue = 0; else blue = 255;
             i2.SetPixel(column, row, Color.FromArgb(red, green, blue));
         }
     }
     i.UnlockBitmap();
     i2.UnlockBitmap();
     return i2.Bitmap.Clone() as Bitmap;
 }
Beispiel #32
0
        private void button6_Click(object sender, EventArgs e)
        {
            var bmp = pictureBox1.Image as Bitmap;

            Random rnd = new Random();

            using (var img = new ImagerBitmap(bmp))
            {
                for (int x = 0; x < img.Width; x++)
                    for (int y = 0; y < img.Height; y++)
                    {
                        var px = img.GetPixel(x,y);
                        var S = ((px.R * 0.16 + px.G * 0.6 + px.B * 0.24)/128-1)*((float)trackBar1.Value/5)+1;
                        img.SetPixel(x, y, Color.FromArgb(cl(px.R*S),cl(px.G*S),cl(px.B*S)));

                    }
                pictureBox1.Image = img.Bitmap;
            }
        }
Beispiel #33
0
        private void button6_Click(object sender, EventArgs e)
        {
            var bmp = pictureBox1.Image as Bitmap;

            using (var img = new ImagerBitmap(bmp))
            {
                var k = 0;
                var radius = 0;
                    if (img.Width <= img.Height)
                        radius = img.Width/2;
                    else
                        radius = img.Height/2;
                for (int x = 0; x < img.Width; x++)
                    for (int y = 0; y < img.Height; y++)
                        {
                            var px = img.GetPixel(x, y);
                            var intensity = px.R + px.B + px.G;
                            intensity /= 3;
                            Color newColor = Color.FromArgb(Math.Abs(px.R - intensity / 5), Math.Abs(px.G - intensity / 5), Math.Abs(px.B - intensity / 5));
                            img.SetPixel(x, y, newColor);
                            if ((Math.Pow(x - img.Width / 2, 2) + Math.Pow(y - img.Height / 2, 2)) >= Math.Pow(radius, 2))
                            {
                                Color newColor1 = Color.FromArgb(Math.Abs(px.G), Math.Abs(px.B), Math.Abs(px.R));
                                img.SetPixel(x, y, newColor1);
                            }

                        }
                 /*var radius = 0;
                 var k = 0;
                 if (img.Width <= img.Height)
                        radius = img.Width/2;
                 else
                        radius = img.Height/2;
                 {
                     for (int x = 0; x < img.Width; x++)
                         for (int y = 0; y < img.Height; y++)
                         {
                             var i = radius - 200;
                             var px = img.GetPixel(x, y);
                             var intensity = px.R + px.B + px.G;
                             intensity /= 3;

                             if (((x - img.Width / 2) ^ 2 + (y - img.Height / 2) ^ 2) >= (i ^ 2))
                             {
                                 //Color newColor1 = Color.FromArgb(Math.Abs(px.R - intensity / (256 - i)), Math.Abs(px.G - intensity / (256 - i)), Math.Abs(px.B - intensity / (256 - i)));
                                 Color newColor1 = Color.FromArgb(255, 255, 255);
                                 img.SetPixel(x, y, newColor1);
                             }
                         }
                 }
                 //for (int i = radius - 200; i <= radius; i++ )*/

                     pictureBox1.Image = img.Bitmap;
            }
        }
Beispiel #34
0
 /// <summary>
 /// Perform a Binomial filter using a 5x5 Mask
 /// </summary>
 /// <param name="b">Image to Process</param>
 /// <returns>Filtered Image</returns>
 public static Bitmap Binomial5x5(Bitmap b)
 {
     ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);
     ImagerBitmap i2 = new ImagerBitmap(b.Clone() as Bitmap);
     for (int column = 2; column < i.Bitmap.Width - 2; column++)
     {
         for (int row = 2; row < i.Bitmap.Height - 2; row++)
         {
             Color[,] c = i.Get5x5(row, column);
             int red = ((c[0, 0].R * 1) + (c[0, 1].R * 4) + (c[0, 2].R * 6) + (c[0, 3].R * 4)
                 + (c[0, 4].R * 1) + (c[1, 0].R * 4) + (c[1, 1].R * 16) + (c[1, 2].R * 24)
                 + (c[1, 3].R * 16) + (c[1, 4].R * 4) + (c[2, 0].R * 6) + (c[2, 1].R * 24)
                 + (c[2, 2].R * 36) + (c[2, 3].R * 24) + (c[2, 4].R * 6) + (c[3, 0].R * 4)
                 + (c[3, 1].R * 16) + (c[3, 2].R * 24) + (c[3, 3].R * 16) + (c[3, 4].R * 4)
                 + (c[4, 0].R * 1) + (c[4, 1].R * 4) + (c[4, 2].R * 6) + (c[4, 3].R * 4)
                 + (c[4, 4].R * 1)) / 256;
             int green = ((c[0, 0].G * 1) + (c[0, 1].G * 4) + (c[0, 2].G * 6) + (c[0, 3].G * 4)
                 + (c[0, 4].G * 1) + (c[1, 0].G * 4) + (c[1, 1].G * 16) + (c[1, 2].G * 24)
                 + (c[1, 3].G * 16) + (c[1, 4].G * 4) + (c[2, 0].G * 6) + (c[2, 1].G * 24)
                 + (c[2, 2].G * 36) + (c[2, 3].G * 24) + (c[2, 4].G * 6) + (c[3, 0].G * 4)
                 + (c[3, 1].G * 16) + (c[3, 2].G * 24) + (c[3, 3].G * 16) + (c[3, 4].G * 4)
                 + (c[4, 0].G * 1) + (c[4, 1].G * 4) + (c[4, 2].G * 6) + (c[4, 3].G * 4)
                 + (c[4, 4].G * 1)) / 256;
             int blue = ((c[0, 0].B * 1) + (c[0, 1].B * 4) + (c[0, 2].B * 6) + (c[0, 3].B * 4)
                 + (c[0, 4].B * 1) + (c[1, 0].B * 4) + (c[1, 1].B * 16) + (c[1, 2].B * 24)
                 + (c[1, 3].B * 16) + (c[1, 4].B * 4) + (c[2, 0].B * 6) + (c[2, 1].B * 24)
                 + (c[2, 2].B * 36) + (c[2, 3].B * 24) + (c[2, 4].B * 6) + (c[3, 0].B * 4)
                 + (c[3, 1].B * 16) + (c[3, 2].B * 24) + (c[3, 3].B * 16) + (c[3, 4].B * 4)
                 + (c[4, 0].B * 1) + (c[4, 1].B * 4) + (c[4, 2].B * 6) + (c[4, 3].B * 4)
                 + (c[4, 4].B * 1)) / 256;
             i2.SetPixel(column, row, Color.FromArgb(red, green, blue));
         }
     }
     i.UnlockBitmap();
     i2.UnlockBitmap();
     return i2.Bitmap.Clone() as Bitmap;
 }
Beispiel #35
0
        private void buttonNew_Click(object sender, EventArgs e)
        {
            var bmp = pictureBox1.Image as Bitmap;
            var dst = bmp.Clone() as Bitmap;
            using (var img = new ImagerBitmap(bmp))
            using (var imgDst = new ImagerBitmap(dst))
            {
                for (int x = 0; x < img.Width; x++)
                    for (int y = 0; y < img.Height; y++)
                    {
                        var px = img.GetPixel(x, y);
                        var sepia = (px.G + px.R+px.B)/3;
                        if (x < 7 || x > img.Width - 7 || y < 7 || y > img.Height-7)
                        {
                            imgDst.SetPixel(x, y, Color.DarkSeaGreen);
                        }
                        else
                        {
                            Color newColor = Color.FromArgb(25,sepia, sepia/2, sepia/6);
                            imgDst.SetPixel(x, y, newColor);
                        }

                    }

                pictureBox1.Image = imgDst.Bitmap;
            }
        }
Beispiel #36
0
        private void button6_Click(object sender, EventArgs e)
        {
            var bmp = pictureBox1.Image as Bitmap;
            var dst = bmp.Clone() as Bitmap;

            using (var img = new ImagerBitmap(bmp))
            {
                for (int x = 0; x < img.Width; x++)
                    for (int y = 0; y < img.Height; y++)
                    {
                        var px = img.GetPixel(x, y);

                       var intensity = px.G + px.R + px.B;
                       Color newColor;
                       if (intensity >= 383)
                         newColor = Color.FromArgb(255, 255, 255);
                       else
                         newColor = Color.FromArgb(0, 0, 0);

                     img.SetPixel(x, y, newColor);
                    }

                pictureBox1.Image = img.Bitmap;
            }
        }
Beispiel #37
0
        private void New2_Click(object sender, EventArgs e)
        {
            int n = 0;
            var bmp = pictureBox1.Image as Bitmap;
            var dst = bmp.Clone() as Bitmap;
            using (var img = new ImagerBitmap(bmp))
            using (var imgDst = new ImagerBitmap(dst))
            {
                Random rand=new Random();
                for (int x = 3; x < imgDst.Width-3; x++)
                    for (int y = 3; y < imgDst.Height-3; y++)
                    {
                        var px = img.GetPixel(x, y);
                        if (rand.Next(200) == 100)
                        {

                                imgDst.SetPixel(x, y - 2, Color.White);
                                imgDst.SetPixel(x, y - 3, Color.White);
                                imgDst.SetPixel(x, y - 1, Color.White);
                                imgDst.SetPixel(x - 3, y, Color.White);
                                imgDst.SetPixel(x - 2, y, Color.White);
                                imgDst.SetPixel(x - 1, y, Color.White);
                                imgDst.SetPixel(x, y, Color.White);
                                imgDst.SetPixel(x + 1, y, Color.White);
                                imgDst.SetPixel(x + 2, y, Color.White);
                                imgDst.SetPixel(x + 3, y, Color.White);
                                imgDst.SetPixel(x, y + 1, Color.White);
                                imgDst.SetPixel(x, y + 2, Color.White);
                                imgDst.SetPixel(x, y + 3, Color.White);
                                imgDst.SetPixel(x+1, y+1, Color.White);
                                imgDst.SetPixel(x+2, y+2, Color.White);
                                imgDst.SetPixel(x-1, y-1, Color.White);
                                imgDst.SetPixel(x-2, y-2, Color.White);
                                imgDst.SetPixel(x-1, y+1, Color.White);
                                imgDst.SetPixel(x-2, y+2, Color.White);
                                imgDst.SetPixel(x+1, y-1, Color.White);
                                imgDst.SetPixel(x+2, y-2, Color.White);
                                x = x + 3;
                                y = y + 3;

                        }
                    }

                pictureBox1.Image = imgDst.Bitmap;
            }
        }
Beispiel #38
0
 private void button6_Click(object sender, EventArgs e)
 {
     var bmp = pictureBox1.Image as Bitmap;
        // var image = new ImagerBitmap(bmp);
     using (var image = new ImagerBitmap(bmp))
     { for (int i=0;i<image.Height;i++)
         for (int j = 0; j < image.Width; j++)
         {
             Color color = image.GetPixel(j, i);
             Color newcolor = Color.FromArgb(255 - color.R, 255 - color.G, 255 - color.B);
             image.SetPixel(j,i,newcolor);
         }
     pictureBox1.Image = image.Bitmap;
     }
 }
Beispiel #39
0
 /// <summary>
 /// Perform a Bionomial filter using a 3x3 Mask
 /// </summary>
 /// <param name="b">Image to Process</param>
 /// <returns>Filtered Image</returns>
 public static Bitmap Binomial3x3(Bitmap b)
 {
     ImagerBitmap i = new ImagerBitmap(b.Clone() as Bitmap);
     ImagerBitmap i2 = new ImagerBitmap(b.Clone() as Bitmap);
     for (int column = 1; column < i.Bitmap.Width - 1; column++)
     {
         for (int row = 1; row < i.Bitmap.Height - 1; row++)
         {
             Color[,] c = i.Get3x3(row, column);
             int red = ((c[0, 0].R * 1) + (c[0, 1].R * 2) + (c[0, 2].R * 1) + (c[1, 0].R * 2)
                 + (c[1, 1].R * 4) + (c[1, 2].R * 2) + (c[2, 0].R * 1) + (c[2, 1].R * 2)
                 + (c[2, 2].R * 1)) / 16;
             int green = ((c[0, 0].G * 1) + (c[0, 1].G * 2) + (c[0, 2].G * 1) + (c[1, 0].G * 2)
                 + (c[1, 1].G * 4) + (c[1, 2].G * 2) + (c[2, 0].G * 1) + (c[2, 1].G * 2)
                 + (c[2, 2].G * 1)) / 16;
             int blue = ((c[0, 0].B * 1) + (c[0, 1].B * 2) + (c[0, 2].B * 1) + (c[1, 0].B * 2)
                 + (c[1, 1].B * 4) + (c[1, 2].B * 2) + (c[2, 0].B * 1) + (c[2, 1].B * 2)
                 + (c[2, 2].B * 1)) / 16;
             i2.SetPixel(column, row, Color.FromArgb(red, green, blue));
         }
     }
     i.UnlockBitmap();
     i2.UnlockBitmap();
     return i2.Bitmap.Clone() as Bitmap;
 }