我有一个图像,我做了一些处理,以便将背景与前景分开,创建一个二进制(黑/白)图像。
使用 AForge,我能够从处理后的图像中检测所有斑点,并返回它们。
因此,我获取原始图像,将其复制到"SourceImg",进行一些过滤以分离背景并使其成为二进制图像,然后我可以正确进行 blob 提取。
public static List<Bitmap> ApplyBlobExtractor(Bitmap SourceImg)
{
List<Bitmap> ImgLetters = new List<Bitmap>();
AForge.Imaging.BlobCounter blobCounter = new AForge.Imaging.BlobCounter();
// Sort order
blobCounter.ObjectsOrder = AForge.Imaging.ObjectsOrder.XY;
blobCounter.ProcessImage(SourceImg);
AForge.Imaging.Blob[] blobs = blobCounter.GetObjects(SourceImg, false);
// Adding images into the image list
AForge.Imaging.UnmanagedImage currentImg;
foreach (AForge.Imaging.Blob blob in blobs)
{
currentImg = blob.Image;
ImgLetters.Add(currentImg.ToManagedImage());
}
return ImgLetters;
}
我真正想做的是使用这些斑点的信息从原始的、未处理的图像中提取位置。
理想情况下,我想像千篇一律一样使用 blob,并从我最初的未处理图像文件中提取它们。
可以使用 AForge.Imaging.Filters.Intersect 类,使用 blob 的映像和源映像。
假设部分图像处理没有调整原始图像的大小,为什么不将裁剪转换循环应用于原始图像,将裁剪矩形设置为 blob 的矩形属性?