0

I'm trying to find a digit within an image. To test my code I took an image of the digit and then used AForge's Exhaustive Template Matching algorithm to search for it in another image. But I think there is a problem in that the digit is obviously not rectangular whereas the image that contains it is. That means that there are a lot of pixels participating in the comparison which shouldn't be. Is there any way to make this comparison while ignoring those pixels? If not in AForge then maybe EMGU/OpenCV or Octave?

Here's my code:

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.

Johnny
  • 7,073
  • 9
  • 46
  • 72

1 Answers1

4

As mentioned above in the comment, you should preprocess your data to improve matching.

The first thing that comes to mind is morphological opening (erode then dilate) to reduce the background noise

Read in your image and invert it so that your character vectors are white:

enter image description here

Apply opening with smallest possible structuring element/window (3x3):

enter image description here

You could try slightly larger structuring elements (5x5):

enter image description here

Invert it back to the original:

enter image description here

See if that helps!

Omar Wagih
  • 8,504
  • 7
  • 59
  • 75