Batman
Batman

Reputation: 19

corr2 in matlab returns NaN

I am trying to use corr2 for template matching. But when i give the window around first pixel and template matrix to the function, I get NaN error.

For ex :- 
template = uint8([1 1 1 0; 1 1 1 0;1 1 1 0]); 
window = uint8([0 0 0 0; 0 0 0 0;0 0 0 0]); 
When i do corr2 on this two matrix :-
r = corr2(template,window);
r = NaN.

But if i change one of the zero value in matrix to 1 in window, it give me output other than NaN. I am following the link :- https://www.youtube.com/watch?v=Q-OzmDen4HU for template matching which show output as 0 for the first pixel. I am not getting where i am doing wrong.

Upvotes: 0

Views: 830

Answers (1)

Christopher Bell II
Christopher Bell II

Reputation: 21

Corr2 Documentation

If you look at the bottom of the page under algorithm, it gives the equation who's result will be represented by Corr2.

Your second matrix is a 0 matrix, and as such the second summation in the equation's denominator will be 0, and you will divide by 0.

Upvotes: 2

Related Questions