模板匹配 - 如何忽略像素

时间:2013-05-06 14:03:46

标签: c# image-processing template-matching

我试图在图像中找到一个数字。为了测试我的代码,我拍摄了数字图像,然后使用AForge的Exhaustive Template Matching算法在另一个图像中搜索它。但我认为有一个问题是数字显然不是矩形,而包含它的图像是。这意味着有很多像素参与比较,这不应该是。有没有办法在忽略那些像素的同时进行这种比较?如果不是在AForge那么可能是EMGU / OpenCV或Octave?

这是我的代码:

Grayscale gray = new GrayscaleRMY();
Bitmap template = (Bitmap)Bitmap.FromFile(@"5template.png");
template = gray.Apply(template);
Bitmap image = (Bitmap)Bitmap.FromFile(filePath);
Bitmap sourceImage = gray.Apply(image);
ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching(0.7f);
TemplateMatch[] matchings = tm.ProcessImage(sourceImage, template);

Here's an example image.

1 个答案:

答案 0 :(得分:4)

如上文评论中所述,您应该预处理数据以改善匹配。

首先想到的是morphological opening(侵蚀然后膨胀)以减少背景噪音

读入你的图像并将其反转,使你的角色矢量为白色:

enter image description here

使用尽可能小的结构元素/窗口(3x3)应用开口:

enter image description here

您可以尝试稍大一些的结构元素(5x5):

enter image description here

将其翻译回原文:

enter image description here

看看是否有帮助!