AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

Blob circularity

The forum is to discuss topics related to different areas of image processing and computer vision.

Blob circularity

Postby Stevenh » Fri Aug 01, 2014 12:42 pm

Hi fellow AForge enjoyers,

To analyze an image, I am using the AForge.NET library. It gives amazing results accept for one: the circularity of a blob.
Is there a way to get the circularity or the perimeter of a blob? Having one will allow me to calculate the other using the area.

Lets have some more info:
An example of an image that I have to analyze (in low resolution):
B5.png
B5.png (44.29 KiB) Viewed 13097 times

The steps I take to get the blobs:
- Define area of interest
- apply a threshold
- invert colors
- extract blobs:
Code: Select all
BlobCounter bc = new BlobCounter();
bc.FilterBlobs = false;
bc.ObjectsOrder = ObjectsOrder.Area;
try
{
    bc.ProcessImage(image);
    Blob[] blobs = bc.GetObjectsInformation();
}
catch { }


Thanks in advance,
Steven
Stevenh
 
Posts: 2
Joined: Fri Aug 01, 2014 12:18 pm

Re: Blob circularity

Postby andrew.kirillov » Fri Aug 01, 2014 9:29 pm

Hello,

There is no blob circularity property for now. How about simple shape detector?
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Blob circularity

Postby Stevenh » Wed Aug 06, 2014 8:46 am

Thanks for your quick response Andrew!

For anyone ever reading this for a solution, I tried to get as close as possible to get to the circularity:

Code: Select all
BlobCounter bc = new BlobCounter();
bc.FilterBlobs = false;
bc.ObjectsOrder = ObjectsOrder.Area; //Descending order
bc.ProcessImage(inImage);
Blob[] blobs = bc.GetObjectsInformation();
foreach (Blob b in blobs)
{
    double perimeter = 0.0;
    List<AForge.IntPoint> edgePoints = bc.GetBlobsEdgePoints(b);
    Point[] points = sortPoints(edgePoints, b.CenterOfGravity).ToArray();
    points = getBezierPoints(points);
    for (int i = 0; i < points.Length; i++)
    {
        if (i + 1 < points.Length)
        {
            double xdiff = Math.Abs(points[i].X - points[i + 1].X);
            double ydiff = Math.Abs(points[i].Y - points[i + 1].Y);
            perimeter += (float)Math.Sqrt(Math.Pow(xdiff, 2) + Math.Pow(ydiff, 2));
        }
    }

    float circularity = (float)((4 * Math.PI * b.Area) / (Math.Pow(perimeter, 2)));
    if (circularity > 1)
    {
        if (circularity >= 2)
            circularity = 0;
        else
            circularity = 1 + (1 - circularity);
        }
    }

    //Use your own functions here to maybe store some of the blob information in a new list.


What's happening in the function GetBezierPoints can be found here.
Stevenh
 
Posts: 2
Joined: Fri Aug 01, 2014 12:18 pm

Re: Blob circularity

Postby floyd » Sat Jun 24, 2017 8:17 am

Sir,

I have encountered an issue while using the below code. Can you please provide some information for 'sortPoints' which will help me to build the code without any errors.

Requesting you to reply as soon as possible.

Thanking you
Floyd

BlobCounter bc = new BlobCounter();
bc.FilterBlobs = false;
bc.ObjectsOrder = ObjectsOrder.Area; //Descending order
bc.ProcessImage(inImage);
Blob[] blobs = bc.GetObjectsInformation();
foreach (Blob b in blobs)
{
double perimeter = 0.0;
List<AForge.IntPoint> edgePoints = bc.GetBlobsEdgePoints(b);
Point[] points = sortPoints(edgePoints, b.CenterOfGravity).ToArray();
points = getBezierPoints(points);
for (int i = 0; i < points.Length; i++)
{
if (i + 1 < points.Length)
{
double xdiff = Math.Abs(points[i].X - points[i + 1].X);
double ydiff = Math.Abs(points[i].Y - points[i + 1].Y);
perimeter += (float)Math.Sqrt(Math.Pow(xdiff, 2) + Math.Pow(ydiff, 2));
}
}

float circularity = (float)((4 * Math.PI * b.Area) / (Math.Pow(perimeter, 2)));
if (circularity > 1)
{
if (circularity >= 2)
circularity = 0;
else
circularity = 1 + (1 - circularity);
}
}
floyd
 
Posts: 1
Joined: Sat Jun 24, 2017 8:10 am




Return to Image Processing and Computer Vision