[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cross-correlation for image registration

From: Carnë Draug
Subject: Re: cross-correlation for image registration
Date: Tue, 21 Feb 2012 10:59:05 +0000

On 16 February 2012 17:04, Matthew Nicholas <address@hidden> wrote:
>> Quoting Carnë Draug <address@hidden>:
>>> On 15 February 2012 21:15, Matt Nicholas <address@hidden> wrote:
>>>> Hello list,
>>>> I'm a reasonably experienced MATLAB user who is trying to move to Octave.
>>>> One task I frequently need to perform is image registration via cross
>>>> correlation, which I used to do in MATLAB using the normxcorr2. Basically, 
>>>> I
>>>> found the index of the maximum value in the correlation matrix, subtracted
>>>> the width and height of the template image from these coordinates, and this
>>>> gave me the shift of the template relative to the test image.  I have tried
>>>> using xcorr2 in Octave with the 'coeff' flag, but the results are not what 
>>>> I
>>>> would expect, and not very similar to normxcorr2 for the same images in
>>>> MATLAB (to be honest, I am not terribly surprised, because for some reason 
>>>> I
>>>> was never able to get this to work with xcorr2 in MATLAB either, but I
>>>> simply switched to normxcorr2 years ago and forgot about it). So I am a
>>>> little stuck. I've seen some previous discussion of this topic, with one
>>>> user even offering to write an Octave version of normxcorr2, but it doesn't
>>>> seem to have come to completion.
>>>> Just to be clear, this is not a complaint that normxcorr2 is 'missing' in
>>>> Octave. I am happy to change my approach if I can achieve similar results
>>>> with another method. Since it's a common task, I figured I would ask for
>>>> suggestions before trying to reinvent the wheel. Is there some appropriate
>>>> method of normalizing the output of xcorr2 to achieve what I want? 
>>>> Honestly,
>>>> I doubt this is a normalization issue, since the maximum value in the
>>>> correlation matrix is not *located* where I would expect (regardless of its
>>>> absolute magnitude). So a related question might be, does anyone know the
>>>> difference between xcorr2 and normxcorr2 in MATLAB?
>>>> Many thanks in advance for your help,
>>>> Matt
>>> Hi Matt
>>> I had a need for that function a while ago (for exactly the same
>>> purpose, image registration). I have an implementation of it on the
>>> development version of the image package. you can see it here:
>>> This makes the image package dependent on the signal package.
> Thanks for your replies!
> Carnë, from what I can tell, the normxcorr2 function you linked is a wrapper 
> for xcorr2 using the coeff flag, correct? I'd tried this previously as well, 
> but the results were not always what you would expect from 'normalized cross 
> correlation' as defined in the link Jordi provided. I think the problem may 
> be that the cross correlation is computed the same way even with the coeff 
> flag, and simply scaled at the end (I have to admit to not looking at the 
> source yet, however). Experimenting with the other available scaling flags 
> did not change the result noticeably. This might work for image registration 
> with a small set of cases (eg bright spot on a dark background),

This is exactly my case. I do fluorescence microscopy, bright spots
moving on a black background that I want to track. Since it also
passes the example here I
didn't bother about it anymore.

> but in general does not give the desired results. As an example, consider 
> this image of Clint Eastwood in a tuxedo:
>> I named it 'test.jpg', and ran the code below in MATLAB. It crops out his 
>> nose and then correctly overlays it with the original photo. In Octave, 
>> replacing normxcorr2 with xcorr2 (or using the normxcorr2 you provided), it 
>> overlays the nose image on his shirt. I believe the problem is that since 
>> his shirt is bright white, multiplying any part of the image with that 
>> region will give a maximum unless it is scaled somehow. Whereas in MATLAB 
>> there is a sharp maximum in the cross correlation near his nose, in Octave 
>> it is diffusely bright and closely resembles the original image. Please let 
>> me know if I am missing something.
>> Jordi, I would be happy to share anything I come up with, though I have to 
>> admit that in the past, I have basically used these functions as an "end 
>> user" and my background in digital signal processing is basically 
>> non-existent. However, the algorithm in the link you provided seems 
>> relatively straightforward. If I can find the time, I'll try to implement it 
>> and see how far I get.

If you are able to implement this, that would be great. I'll gladly
add it to the image package. I don't know thought if it would be
better to fix the coeff option of xcorr2 and keep normxcorr2 a wrapper
for it though.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]