コード例 #1
0
        public static void GaussFilter(ByteImage btm, double a, double[,] wages)
        {
            ByteImage tempPict = new ByteImage(btm);

            for (int x = 0; x < tempPict.Width; x++)
            {
                for (int y = 0; y < tempPict.Height; y++)
                {
                    var    currPix = tempPict.Pixels[tempPict.getPixelIndex(x, y)];
                    double sumR    = 0.0;
                    double sumG    = 0.0;
                    double sumB    = 0.0;
                    double dividor = 0.0;
                    for (int x2 = -1; x2 < 2; x2++)
                    {
                        for (int y2 = -1; y2 < 2; y2++)
                        {
                            if (x + x2 >= 0 && y + y2 >= 0 && x + x2 < tempPict.Width && y + y2 < tempPict.Height)
                            {
                                double currWage = wages[x2 + 1, y2 + 1];
                                var    xx       = x + x2;
                                var    yy       = y + y2;
                                sumR    += tempPict.Pixels[tempPict.getPixelIndex(xx, yy) + 1] * currWage;
                                sumG    += tempPict.Pixels[tempPict.getPixelIndex(xx, yy) + 2] * currWage;
                                sumB    += tempPict.Pixels[tempPict.getPixelIndex(xx, yy) + 3] * currWage;
                                dividor += currWage;
                            }
                        }
                    }
                    btm.setPixel(x, y, currPix, (byte)FromInterval((int)(sumR / dividor)), (byte)FromInterval((int)(sumG / dividor)), (byte)FromInterval((int)(sumB / dividor)));
                }
            }
        }
コード例 #2
0
        public static void IrisContrast(ByteImage newBmpTbl)
        {
            PrimitiveContrast pc = new PrimitiveContrast(0, 255, 185, 0);

            for (int x = 0; x < newBmpTbl.Width; x++)
            {
                for (int y = 0; y < newBmpTbl.Height; y++)
                {
                    newBmpTbl.setPixel(x, y, pc.GetColor(newBmpTbl.getPixel(x, y)));
                }
            }
        }
コード例 #3
0
        public static void Contrast(ByteImage btm)
        {
            PrimitiveContrast pc = new PrimitiveContrast(30, 255, 255, 0);

            for (int x = 0; x < btm.Width; x++)
            {
                for (int y = 0; y < btm.Height; y++)
                {
                    btm.setPixel(x, y, pc.GetColor(btm.getPixel(x, y)));
                }
            }
        }
コード例 #4
0
        internal static void DrawInnerCircle(ByteImage originalBitmapTbl, Tuple <int, int, int> pupCenter)
        {
            int x = pupCenter.Item1;
            int y = pupCenter.Item2;
            int r = pupCenter.Item3;

            try
            {
                originalBitmapTbl.setPixel(x, y, 255, 255, 0, 0);
                originalBitmapTbl.setPixel(x + 1, y, 255, 255, 0, 0);
                originalBitmapTbl.setPixel(x - 1, y, 255, 255, 0, 0);
                originalBitmapTbl.setPixel(x, y + 1, 255, 255, 0, 0);
                originalBitmapTbl.setPixel(x, y - 1, 255, 255, 0, 0);

                for (int t = 0; t < 360; t++)
                {
                    var a = (int)(x - (r * Math.Cos(t * Math.PI / 180)));
                    var b = (int)(y - (r * Math.Sin(t * Math.PI / 180)));
                    if (a >= 0 && b >= 0 && a < originalBitmapTbl.Width && b < originalBitmapTbl.Height)
                    {
                        try
                        {
                            originalBitmapTbl.setPixel(a, b, 255, 0, 0, 255);
                        }
                        catch (Exception e) { };
                    }
                }
            }
            catch (Exception ex) { }
        }
コード例 #5
0
 public static void GrayScale(ByteImage btm)
 {
     for (int x = 0; x < btm.Width; x++)
     {
         for (int y = 0; y < btm.Height; y++)
         {
             byte[] oldColour;
             oldColour = btm.getPixel(x, y);
             var value = (0.2 * (double)oldColour[1]) + (0.7 * (double)oldColour[2]) + (0.1 * (double)oldColour[3]);
             btm.setPixel(x, y, oldColour[0], (byte)value, (byte)value, (byte)value);
         }
     }
 }
コード例 #6
0
 public static void CuttOffIris(ByteImage btm, Tuple <System.Drawing.Point, int> pupil, Tuple <System.Drawing.Point, int> iris)
 {
     for (int x = 0; x < btm.Width; x++)
     {
         for (int y = 0; y < btm.Height; y++)
         {
             if (IsInsideCircle(pupil, x, y) || !IsInsideCircle(iris, x, y))
             {
                 btm.setPixel(x, y, 255, 255, 255, 255);
             }
         }
     }
 }
コード例 #7
0
        public static void RemoveSingleNoises(ByteImage btm)
        {
            ByteImage tempPict = new ByteImage(btm);
            int       counter  = 0;

            for (int x = 0; x < btm.Width; x++)
            {
                for (int y = 0; y < btm.Height; y++)
                {
                    var oldColour = btm.getPixel(x, y);
                    if (oldColour[1] == 0)
                    {
                        bool isAlone = true;

                        for (int x2 = -1; x2 <= 1; x2++)
                        {
                            for (int y2 = -1; y2 <= 1; y2++)
                            {
                                if (x + x2 >= 0 && x + x2 < btm.Width && y + y2 >= 0 && y + y2 < btm.Height)
                                {
                                    var col = btm.Pixels[btm.getPixelIndex(x + x2, y + y2) + 1];
                                    if (col == 0)
                                    {
                                        isAlone = false;
                                        break;
                                    }
                                }
                            }
                        }

                        if (isAlone)
                        {
                            tempPict.setPixel(x, y, 255, 0, 0, 0);
                        }
                    }
                }
            }
            Console.WriteLine(counter + " pixels removed");
            for (int x = 0; x < btm.Width; x++)
            {
                for (int y = 0; y < btm.Height; y++)
                {
                    btm.setPixel(x, y, tempPict.getPixel(x, y));
                }
            }
        }
コード例 #8
0
        public static void RunFullBlack(ByteImage newBmpTbl)
        {
            int bigCounter = 3;

            while (bigCounter > 2)
            {
                ByteImage tempPict = new ByteImage(newBmpTbl);
                bigCounter = 0;
                for (int x = 0; x < newBmpTbl.Width; x++)
                {
                    for (int y = 0; y < newBmpTbl.Height; y++)
                    {
                        int counter = 0;
                        for (int x2 = -1; x2 < 2; x2++)
                        {
                            for (int y2 = -1; y2 < 2; y2++)
                            {
                                if (newBmpTbl.Pixels[newBmpTbl.getPixelIndex(x, y) + 1] != 0 && x + x2 >= 0 && y + y2 >= 0 && x + x2 < newBmpTbl.Width && y + y2 < newBmpTbl.Height && newBmpTbl.Pixels[newBmpTbl.getPixelIndex(x + x2, y + y2) + 1] <= (255 / 6))
                                {
                                    counter++;
                                }
                            }
                        }
                        if (counter >= 5)
                        {
                            tempPict.setPixel(x, y, 255, 0, 0, 0);
                            bigCounter++;
                        }
                    }
                }
                Console.WriteLine("Blacked " + bigCounter + " pixels.");
                for (int x = 0; x < newBmpTbl.Width; x++)
                {
                    for (int y = 0; y < newBmpTbl.Height; y++)
                    {
                        newBmpTbl.setPixel(x, y, tempPict.getPixel(x, y));
                    }
                }
            }
        }
コード例 #9
0
        public static int ThreeColors(ByteImage newBmpTbl)
        {
            int borderColor = 255;
            int threads     = 8;

            ByteImage[]         pictures = new ByteImage[threads];
            ConcurrentBag <int> mins     = new ConcurrentBag <int>();
            ConcurrentBag <int> maxs     = new ConcurrentBag <int>();
            ConcurrentBag <int> sums     = new ConcurrentBag <int>();
            ConcurrentBag <int> counters = new ConcurrentBag <int>();

            for (int i = 0; i < threads; i++)
            {
                pictures[i] = new ByteImage(newBmpTbl);
            }


            Parallel.For(0, threads, i =>
                         //for (int i = 0; i < threads; i++)
            {
                int min     = 255;
                int max     = 0;
                int totSum  = 0;
                int counter = 0;
                int w       = (int)pictures[i].Width / threads;

                for (int x = i * w; x < (i + 1) * w; x++)
                {
                    for (int y = 0; y < pictures[i].Height; y++)
                    {
                        var col = pictures[i].getPixel(x, y)[1];
                        if (col > max)
                        {
                            max = col;
                        }
                        if (col < min)
                        {
                            min = col;
                        }
                        if (col <= 215)
                        {
                            totSum += col;
                            counter++;
                        }
                    }
                }
                mins.Add(min);
                maxs.Add(max);
                sums.Add(totSum);
                counters.Add(counter);
            });
            //}

            int fmin  = mins.Min();
            int fmax  = maxs.Max();
            int fmid  = sums.Sum() / counters.Sum();
            int fmid1 = (fmid + fmin) / 2;
            int fmid2 = (fmax + fmid) / 2;

            borderColor = fmid2;

            for (int x = 0; x < newBmpTbl.Width; x++)
            {
                for (int y = 0; y < newBmpTbl.Height; y++)
                {
                    var col = newBmpTbl.Pixels[newBmpTbl.getPixelIndex(x, y) + 1];

                    int distMin  = Math.Abs(col - fmin);
                    int distMid1 = Math.Abs(col - fmid1);
                    int distMid2 = Math.Abs(col - fmid2);
                    int distMax  = Math.Abs(col - fmax);

                    int minV = Math.Min(distMin, Math.Min(distMid1, Math.Min(distMid2, distMax)));
                    if (minV == distMin)
                    {
                        newBmpTbl.setPixel(x, y, 255, 0, 0, 0);
                    }
                    else if (minV == distMid1)
                    {
                        newBmpTbl.setPixel(x, y, 255, (byte)fmid2, (byte)fmid2, (byte)fmid2);
                    }
                    else if (minV == distMid2)
                    {
                        newBmpTbl.setPixel(x, y, 255, (byte)fmid2, (byte)fmid2, (byte)fmid2);
                    }
                    else
                    {
                        newBmpTbl.setPixel(x, y, 255, 255, 255, 255);
                    }
                }
            }
            return(borderColor);
        }