Normalised cross correlation

Tony Yu tsyu80 at gmail.com
Tue Mar 20 11:13:26 EDT 2012


On Tue, Mar 20, 2012 at 10:56 AM, Malcolm Reynolds <
malcolm.reynolds at gmail.com> wrote:

> On Tuesday, March 6, 2012 6:54:22 PM UTC, Tony S Yu wrote:
>>
>>
>> Hi Malcolm,
>>
>> I currently have a PR for a normalized cross-correlation function<https://github.com/scikits-image/scikits-image/pull/100>(which was originally implemented by Pieter Holtzhausen).
>> Comments/suggestions would definitely be appreciated.
>>
>> -Tony
>>
>
> Hi Tony
>
> I've just got round to trying this and I may be using it wrong, but
> currently I'm finding it doesn't match the result given by matlab's
> normxcorr2. For one thing I think it would make sense to raise an error
> when the user passes the template and image the wrong way round (matlab
> does this). Also, I've tested by having the template as the central part of
> some image, and using ncc to compare the template to the whole image.
> Ideally since there is one arrangement which makes each pixel match
> perfectly, there will be a very clear strong peak in the NCC image - which
> is indeed what I see in matlab (eg
> http://img840.imageshack.us/img840/8577/screenshot20120320at143.png ).
> With your match_template function however, I'm unable to get the same
> result, what I get instead is this:
> http://img844.imageshack.us/img844/8577/screenshot20120320at143.png - and
> if I put the template and image arguments in a different order I get an
> image that looks like it may have accessed invalid memory:
> http://img849.imageshack.us/img849/7696/screenshot20120320at144.png
>
> Additionally, calling template_match a second time with the arguments in
> this 'wrong' order produces a segmentation fault.
>
> Also note that the matlab, when given a 768x432 image and 384x216 template
> the size of the result from normxcorr2 is 647x1151. As far as I can see
> this size of result is not possible to create with your code, although
> please correct me if I'm wrong?
>
> I hope these bug reports are useful, if you need me to put together a
> reproduction script just let me know.
>
> Malcolm
>

Wow, those results are incredibly different. Yes, please put together a
small script to reproduce the different behaviors (ideally, with the matlab
result saved as .npy---or if it's easier .mat---file; also, if you can
reproduce with a smaller image, that would be great).

It'll be easy to check for switched arguments, but the rest might take some
time for me to get to. In your original email, it sounded like you have
some expertise in template matching; feel free to dig into the code and see
if you can spot any errors in the code.

Cheers,
-Tony
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20120320/dcbcfa17/attachment.html>


More information about the scikit-image mailing list