Reputation: 27575
I have zebra-striped images where each fringe is to be considered a blob for further processing, but which also contains blobs that should not be considered. I am using AForge.NET / C# / VisualStudio2010. A typical example would be this:
The plan is to do this:
I have this code, which successfully isolate only the fringes crossing the reference vertical line:
using AForge.Imaging;
using AForge.Imaging.Filters;
Bitmap threshold_binary = gimme_threshold_image();
var blob_counter = new BlobCounter();
blob_counter.ProcessImage(threshold_binary);
var blobs = blob_counter.GetObjects(threshold_binary, true);
int midline_x_coord = threshold_binary.Width/2;
int counter = 1;
foreach (var blob in blobs)
{
// This saves an image for each blob (white fringe) which crosses the vertical reference line,
// but the fringes are not sorted vertically!
if (blob.Rectangle.X < midline_x_coord & (blob.Rectangle.X + blob.Rectangle.Width) > midline_x_coord) {
blob_counter.ExtractBlobsImage(threshold_grayscale, blob, true);
var blobimage = blob.Image.ToManagedImage();
blobimage.Save(String.Format("{0}singlefringes/{1}_singlefringe.png", base_input_dir, counter));
counter++;
}
}
Since the block above doesn't return sorted fringes, another approach would be to scan the midline vertically, pixel by pixel, identifying the ordered blobs, but I'm having difficulty figuring out how to do it. A proposition would be something like this:
for (int y = 0; y < threshold_binary.Height; y++) {
if (threshold_binary.GetPixel(midline_x_coord, y)) {
// somehow create a List of blobs or blob indexes,
// but only if I can find out which blob
// this pixel is in (brute-force would be ugly, right?)
}
}
Thanks for any suggestion!
Upvotes: 1
Views: 1325
Reputation: 11
you can sort by vertically by chossing how you want to get the blobs by area or size or x or y (you have to chose y) take it :
BlobCounter bc = new BlobCounter();
bc.ObjectsOrder = ObjectsOrder.YX;
Upvotes: 1