You are here: Start » AVL.NET » Adaptive Vision Library .NET Usage » Blob Analysis Example

Blob Analysis Example

Following example thresholds a loaded image into the region with ThresholdToRegion function and then splits it into blobs with SplitRegionIntoBlobs function. Blobs, that don't met specific area condition, are bounded with red circle. Circles, determined with RegionBoundingCircle function are drawn with DrawCircle function. The region area is calculated using RegionArea function.

To have the example work, a single form with PictureBox control and a mounts.jpg file located in the application directory are needed.

//...
using AvlNet;
    //...

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            Inspect();
        }

        private void Inspect()
        {
            using (var mountsImage = new Image())
            using (var mountsRegion = new Region())
            using (var mounts = new SafeList<Region>())
            {
                AVL.LoadImage("mounts.jpg", false, mountsImage);
                AVL.ThresholdToRegion(mountsImage, null, null, 128.0f, 0.0f, mountsRegion);
                AVL.SplitRegionIntoBlobs(mountsRegion, RegionConnectivity.FourDirections, 1, false, mounts);

                //display invalid mounts
                DrawingStyle style = new DrawingStyle()
                {
                    Thickness = 2.0f,
                    DrawingMode = DrawingMode.HighQuality,
                    Opacity = 1.0f
                };

                Pixel red = new Pixel(255.0f, 0.0f, 0.0f, 0.0f);
                foreach (Region mount in mounts)
                {
                    int area;
                    AVL.RegionArea(mount, out area);
                    if (area < 2000)
                    {
                        Circle2D circle;
                        AVL.RegionBoundingCircle(mount, out circle);
                        AVL.DrawCircle(mountsImage, circle, red, style);
                    }
                }

                if (pictureBox1.Image != null)
                    pictureBox1.Image.Dispose();

                pictureBox1.Image = mountsImage.CreateBitmap();
            }
        }
        //...
    }
Previous: Basic Template Matching Next: AvlNet Designers example