Beispiel #1
0
 public static double[] Histogram(DevImage img)
 {
     double[] histogram = new double[64];
     img.LockBitmap();
     for (int y = 0; y < img.Width; y++)
     {
         for (int x = 0; x < img.Height; x++)
         {
             histogram[Pixel.GetRGBHistogramValue(y, x, img)]++;
         }
     }
     img.UnlockBitmap();
     return histogram;
 }
Beispiel #2
0
 public static double[] GreyscaleHistogram(DevImage img)
 {
     double[] histogram = new double[256];
     img.LockBitmap();
     for (int y = 0; y < img.Width; y++)
     {
         for (int x = 0; x < img.Height; x++)
         {
             histogram[img.GetGreyPixel(y, x)]++;
         }
     }
     img.UnlockBitmap();
     return histogram;
 }
Beispiel #3
0
 public static Bitmap Median3x3(DevImage img)
 {
     Bitmap bmp = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb);
     img.LockBitmap();
     for (int y = 1; y < img.Width - 1; y++)
     {
         for (int x = 1; x < img.Height - 1; x++)
         {
             Color[,] c = Pixel.Get3x3(x, y,img);
             int red = Median(c[0, 0].R, c[0, 1].R, c[0, 2].R, c[1, 0].R, c[1, 1].R, c[1, 2].R,
                              c[2, 0].R, c[2, 1].R, c[2, 2].R);
             int green = Median(c[0, 0].G, c[0, 1].G, c[0, 2].G, c[1, 0].G, c[1, 1].G,
                                c[1, 2].G, c[2, 0].G, c[2, 1].G, c[2, 2].G);
             int blue = Median(c[0, 0].B, c[0, 1].B, c[0, 2].B, c[1, 0].B, c[1, 1].B, c[1, 2].B,
                               c[2, 0].B, c[2, 1].B, c[2, 2].B);
             bmp.SetPixel(y, x, Color.FromArgb(red, green, blue));
         }
     }
     img.UnlockBitmap();
     return bmp;
 }
Beispiel #4
0
 public static Bitmap LaplaceGreyscale(DevImage img)
 {
     Bitmap bmp = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb);
     img.LockBitmap();
     for (int y = 1; y < img.Width - 1; y++)
     {
         for (int x = 1; x < img.Height - 1; x++)
         {
             int[,] c = Pixel.GetGrey3x3(x, y,img);
             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;
             bmp.SetPixel(y, x, Color.FromArgb(val, val, val));
         }
     }
     img.UnlockBitmap();
     return bmp;
 }
Beispiel #5
0
 public static Bitmap Laplace(DevImage img)
 {
     Bitmap bmp = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb);
     img.LockBitmap();
     for (int y = 1; y < img.Width - 1; y++)
     {
         for (int x = 1; x < img.Height - 1; x++)
         {
             Color[,] c = Pixel.Get3x3(x, y,img);
             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;
             bmp.SetPixel(y, x, Color.FromArgb(red, green, blue));
         }
     }
     img.UnlockBitmap();
     return bmp;
 }
Beispiel #6
0
        public bool CopyImg(Int32 offX, Int32 offY, DevImage image)
        {
            //*
            if(image == null) return false;
            if((image.Width  > m_width - offX) && (image.Height > m_height - offY)) return false;

            LockBitmap();
            image.LockBitmap();

            byte[] val = new byte[4];

            for (int i = 0; i < image.Height; i++)
            {
                for (int j = 0; j < image.m_width; j++)
                {
                    val[0] = image.GetPixel(j, i).A;
                    val[1] = image.GetPixel(j, i).R;
                    val[2] = image.GetPixel(j, i).G;
                    val[3] = image.GetPixel(j, i).B;
                    SetPixel(offX + j, offY + i, val);
                }
            }

            image.UnlockBitmap();
            UnlockBitmap();
            return true;
            /**/

            //Bitmap bmp = new Bitmap(image.Width, image.Height, PixelFormat.Format24bppRgb);
            //Graphics g = Graphics.FromImage(bmp);

            //g.DrawImage(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height,
            //                    GraphicsUnit.Pixel);
            //g.Dispose();
            //return true;
        }
Beispiel #7
0
        public static Bitmap SplitImage(DevImage image, Rectangle rect)
        {
            Bitmap destBmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb);

            image.LockBitmap();
            BitmapData destData = destBmp.LockBits(new Rectangle(0, 0, destBmp.Width, destBmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

            byte* pDest = (byte*)destData.Scan0;
            int offset = destData.Stride - destBmp.Width * 4;
            for (int y = 0; y < destBmp.Height; ++y)
            {
                for (int x = 0; x < destBmp.Width; ++x)
                {
                    Color color = image.GetPixel(x + rect.Left, y + rect.Top);
                    *(pDest++) = color.R;
                    *(pDest++) = color.G;
                    *(pDest++) = color.B;
                    *(pDest++) = color.A;
                }
                pDest += offset;
            }

            image.UnlockBitmap();
            destBmp.UnlockBits(destData);
            return destBmp;
        }