[RESOLVED] NCC subimage-search

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

[RESOLVED] NCC subimage-search

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: NCC subimage-search

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: NCC subimage-search

Post by snibgo »

Ah, yes, of course, thank you. Must engrave "NCC divides by standard deviation" on my brain.
snibgo's IM pages: im.snibgo.com
Post Reply