Page 1 of 1

[RESOLVED] NCC subimage-search

Posted: 2014-05-06T09:26:37-07:00
by snibgo
Metric NCC doesn't seem to work with subimage-search. As always, the bug may be in my understanding.

Testing on IM v 6.8.9-0 on Windows 8.1. Create large and small sample images:

Code: Select all

%IM%convert ^
  -size 400x300 xc: ^
  -sparse-color barycentric "0,0 #88f 399,0 #44f 0,299 #2f2 399,299 #484" ^
  si_large.png

%IM%convert ^
  -size 50x50 xc:#0aa ^
  si_sub.png
RMSE search:

Code: Select all

%IM%compare ^
  si_large.png si_sub.png ^
  -metric RMSE ^
  -subimage-search ^
  NULL: 

12068.7 (0.184156) @ 182,140
The result is good.

NCC search:

Code: Select all

%IM%compare ^
  si_large.png si_sub.png ^
  -metric NCC ^
  -subimage-search ^
  NULL: 

0 @ 0,20
This is (I think) a bad result.

If I understand correctly, NCC result 1.0 (or greater, huh?) is a perfect match, where 0.0 isn't. But subimage-search finds the minimum score.

Re: NCC subimage-search

Posted: 2014-05-06T11:00:56-07:00
by fmw42
NCC is not applicable to any small constant color image or any large image with constant color regions the size of the small image. That is because it divides the numerator correlation with the standard deviation of the small image and the standard deviation of the subsection of the large image for each shift position. Thus a divide by zero.

Re: NCC subimage-search

Posted: 2014-05-06T11:23:34-07:00
by snibgo
Ah, yes, of course, thank you. Must engrave "NCC divides by standard deviation" on my brain.