c# - Template matching - how to ignore pixels -


i'm trying find digit within image. test code took image of digit , used aforge's exhaustive template matching algorithm search in image. think there problem in digit not rectangular whereas image contains is. means there lot of pixels participating in comparison shouldn't be. there way make comparison while ignoring pixels? if not in aforge maybe emgu/opencv or octave?

here's 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 example image.

as mentioned above in comment, should preprocess data improve matching.

the first thing comes mind morphological opening (erode dilate) reduce background noise

read in image , invert character vectors white:

enter image description here

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

enter image description here

you try larger structuring elements (5x5):

enter image description here

invert original:

enter image description here

see if helps!


Comments