Пример #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());
        }
Пример #2
0
        private static double dotProduct(XBitmap _bmp, double[,] _convmatrix, int i, int j) // putar matrix 45 drj, 8x jadi kembali ke asal, untuk derajat 2
        {
            double res = (double)_bmp.getPixel(i - 1, j - 1).R *_convmatrix[0, 0] +
                         (double)_bmp.getPixel(i - 1, j).R *_convmatrix[0, 1] +
                         (double)_bmp.getPixel(i - 1, j + 1).R *_convmatrix[0, 2] +
                         (double)_bmp.getPixel(i, j - 1).R *_convmatrix[1, 0] +
                         (double)_bmp.getPixel(i, j).R *_convmatrix[1, 1] +
                         (double)_bmp.getPixel(i, j + 1).R *_convmatrix[1, 2] +
                         (double)_bmp.getPixel(i + 1, j - 1).R *_convmatrix[2, 0] +
                         (double)_bmp.getPixel(i + 1, j).R *_convmatrix[2, 1] +
                         (double)_bmp.getPixel(i + 1, j + 1).R *_convmatrix[2, 2];

            return(res);
        }
Пример #3
0
        public static Bitmap edgeDiff2(Bitmap _b)   // inversi warna
        {
            Bitmap  result           = copy(_b);
            Bitmap  framedImage      = addMirroredFrame(_b);
            XBitmap framedImage_xbmp = new XBitmap(framedImage);

            for (int i = 1; i < framedImage.Width - 1; i++)
            {
                for (int j = 1; j < framedImage.Height - 1; j++)
                {
                    Color dc1   = XColor.differrence(framedImage_xbmp.getPixel(i, j - 1), framedImage_xbmp.getPixel(i, j + 1));
                    Color dc2   = XColor.differrence(framedImage_xbmp.getPixel(i + 1, j), framedImage_xbmp.getPixel(i - 1, j));
                    int   maxdr = Math.Max(dc1.R, dc2.R);
                    int   maxdg = Math.Max(dc1.G, dc2.G);
                    int   maxdb = Math.Max(dc1.B, dc2.B);
                    result.SetPixel(i - 1, j - 1, Color.FromArgb(maxdr, maxdr, maxdb));
                }
            }
            return(result);
        }
Пример #4
0
        public static Bitmap grad2(Bitmap _b, int _radius, Color _mark, int _distance)   // gradation diff
        //Bitmap result = XImage.copy(_b);
        {
            int     r                 = _radius;
            int     r2                = _distance / 2 + 1;
            int     limit             = (int)(Math.Pow((2 * r + 1), 2) * (0.3));
            Bitmap  framedImage       = addNFrame(_b, Color.FromArgb(0, 0, 0), r);
            XBitmap xbmp_framedImage  = new XBitmap(framedImage);
            Bitmap  result            = XImage.getPlainImage(_b, Color.Black);
            Bitmap  framedResultImage = addNFrame(_b, Color.FromArgb(0, 0, 0), r2);

            for (int i = 0; i < result.Width; i += _distance)
            {
                for (int j = 0; j < result.Height; j += _distance)
                {
                    int x     = i + r;
                    int y     = j + r;
                    int count = 0;
                    for (int k = x - r; k < x + r; k++)
                    {
                        for (int l = y - r; l < y + r; l++)
                        {
                            Color px = xbmp_framedImage.getPixel(k, l);
                            count += (px.R != 0) ? 1 : 0;
                        }
                    }
                    if (count >= limit)
                    {
                        int d = _distance / 2;
                        for (int k = i - d; k <= i + d; k++)
                        {
                            for (int l = j - d; l <= j + d; l++)
                            {
                                framedResultImage.SetPixel(k + r2, l + r2, _mark);
                            }
                        }/**/
                         //framedResultImage.SetPixel(i + r2, j + r2, _mark);
                    }
                }
            }/**/
            return(XImage.removeNFrame(framedResultImage, r2));
        }
Пример #5
0
        public static Bitmap gradDiff4(Bitmap _b)   // gradation diff
        {
            Bitmap  result           = copy(_b);
            Bitmap  framedImage      = addMirroredFrame(_b);
            XBitmap framedImage_xbmp = new XBitmap(framedImage);

            for (int i = 1; i < framedImage.Width - 1; i++)
            {
                for (int j = 1; j < framedImage.Height - 1; j++)
                {
                    Color px           = framedImage_xbmp.getPixel(i, j);
                    int   thres        = 21;
                    bool  isWarnaKulit = (px.R > 102 - thres && px.R < 102 + thres) && (px.G > 107 - thres && px.G < 107 + thres) && (px.B > 95 - thres && px.B < 95 + thres);
                    int   maxdr        = isWarnaKulit ? 255 : 0;
                    int   maxdg        = isWarnaKulit ? 255 : 0;
                    int   maxdb        = isWarnaKulit ? 255 : 0;
                    result.SetPixel(i - 1, j - 1, Color.FromArgb(maxdr, maxdr, maxdb));
                }
            }
            return(result);
        }
 private static bool isLatar(XBitmap _b, int i, int j)
 {
     Color temp = _b.getPixel(i, j);
     return XColor.isEqual(temp, latar);
 }
Пример #7
0
 // putar matrix 45 drj, 8x jadi kembali ke asal, untuk derajat 2
 private static double dotProduct(XBitmap _bmp, double[,] _convmatrix, int i, int j)
 {
     double res = (double)_bmp.getPixel(i - 1, j - 1).R * _convmatrix[0, 0] +
                 (double)_bmp.getPixel(i - 1, j).R * _convmatrix[0, 1] +
                 (double)_bmp.getPixel(i - 1, j + 1).R * _convmatrix[0, 2] +
                 (double)_bmp.getPixel(i, j - 1).R * _convmatrix[1, 0] +
                 (double)_bmp.getPixel(i, j).R * _convmatrix[1, 1] +
                 (double)_bmp.getPixel(i, j + 1).R * _convmatrix[1, 2] +
                 (double)_bmp.getPixel(i + 1, j - 1).R * _convmatrix[2, 0] +
                 (double)_bmp.getPixel(i + 1, j).R * _convmatrix[2, 1] +
                 (double)_bmp.getPixel(i + 1, j + 1).R * _convmatrix[2, 2];
     return res;
 }
Пример #8
0
 public static Bitmap gradDiff4(Bitmap _b)
 {
     // gradation diff
     Bitmap result = copy(_b);
     Bitmap framedImage = addMirroredFrame(_b);
     XBitmap framedImage_xbmp = new XBitmap(framedImage);
     for (int i = 1; i < framedImage.Width-1; i++) {
         for (int j = 1; j < framedImage.Height-1; j++) {
             Color px = framedImage_xbmp.getPixel(i, j);
             int thres = 21;
             bool isWarnaKulit = (px.R>102-thres && px.R<102+thres) && (px.G>107-thres && px.G<107+thres) && (px.B>95-thres && px.B<95+thres);
             int maxdr = isWarnaKulit ? 255 : 0;
             int maxdg = isWarnaKulit ? 255 : 0;
             int maxdb = isWarnaKulit ? 255 : 0;
             result.SetPixel(i-1, j-1, Color.FromArgb(maxdr, maxdr, maxdb));
         }
     }
     return result;
 }
Пример #9
0
 public static Bitmap grad2(Bitmap _b, int _radius, Color _mark, int _distance)
 {
     // gradation diff
     //Bitmap result = XImage.copy(_b);
     int r = _radius;
     int r2 = _distance/2+1;
     int limit = (int)(Math.Pow((2*r+1), 2)*(0.3));
     Bitmap framedImage = addNFrame(_b, Color.FromArgb(0, 0, 0), r);
     XBitmap xbmp_framedImage = new XBitmap(framedImage);
     Bitmap result = XImage.getPlainImage(_b, Color.Black);
     Bitmap framedResultImage = addNFrame(_b, Color.FromArgb(0, 0, 0), r2);
     for (int i = 0; i < result.Width; i+=_distance) {
         for (int j = 0; j < result.Height; j+=_distance) {
             int x = i+r;
             int y = j+r;
             int count = 0;
             for (int k = x-r; k < x+r; k++) {
                 for (int l = y-r; l < y+r; l++) {
                     Color px = xbmp_framedImage.getPixel(k, l);
                     count += (px.R!=0) ? 1 : 0;
                 }
             }
             if (count>=limit) {
                 int d = _distance/2;
                 for (int k = i-d; k <= i+d; k++) {
                     for (int l = j-d; l <= j+d; l++) {
                         framedResultImage.SetPixel(k + r2, l + r2, _mark);
                     }
                 }/**/
                 //framedResultImage.SetPixel(i + r2, j + r2, _mark);
             }
         }
     }/**/
     return XImage.removeNFrame(framedResultImage, r2);
 }
Пример #10
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());
 }
Пример #11
0
 public static Bitmap edgeDiff4(Bitmap _b)
 {
     // inversi warna
     Bitmap result = copy(_b);
     Bitmap framedImage = addMirroredFrame(_b);
     XBitmap framedImage_xbmp = new XBitmap(framedImage);
     for (int i = 1; i < framedImage.Width-1; i++) {
         for (int j = 1; j < framedImage.Height-1; j++) {
             Color dc1 = XColor.differrence(framedImage_xbmp.getPixel(i, j - 1), framedImage_xbmp.getPixel(i, j + 1));
             Color dc2 = XColor.differrence(framedImage_xbmp.getPixel(i + 1, j - 1), framedImage_xbmp.getPixel(i - 1, j + 1));
             Color dc3 = XColor.differrence(framedImage_xbmp.getPixel(i + 1, j), framedImage_xbmp.getPixel(i - 1, j));
             Color dc4 = XColor.differrence(framedImage_xbmp.getPixel(i + 1, j + 1), framedImage_xbmp.getPixel(i - 1, j - 1));
             int maxdr = Math.Max(dc1.R, Math.Max(dc2.R, Math.Max(dc3.R, dc4.R)));
             int maxdg = Math.Max(dc1.G, Math.Max(dc2.G, Math.Max(dc3.G, dc4.G)));
             int maxdb = Math.Max(dc1.B, Math.Max(dc2.B, Math.Max(dc3.B, dc4.B)));
             result.SetPixel(i-1, j-1, Color.FromArgb(maxdr, maxdr, maxdb));
         }
     }
     return result;
 }