Normalisation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Normalisation

supr8sung
I'm running Octave 4.0.3  Im currently following a computer vision course on Udacity and came across the following unexpected behaviour of normxcorr2 (from the image package): 
It is always giving me wrong index value for matchig template with the signal.
Can you help me in figuring this out.
Supreet Singh

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Normalisation

Joel Holder
Did you figure it out? Same issue. Same problem set: Example:
>> s = [-1 0 0 1 1 1 0 -1 -1 0 1 0 0 -1];
>> t = [1 1 0];

>> disp('Signal:'), disp([1:size(s, 2); s]);

Signal:
    1    2    3    4    5    6    7    8    9   10   11   12   13   14
   -1    0    0    1    1    1    0   -1   -1    0    1    0    0   -1

>> disp('Template:'), disp([1:size(t, 2); t]);

Template:
   1   2   3
   1   1   0

>> index = find_template_1D(t, s);

>> c = normxcorr2(t, s);
>> [maxValue index] = max(c);
index should be 7. I get 6. Can anyone tell me why?
supr8sung wrote
I'm running Octave 4.0.3 Im currently following a computer vision course on Udacity and came across the following unexpected behaviour of normxcorr2 (from the image package): It is always giving me wrong index value for matchig template with the signal. Can you help me in figuring this out. Supreet Singh _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Normalisation

Hartmut
In reply to this post by supr8sung
Welcome to Octave!

Please have a look here [1] where this question of your Udacity course has been answered previously.

Short summary:

Your Udacity course works with an old version of Octave's image package. Those results where buggy, and have now been (mostly) corrected.

Try this Octave code:

clear
pkg load image                        % using image 2.6.1 release
s = [-1 0 0 1 1 1 0 -1 -1 0 1 0 0 -1]
t = [1 1 0]
x = normxcorr2(t,s);
x(~isfinite(x))=0                       % to fix inf values (bug 50151)
[maxVal maxRawIndex] = max(x)

The resulting output is (slightly rounded):
x = 1 -0.5 -0.5 -1 -0.5 0 1 0.87 0.5 -1 -0.87 0.5 0.5 1 -0.5 -0.5
maxVal = 1
maxRawIndex = 7

The maxRawIndex could equally well be 1 or 14 instead of this 7. Those are all the positions where x has the value 1 (the position 7 seems to be closest to 1 because of machine precision).

The index 7 position corresponds to "1 1 0" in s, and the index 14 position corresponds to "0 0 -1" in s. Both have the same maximum normalized cross correlation to t. The index position 1 is just an artifact of padding the borders (those padded borders are also currently not perfectly Matlab compatible).

This raw index can the be transferred to the index in the original array s if you like. You might do something like "index = rawIndex-(length(t)-1)/2". Then you will get the center element in s that corresponds to your matching substring. This value would then be 6 and would properly correspond to the part "1 1 0" in s.

Have fun with Octave and the image package

    Hartmut

[1] http://octave.1599824.n4.nabble.com/Octave-4-0-3-normxcorr2-producing-unexpected-result-td4681543.html
Reply | Threaded
Open this post in threaded view
|

Re: Normalisation

Joel Holder
This really makes clear what's going on here.

Thank you, Harmut.  

On Mon, Aug 28, 2017 at 12:35 PM Hartmut [via Octave] <[hidden email]> wrote:
Welcome to Octave!

Please have a look here [1] where this question of your Udacity course has been answered previously.

Short summary:

Your Udacity course works with an old version of Octave's image package. Those results where buggy, and have now been (mostly) corrected.

Try this Octave code:

clear
pkg load image                        % using image 2.6.1 release
s = [-1 0 0 1 1 1 0 -1 -1 0 1 0 0 -1]
t = [1 1 0]
x = normxcorr2(t,s);
x(~isfinite(x))=0                       % to fix inf values (bug 50151)
[maxVal maxRawIndex] = max(x)

The resulting output is (slightly rounded):
x = 1 -0.5 -0.5 -1 -0.5 0 1 0.87 0.5 -1 -0.87 0.5 0.5 1 -0.5 -0.5
maxVal = 1
maxRawIndex = 7

The maxRawIndex could equally well be 1 or 14 instead of this 7. Those are all the positions where x has the value 1 (the position 7 seems to be closest to 1 because of machine precision).

The index 7 position corresponds to "1 1 0" in s, and the index 14 position corresponds to "0 0 -1" in s. Both have the same maximum normalized cross correlation to t. The index position 1 is just an artifact of padding the borders (those padded borders are also currently not perfectly Matlab compatible).

This raw index can the be transferred to the index in the original array s if you like. You might do something like "index = rawIndex-(length(t)-1)/2". Then you will get the center element in s that corresponds to your matching substring. This value would then be 6 and would properly correspond to the part "1 1 0" in s.

Have fun with Octave and the image package

    Hartmut

[1] http://octave.1599824.n4.nabble.com/Octave-4-0-3-normxcorr2-producing-unexpected-result-td4681543.html


If you reply to this email, your message will be added to the discussion below:
http://octave.1599824.n4.nabble.com/Normalisation-tp4682870p4684700.html
To unsubscribe from Normalisation, click here.
NAML
--
Sent from Gmail Mobile