Example #1
0
        public static Dictionary <Point, MinutiaeType> DetectMinutiae(WriteableBitmap bitmap)
        {
            Dictionary <Point, MinutiaeType> points = new Dictionary <Point, MinutiaeType>();

            using (BitmapContext context = bitmap.GetBitmapContext())
            {
                int width  = context.Width;
                int height = context.Height;

                int[] mask = new int[9];


                for (int x = 1; x < width - 1; ++x)
                {
                    for (int y = 1; y < height - 1; ++y)
                    {
                        if (PixelHelper.IsBlack(context, x, y))
                        {
                            mask[0] = PixelHelper.IsWhite(context, x, y + 1) ? 0 : 1;
                            mask[1] = PixelHelper.IsWhite(context, x - 1, y + 1) ? 0 : 1;
                            mask[2] = PixelHelper.IsWhite(context, x - 1, y) ? 0 : 1;
                            mask[3] = PixelHelper.IsWhite(context, x - 1, y - 1) ? 0 : 1;
                            mask[4] = PixelHelper.IsWhite(context, x, y - 1) ? 0 : 1;
                            mask[5] = PixelHelper.IsWhite(context, x + 1, y - 1) ? 0 : 1;
                            mask[6] = PixelHelper.IsWhite(context, x + 1, y) ? 0 : 1;
                            mask[7] = PixelHelper.IsWhite(context, x + 1, y + 1) ? 0 : 1;
                            mask[8] = mask[0];


                            MinutiaeType cn = CalculateCN(mask);
                            if (IsMinutiae(cn))
                            {
                                points.Add(new Point(x, y), cn);

                                if (cn == MinutiaeType.Point)
                                {
                                    PixelHelper.SetPixel(context, x, y, Colors.Red);
                                }
                                else if (cn == MinutiaeType.Ending)
                                {
                                    PixelHelper.SetPixel(context, x, y, Colors.Green);
                                }
                                else if (cn == MinutiaeType.Fork)
                                {
                                    PixelHelper.SetPixel(context, x, y, Colors.Yellow);
                                }
                                else if (cn == MinutiaeType.Crossing)
                                {
                                    PixelHelper.SetPixel(context, x, y, Colors.DeepPink);
                                }
                            }
                        }
                    }
                }
            }

            return(points);
        }
        public static WriteableBitmap DilateAndErode(WriteableBitmap writeableBitmap, bool?[,] matrix3x3)
        {
            int width  = writeableBitmap.PixelWidth;
            int height = writeableBitmap.PixelHeight;

            WriteableBitmap newImage = writeableBitmap.Clone();

            using (BitmapContext newcontext = newImage.GetBitmapContext())
            {
                using (BitmapContext context = writeableBitmap.GetBitmapContext())
                {
                    for (int x = 0; x < width; ++x)
                    {
                        for (int y = 0; y < height; ++y)
                        {
                            bool exaclyMatch = true;

                            for (int i = 0; i < 3; ++i)
                            {
                                for (int j = 0; j < 3; ++j)
                                {
                                    bool?matVal = matrix3x3[i, j];
                                    int  cX     = x - 1 + i;
                                    int  cY     = y - 1 + j;

                                    if (cX > 0 && cY > 0 && cX < width && cY < height && matVal != null)
                                    {
                                        if (!(PixelHelper.IsBlack(context, cX, cY) == matVal))
                                        {
                                            exaclyMatch = false;
                                            goto ExitLoop;
                                        }
                                    }
                                }
                            }
ExitLoop:

                            if (exaclyMatch)
                            {
                                PixelHelper.SetBlack(newcontext, x, y);
                            }
                            else
                            {
                                PixelHelper.SetWhite(newcontext, x, y);
                            }
                        }
                    }
                }
            }
            return(newImage);
        }
Example #3
0
        private static int CalculateWeight(int i, int j, BitmapContext context)
        {
            int width  = context.Width;
            int height = context.Height;

            int[] N      = new int[] { 128, 1, 2, 64, 0, 4, 32, 16, 8 };
            int   weight = 0;

            if (i - 1 > 0)
            {
                if (j - 1 > 0 && PixelHelper.IsBlack(context, i - 1, j - 1))
                {
                    weight += N[0];
                }
                if (PixelHelper.IsBlack(context, i - 1, j))
                {
                    weight += N[3];
                }
                if (j + 1 < height && PixelHelper.IsBlack(context, i - 1, j + 1))
                {
                    weight += N[6];
                }
            }
            if (i + 1 < width)
            {
                if (j - 1 > 0 && PixelHelper.IsBlack(context, i + 1, j - 1))
                {
                    weight += N[2];
                }
                if (PixelHelper.IsBlack(context, i + 1, j))
                {
                    weight += N[5];
                }
                if (j + 1 < height && PixelHelper.IsBlack(context, i + 1, j + 1))
                {
                    weight += N[8];
                }
            }

            if (j - 1 > 0 && PixelHelper.IsBlack(context, i, j - 1))
            {
                weight += N[1];
            }
            if (j + 1 < height && PixelHelper.IsBlack(context, i, j + 1))
            {
                weight += N[7];
            }

            return(weight);
        }
Example #4
0
        private static int[,] PixelInfo(BitmapContext context)
        {
            int width  = context.Width;
            int height = context.Height;

            int[,] pixels = new int[width, height];
            for (int i = 0; i < width; ++i)
            {
                for (int j = 0; j < height; ++j)
                {
                    if (PixelHelper.IsBlack(context, i, j))
                    {
                        pixels[i, j] = 1;
                    }
                    else
                    {
                        pixels[i, j] = 0;
                    }
                }
            }
            return(pixels);
        }