1
我有斑馬條紋的圖像,其中每個邊緣被認爲是進一步處理的斑點,但也包含不應該被考慮的斑點。我正在使用AForge.NET/C#/ VisualStudio2010。一個典型的例子是這樣的:如何使用AForge.NET BlobCounter垂直排序Blob?
該計劃是做到這一點:
- 選擇一些X座標限定垂直線;
- 取每個穿過這條垂直線的白色斑點;
- 輸出應該是一個blob或blob索引列表VERTICALLY SORTED VERTICALLY(這是必須的),以便白色邊緣將從高到低排序。
我有此代碼,它成功地僅分離條紋交叉的參考線垂直:
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?)
}
}
謝謝你的任何建議!