示例#1
0
        public int GetAvarageSpermArea(Bitmap bitmap)
        {
            var blobFinder = new BlobFinder(provider);
            var deviation  = blobFinder.FindAreaDeviation(bitmap);

            return((int)deviation.Median);
        }
示例#2
0
        public IEnumerable <Sperm> Discover(Bitmap image)
        {
            var classificator           = new SpermClassificator();
            var blobFinder              = new BlobFinder(provider);
            var blobs                   = blobFinder.FindBlobsByArea(image);
            GrahamConvexHull grahamScan = new GrahamConvexHull();

            foreach (var blob in blobs)
            {
                List <IntPoint> leftEdge   = new List <IntPoint>();
                List <IntPoint> rightEdge  = new List <IntPoint>();
                List <IntPoint> topEdge    = new List <IntPoint>();
                List <IntPoint> bottomEdge = new List <IntPoint>();

                // collect edge points
                blobFinder.BlobCounter.GetBlobsLeftAndRightEdges(blob, out leftEdge, out rightEdge);
                blobFinder.BlobCounter.GetBlobsTopAndBottomEdges(blob, out topEdge, out bottomEdge);

                // find convex hull
                List <IntPoint> edgePoints = new List <IntPoint>();
                edgePoints.AddRange(leftEdge);
                edgePoints.AddRange(rightEdge);

                List <IntPoint> hull = grahamScan.FindHull(edgePoints);

                var points = hull.Select(x => new Point(x.X, x.Y)).ToList();
                var center = new Point(blob.CenterOfGravity.X, blob.CenterOfGravity.Y);
                blobFinder.BlobCounter.ExtractBlobsImage(image, blob, false);
                var blobBitmap = blob.Image.ToManagedImage(true);
                var spermType  = classificator.Classify(blobBitmap);
                yield return(new Sperm(points, center, spermType));
            }
        }
示例#3
0
        private void FilterMinimumDensityandRatio()
        {
            List <Blob> tmpBlobs;
            Blob        tmpBlob;

            tmpBlobs        = new List <Blob>();
            pBlue.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;

            //FIRST FILTERS OF PROPORTIONS FOR SQUARED BLOBS
            for (int i = 0; i < BlobFinder.Count; i++)
            {
                tmpBlob = BlobFinder.Blobs[i];

                if (tmpBlob.Density < 0.25)
                {
                    continue;
                }

                if (tmpBlob.Ratio < 0.15)
                {
                    continue;
                }

                tmpBlobs.Add(tmpBlob);
            }

            BlobFinder.Clear();
            BlobFinder.Blobs.AddRange(tmpBlobs.OrderBy(b => b.Centroid2Origin).ToList());
        }
示例#4
0
        private List <Triangle> FindTriangles()
        {
            Blob            one, two;
            double          distance;
            List <Triangle> triangles;
            List <Blob>     tmpBlobs;

            triangles = new List <Triangle>();
            tmpBlobs  = new List <Blob>();
            Triangle triangle;

            for (int index = 0; index < BlobFinder.Count; index++)
            {
                one      = BlobFinder.Blobs[index];
                triangle = new Triangle(one, Color.Red);
                tmpBlobs.Add(one);

                for (int next = index + 1; next < BlobFinder.Count; next++)
                {
                    two = BlobFinder.Blobs[next];

                    distance = Distance(one.Centroid, two.Centroid);

                    if ((distance / ((one.AvgSize + two.AvgSize) / 2)) > 10)//works
                    {
                        next = BlobFinder.Count;
                        BlobFinder.Remove(one);
                        tmpBlobs.Remove(one);
                        index--;
                    }
                    else
                    {
                        tmpBlobs.Add(two);
                        triangle.points.Add(two);
                        BlobFinder.Remove(two);
                        next--;
                        if (triangle.points.Count > 2)
                        {
                            triangles.Add(triangle);
                            next = BlobFinder.Count;
                        }
                    }
                }
            }

            BlobFinder.Clear();
            BlobFinder.Blobs.AddRange(tmpBlobs.ToList());

            return(triangles);
        }
示例#5
0
        private IEnumerable <Rectangle> GetRectangles(IAddressableImage image)
        {
            var blobFinder = new BlobFinder();

            var sw = new Stopwatch();

            sw.Start();
            var rectangles = blobFinder.From(image);

            sw.Stop();
            TimeToFindLetter = sw.Elapsed;

            return(rectangles);
        }
示例#6
0
        public Detect(BackPropNeuralNet bnn)
        {
            InitializeComponent();

            DoubleBuffered = true;
            Dock           = DockStyle.Fill;

            blobFinder = new BlobFinder();
            this.bnn   = bnn;


            this.panel1.Paint     += new PaintEventHandler(this.panel1_Paint);
            this.panel1.MouseDown += new MouseEventHandler(this.panel1_MouseDown);
            this.panel1.MouseMove += new MouseEventHandler(this.panel1_MouseMove);
            this.panel1.MouseUp   += new MouseEventHandler(this.panel1_MouseUp);
        }
示例#7
0
        /// <summary>
        /// The constructor of the QR finde, which starts by
        /// scaling the input image and binarizes the image using
        /// the integral image in adaptative threshold
        /// </summary>
        /// <param name="image">input image to analize</param>
        /// <param name="scale">an option to tell the software if we want to scale the input</param>
        /// <param name="maskSize">size of the adaptative threshold window</param>
        public QRFinder(Bitmap image, SCALARS scale, int maskSize)
        {
            names  = (KnownColor[])Enum.GetValues(typeof(KnownColor));
            random = new Random();
            switch (scale)
            {
            case SCALARS.NONE:
                bmp = image;
                break;

            case SCALARS.SCALE:
                bmp = ImgTools.Scale(image, 640, 480);
                break;
            }

            bmp = IAdaptative.Execute(bmp, maskSize);
            BlobFinder.Execute(bmp);
        }
示例#8
0
        public void Able_To_Find_Two_Rectangle()
        {
            int[,] imageData = new int[10, 10]
            {
                { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
                { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
                { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
                { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
            };

            var finder = new BlobFinder();

            var rectangles = finder.From(new TestImage(imageData));

            Assert.True(rectangles.Count() == 2);
            Assert.NotEmpty(rectangles);
        }
示例#9
0
        private void FindBlobPairs()
        {
            List <Blob> tmpBlobs;
            float       maxR, minR;
            Blob        one, two, tmp;
            Point       p1, p2, p3, p4, midAB, midAC;

            tmpBlobs = new List <Blob>();
            maxR     = 0;
            minR     = 1000;

            //FINDS PAIRS OF BLOBS ONE INSIDE ANOTHER WITH CLOSE CENTROIDS
            for (int index = 0; index < BlobFinder.Count - 1; index++)
            {
                one = BlobFinder.Blobs[index];

                for (int t = index + 1; t < BlobFinder.Count; t++)
                {
                    two = BlobFinder.Blobs[t];

                    if (Math.Abs(one.Centroid2Origin - two.Centroid2Origin) > one.Diagonal / 3)
                    {
                        t = BlobFinder.Count;
                        BlobFinder.Blobs.Remove(one);
                        index--;
                        continue;
                    }//*/

                    if (one.Width < two.Width)
                    {
                        tmp = one;
                        one = two;
                        two = tmp;
                    }

                    midAB = MidPoint(one.A, one.B);
                    midAC = MidPoint(one.A, one.C);

                    p1 = MidPoint(one.A, midAB);
                    p2 = MidPoint(midAB, one.B);

                    p3 = MidPoint(one.A, midAC);
                    p4 = MidPoint(midAC, one.C);

                    if (
                        (two.Centroid.X > p1.X) && (two.Centroid.X < p2.X) &&
                        (two.Centroid.Y > p3.Y) && (two.Centroid.Y < p4.Y) &&
                        (one.Density / two.Density) < 1.3 && (two.Density / one.Density) > 1 &&
                        (one.Width / two.Width) > 1.5 && (one.Width / two.Width) < 3.5
                        )
                    {
                        tmpBlobs.Add(two);

                        if (two.Ratio > maxR)
                        {
                            maxR = two.Ratio;
                        }

                        if (two.Ratio < minR)
                        {
                            minR = two.Ratio;
                        }

                        BlobFinder.Blobs.Remove(one);
                        BlobFinder.Blobs.Remove(two);

                        index--;
                        t = BlobFinder.Count;
                    }
                    else
                    {
                        one = BlobFinder.Blobs[index];
                    }
                }
            }

            BlobFinder.Clear();
            BlobFinder.Blobs.AddRange(tmpBlobs.OrderBy(b => b.Centroid2Origin).ToList());
        }