'White blob detection
I'm trying to use AForge.NET to detect a thick white line across an Image.
It's like pipe that I get and is my desired result after applying a Threshold filter.
I know how to detect shapes and I'm doing that, already, but this doesn't match under any shape since it has no edges and isn't a circle.
I have sample code from detecting equilateral shapes, but I don't know if that's relevant.
public void DetectQuadrilateralType(Bitmap bitmap)
{
BlobCounter blobCounter = new BlobCounter();
blobCounter.ProcessImage(bitmap);
Blob[] blobs = blobCounter.GetObjectsInformation();
//Graphics object to draw
Pen pen;
Graphics g = Graphics.FromImage(bitmap);
SimpleShapeChecker shapeChecker = new SimpleShapeChecker();
for (int i = 0; i < blobs.Length; i++)
{
List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);
List<IntPoint> corners;
if (i < edgePoints.ToArray().Length && i > -1)
{
try
{
if (shapeChecker.IsConvexPolygon(edgePoints, out corners))
{
PolygonSubType subType = shapeChecker.CheckPolygonSubType(corners);
pen = new Pen(colors[subType], 2);
g.DrawPolygon(pen, ToPointsArray(corners));
pen.Dispose();
}
}
catch (Exception e) { }
}
}
g.Dispose();
}
Here's the image i'm trying to detect:
If anybody has any idea how I can detect that white blob with AForge or otherwise using C#/.NET i'd really appreciate it.
The code above only detects edges, so it'll only detect the shape if it has a sharp edge, which will rarely be the case.
EDIT
I sort of have it working with the following method
public void DetectBigBlobs(Bitmap bitmap)
{
BlobCounter blobCounter = new BlobCounter();
blobCounter.ProcessImage(bitmap);
Rectangle[] rects = blobCounter.GetObjectsRectangles();
//Graphics object to draw
Pen pen = new Pen(Color.Red, 2);
Graphics g = Graphics.FromImage(bitmap);
foreach (Rectangle rect in rects)
{
if (rect.Width > 200 && rect.Height > 150)
{
g.DrawRectangle(pen, rect);
}
}
pen.Dispose();
g.Dispose();
}
There must be a better way than using fixed widths (because they could vary greatly)
Solution 1:[1]
if you want to get a marked blob you can use this code
public void DetectBigBlobs(Bitmap bitmap)
{
BlobCounter blobCounter = new BlobCounter();
Graphics g = Graphics.FromImage(bitmap);
//filtering the blobs before searching for blobs
blobCounter.FilterBlobs = true;
blobCounter.MinHeight = bitmap.Height/3;
blobCounter.MinWidth = bitmap.Width/3;
blobCounter.ProcessImage(bitmap);
Blob[] blobs = blobCounter.GetObjectsInformation();
foreach (Blob b in blobs)
{
//getting the found blob edgepoints
List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(b);
//if you want to mark every edge point RED
foreach (IntPoint point in edgePoints)
bitmap.SetPixel(point.X, point.Y, Color.Red);
//if you want to draw a rectangle around the blob
g.DrawRectangle(Pens.Blue,b.Rectangle);
}
g.Dispose();
}
ask me if you want something differing i will help as much as i can :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ayad Kara Kâhya |