Template Matching - NCC

  • Hi ,

    I am tryin to do the template matching: I tested the provided example "normalized cross correlation". The example seems to detect the object with dimension of 12 pixels by using the operator FIR kernel 12x12, is this correct?

    I want to match an image using sub-image as template, how should I revise the design?



  • Dear Bingnan,

    Thank you for your question.

    When using FIR kernel one has to be careful not to use too large Kernels, since this will increase the used FPGA ressources by a lot. Therefore, it is important to know how large your sub-image will be?

    If it is 12x12 Pixel (or somewhere in that region) you can convert your image file to a text file and load it in the FirOperator by clicking on Coefficents -> File.

    Inside the example directory you can find a NCC.m script that shows you how to convert a tif file into the apropriate textformat (basically writing one pixel per line)

    If your subimage is vastly larger than that more advanced techniques must be used, e.g. cutting the image in tiles by using the ImageBufferMultiROI or downscaling your subimage.



  • Hi Bingnan,

    You can use the Operator "SplitComponents" to divide the input image in its three componets (R,G,B) and then compute the filter on each one. To combine the results together again to one RGB Image use the operator "MergeComponents"



  • I think the problem is that I am using the gray camera operator, how should I modify the design? (change the RGB settings)

  • Hi Bingan,

    Sorry for the confusion. The error message comes from the upcoming Opreator "SelectComponent". This in the example because an RGB Camera was used.

    Since you already have a gray camera you should be able to simply delete the "SelectComponent" Operator and combine the 12x12 FIRkernelNxM Operator with the NCC H-Box



  • Thank you for your advice

    I am trying to use my images, but the result shows failed (blank image)

    I loaded my .txt file into the FirOperator in the NCC hierarchical box. The text file is from the 12x12 Downscaled image I made by OpenCV.

    Could you please check what is the problem? (I noticed that there are other FirOperators in other hierarchical boxes, but I suppose the parameters there are from FIRkernal and don't need to be changed)