我有斑马条纹图像,其中每个条纹都被视为一个斑点以进行进一步处理,但其中也包含不应考虑的斑点。我正在使用 AForge.NET/C#/VisualStudio2010。一个典型的例子是:
计划是这样做的:
- 选择一些定义垂直线的 X 坐标;
- 取每个穿过这条垂直线的白色斑点;
- 输出应该是垂直排序的 blob 或 blob 索引列表(这是必要的),以便白边从高到低排序。
我有这段代码,它只成功地隔离了穿过参考垂直线的边缘:
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++;
}
}
由于上面的块不返回排序的边缘,另一种方法是垂直扫描中线,逐个像素,识别有序的斑点,但我很难弄清楚如何去做。一个命题是这样的:
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?)
}
}
感谢您的任何建议!