I have a problem with counting small objects on the image. In example I used BlobCounter class (from AForge framework). But it doesnt recognize splitted objects. Here is the function output
http://s3.postimg.org/cwkexxucj/result.jpg[
^]
Here is the treshold that method produces
http://s29.postimg.org/y0rze5ulj/treshold.jpg[
^]
Here is the code
private void count_Objects_Click(object sender, EventArgs e)
{
Bitmap sample = (Bitmap)picProcessed.Image.Clone();
Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);
Bitmap grayImage = filter.Apply(sample);
SISThreshold filterT = new SISThreshold();
filterT.ApplyInPlace(grayImage);
Invert filterInvert = new Invert();
filterInvert.ApplyInPlace(grayImage);
BlobCounter blobCounter = new BlobCounter();
blobCounter.FilterBlobs = true;
blobCounter.MinWidth = 2;
blobCounter.MinHeight = 2;
blobCounter.CoupledSizeFiltering = true;
blobCounter.ProcessImage(grayImage);
Blob[] blobs = blobCounter.GetObjectsInformation();
GrahamConvexHull hullFinder = new GrahamConvexHull();
Bitmap image = (Bitmap)picProcessed.Image;
Bitmap clonimage = (Bitmap)picProcessed.Image.Clone();
BitmapData data = clonimage.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadWrite, image.PixelFormat);
foreach (Blob blob in blobs)
{
List<IntPoint> leftPoints, rightPoints, edgePoints;
edgePoints = new List<IntPoint>();
blobCounter.GetBlobsLeftAndRightEdges(blob,
out leftPoints, out rightPoints);
edgePoints.AddRange(leftPoints);
edgePoints.AddRange(rightPoints);
List<IntPoint> hull = hullFinder.FindHull(edgePoints);
Drawing.Polygon(data, hull, Color.Black);
}
clonimage.UnlockBits(data);
picProcessed.Image = clonimage;
picProcessed.Refresh();
int count = blobs.Length;
MessageBox.Show("Total objects found: " + count);
}
1 First function process image to binary image for blobcount algorithm
2 Then it looks for blobs
3 Then it draws (on original image) borders around blobs
How to split blobs? Or maybe there is other methods for counting objects in image?