Beispiel #1
0
        public static Bitmap filterColor(Bitmap _b, Color _c, Color _t, Color _mark)   // gradation diff
        {
            Bitmap  result           = copy(_b);
            XBitmap framedImage_xbmp = new XBitmap(result);

            for (int i = 0; i < result.Width; i++)
            {
                for (int j = 0; j < result.Height; j++)
                {
                    Color px           = framedImage_xbmp.getPixel(i, j);
                    bool  isWarnaKulit = (px.R > _c.R - _t.R && px.R < _c.R + _t.R) && (px.G > _c.G - _t.G && px.G < _c.G + _t.G) && (px.B > _c.B - _t.B && px.B < _c.B + _t.B);
                    int   maxdr        = isWarnaKulit ? _mark.R : 0;
                    int   maxdg        = isWarnaKulit ? _mark.G : 0;
                    int   maxdb        = isWarnaKulit ? _mark.B : 0;
                    if (isWarnaKulit)
                    {
                        framedImage_xbmp.setPixel(i, j, _mark);
                    }
                    else
                    {
                        framedImage_xbmp.setPixel(i, j, Color.FromArgb(0, 0, 0));
                    }
                }
            }
            return(framedImage_xbmp.getBitmap());
        }
Beispiel #2
0
        public static Bitmap RectangleMorph(Bitmap _b, Point _E, Point _F, Point _G, Point _H)   // gradation diff
        {
            Point   E           = new Point(_b.Width * _E.X, _b.Height * _E.Y);
            Point   F           = new Point(_b.Width * _F.X, _b.Height * _F.Y);
            Point   G           = new Point(_b.Width * _G.X, _b.Height * _G.Y);
            Point   H           = new Point(_b.Width * _H.X, _b.Height * _H.Y);
            int     res_w       = Math.Max(F.X - E.X, G.X - H.X);
            int     res_h       = Math.Max(H.Y - E.Y, G.Y - F.Y);
            Bitmap  result      = new Bitmap(res_w, res_h);
            XBitmap result_xbmp = new XBitmap(result);

            for (int i = 0; i < result.Width; i++)
            {
                for (int j = 0; j < result.Height; j++)
                {
                    int   new_width  = j * ((G.X - H.X) - (F.X - E.X)) / H.Y - E.Y + F.X - E.X;
                    int   new_height = i * ((G.Y - F.Y) - (H.Y - E.Y)) / F.X - E.X + H.Y - E.Y;
                    int   x1         = i * _b.Width / new_width;
                    int   y1         = j * _b.Height / new_height;
                    Color px         = (y1 >= _b.Height || x1 >= _b.Width || y1 < 0 || x1 < 0) ? Color.FromArgb(0, 0, 0) : _b.GetPixel(x1, y1);
                    result_xbmp.setPixel(i, j, px);
                }
            }
            return(result_xbmp.getBitmap());
        }
 public static Bitmap zhangsuen(Bitmap _b)
 {
     Bitmap framedImage = addFrame(_b, latar);
     XBitmap framedImage_xbmp = new XBitmap(framedImage);
     List<System.Drawing.Point> pointsToChange = new List<System.Drawing.Point>();
     int a, b; int p2 = 0; int p4 = 0; int p6 = 0; int p8 = 0;
     bool notSkeleton = true;
     while (notSkeleton)
     {
         notSkeleton = false;
         for (int i = 1; i < _b.Height + 1; i++)
         {
             for (int j = 1; j < _b.Width + 1; j++)
             {
                 if (isNotLatar(framedImage_xbmp, j, i))
                 {
                     a = getA(framedImage_xbmp, j, i);
                     b = getB(framedImage_xbmp, j, i, ref p2, ref p4, ref p6, ref p8);
                     if (2 <= b && b <= 6 && a == 1 && (p2 * p4 * p6 == 0) && (p4 * p6 * p8 == 0))
                     {
                         pointsToChange.Add(new System.Drawing.Point(j, i));
                         notSkeleton = true;
                     }
                 }
             }
         }
         foreach (System.Drawing.Point point in pointsToChange)
         {
             framedImage_xbmp.setPixel(point.X, point.Y, latar);
         }
         pointsToChange.Clear();
         for (int i = 1; i < _b.Height + 1; i++)
         {
             for (int j = 1; j < _b.Width + 1; j++)
             {
                 if (isNotLatar(framedImage_xbmp, j, i))
                 {
                     a = getA(framedImage_xbmp, j, i);
                     b = getB(framedImage_xbmp, j, i, ref p2, ref p4, ref p6, ref p8);
                     if (2 <= b && b <= 6 && a == 1 && (p2 * p4 * p8 == 0) && (p2 * p6 * p8 == 0))
                     {
                         pointsToChange.Add(new System.Drawing.Point(j, i));
                         notSkeleton = true;
                     }
                 }
             }
         }
         foreach (System.Drawing.Point point in pointsToChange)
         {
             framedImage_xbmp.setPixel(point.X, point.Y, latar);
         }
         pointsToChange.Clear();
     }
     return XImage.removeFrame(framedImage_xbmp.getBitmap());
 }
 public static Bitmap RectangleMorph(Bitmap _b, System.Drawing.Point _E, System.Drawing.Point _F, System.Drawing.Point _G, System.Drawing.Point _H)
 {
     // gradation diff
     System.Drawing.Point E = new System.Drawing.Point(_b.Width * _E.X, _b.Height * _E.Y);
     System.Drawing.Point F = new System.Drawing.Point(_b.Width * _F.X, _b.Height * _F.Y);
     System.Drawing.Point G = new System.Drawing.Point(_b.Width * _G.X, _b.Height * _G.Y);
     System.Drawing.Point H = new System.Drawing.Point(_b.Width * _H.X, _b.Height * _H.Y);
     int res_w = Math.Max(F.X - E.X, G.X - H.X);
     int res_h = Math.Max(H.Y - E.Y, G.Y - F.Y);
     Bitmap result = new Bitmap(res_w, res_h);
     XBitmap result_xbmp = new XBitmap(result);
     for (int i = 0; i < result.Width; i++)
     {
         for (int j = 0; j < result.Height; j++)
         {
             int new_width = j * ((G.X - H.X) - (F.X - E.X)) / H.Y - E.Y + F.X - E.X;
             int new_height = i * ((G.Y - F.Y) - (H.Y - E.Y)) / F.X - E.X + H.Y - E.Y;
             int x1 = i * _b.Width / new_width;
             int y1 = j * _b.Height / new_height;
             Color px = (y1 >= _b.Height || x1 >= _b.Width || y1 < 0 || x1 < 0) ? Color.FromArgb(0, 0, 0) : _b.GetPixel(x1, y1);
             result_xbmp.setPixel(i, j, px);
         }
     }
     return (result_xbmp.getBitmap());
 }
Beispiel #5
0
 public static Bitmap filterColor(Bitmap _b, Color _c, Color _t, Color _mark)
 {
     // gradation diff
     Bitmap result = copy(_b);
     XBitmap framedImage_xbmp = new XBitmap(result);
     for (int i = 0; i < result.Width; i++) {
         for (int j = 0; j < result.Height; j++) {
             Color px = framedImage_xbmp.getPixel(i, j);
             bool isWarnaKulit = (px.R>_c.R-_t.R && px.R<_c.R+_t.R) && (px.G>_c.G-_t.G && px.G<_c.G+_t.G) && (px.B>_c.B-_t.B && px.B<_c.B+_t.B);
             int maxdr = isWarnaKulit ? _mark.R : 0;
             int maxdg = isWarnaKulit ? _mark.G : 0;
             int maxdb = isWarnaKulit ? _mark.B : 0;
             if (isWarnaKulit)
                 framedImage_xbmp.setPixel(i, j, _mark);
             else
                 framedImage_xbmp.setPixel(i, j, Color.FromArgb(0,0,0));
         }
     }
     return (framedImage_xbmp.getBitmap());
 }