# Machine Vision

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## IMAQ Correlate - normalized cross correlation calculation

Hello to all,

I am trying to clarify the meaning of the [0:255] range which the output of the IMAQ Correlate VI provides. I understand that 255 indicates a very high correlation, while 0 means no correlation.

I did not find the formula after which this VI computes the results. NCC calculation results in the coefficient with values in the range [1,1] where 1 signifies best correlation between the source image & the template. The relation of this calculation, as found in NI Vision Concepts Manual, is:

The observations that I found in one of the older posts (dated 2012) was that the positive values of the coefficient [0:1] are mapped as [0:255] in this VI. While negative coefficient values [-1:0) are allocated the value of 0 by default.

Anyway, my question is on the mapping of the [0:255] to [-1:1]. Is it accurate to assume that the IMAQ Correlate VI [0:255] can be mapped to [-1:1]? Or we can assume that IMAQ Correlate VI [0:255] can be mapped to [0:1]?

Please let me know if you have any suggestions on this matter?

Have a nice day, thanks.

Message 1 of 5
(539 Views)

## Re: IMAQ Correlate - normalized cross correlation calculation

I think, the easiest way to proof is to recreate this computation from the scratch and compare the results side by side to IMAQ Correlate. Could be interesting experiment and good exercise.

Message 2 of 5
(503 Views)

## Re: IMAQ Correlate - normalized cross correlation calculation

Hi Andrey,

Thanks for the reply. Unfortunately to recreate this calculation from scratch is outside the purpose of my application, although I agree that it could be an interesting task.

I was thinking to call the MATLAB function normxcorr2 from the Matlab Script Node, with the same image & template inputs and try to see if the results follow the IMAQ Correlate output.

Otherwise, empirically, I would just define an acceptance threshold (for example 240), and consider all values above as "good" correlation. But this would be strictly related to my acquisition conditions (illumination, distance, resolution etc.).

Please let me know what you think?

Message 3 of 5
(476 Views)
Solution
Accepted by topic author Raul.Ionel

## Re: IMAQ Correlate - normalized cross correlation calculation

In general the normalized cross correlation is not so sensitive for different illumination condition (therefore called "normalized". Usually the only absolute maximum is interesting, which is the best correlation.

Anyway, I checked the MATLAB normxcorr2 and was able to recreate crosscorrelation exactly as implemented in MATLAB (result copypasted) and supposesd to be implemented by NI. I still unable to understand the rescaling from -1...1 range to 0...255 (it seems to be NI uses different slopes for negative and positive ranges and something is non-linear), but comparizon of all three implementations is attached (LV 2021). A little bit "spaghetti-like" but will give you and idea how this works under the hood.

Message 4 of 5
(453 Views)
Solution
Accepted by topic author Raul.Ionel

## Re: IMAQ Correlate - normalized cross correlation calculation

Hi Andrey,

I definitely thank you for this VI! And I will test it on my images. I will also look at the step-by-step details. No matter of the "spaghetti-like" structure, I think it is a valuable implementation for all interested. I was ready to just use the call to normxcorr2 and report the results in my LabVIEW Front Panel.

Thank you again for this implementation! 🙂

Message 5 of 5
(421 Views)