bugGNU Octave - Bugs: bug #50151, [octave forge] (image) normxcorr2...

 
 

bug #50151: [octave forge] (image) normxcorr2 is not compatible with Matlab

Submitter:  Avinoam Kalma <avinoam>
Submitted:  Thu 26 Jan 2017 04:45:59 AM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  None Assigned to:  None
Originator Name:  Avinoam Open/Closed:  * Open
Release:  * other Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 30 Jan 2017 05:52:23 AM UTC, comment #3: 

I did not see problems which are not in the margins.
Probably a problem of padding policy.
In such small images and templates, Matlab is probably using
direct calculation and not FFT, which is efficient in larger images.

Avinoam Kalma <avinoam>
Group Member
Sun 29 Jan 2017 01:01:30 PM UTC, comment #2: 

Here is another normxcorr2 result from Matlab and Octave, to compare:

I = [0 1 2 1 2;
     1 0 1 1 0;
     0 1 2 2 0;
     0 2 0 0 0;
     2 1 0 0 0]

T = [0 1 1];

c = normxcorr2(T, I);
c(isinf(c))=0  # work around bug #50122

c_matlab = [ ...   # the Matlab result
          0    0.5000    0.8660    0.5000   -0.5000         0   -1.0000
     0.5000    0.5000   -0.5000    1.0000   -0.5000   -1.0000         0
          0    0.5000    0.8660    1.0000   -0.5000   -1.0000         0
          0    0.5000    0.5000   -1.0000         0         0         0
     0.5000    0.8660   -0.8660   -1.0000         0         0         0]

(abs(c - c_matlab)) > 1e-4

# result of this difference calcluation (in Octave):
#  1  1  0  0  0  1  0
#  0  1  0  0  0  1  1
#  1  1  0  0  0  1  1
#  1  1  0  0  0  1  1
#  0  1  0  0  0  1  1


This strengthens my suspicion that the significant differences are mainly around the border pixels, where some kind of extrapolation needed to be done.


Hartmut <hardy>
Thu 26 Jan 2017 10:00:19 PM UTC, comment #1: 

It might be a non-trivial task to fix this:

Matlab sometimes does calculations in the spatial or the frequency domain, it sounds quite convoluted:

Algorithms

normxcorr2 uses the following general procedure:

1. Calculate cross-correlation in the spatial or the frequency domain, depending on size of images.

2. Calculate local sums by precomputing running sums.

3. Use local sums to normalize the cross-correlation to get correlation coefficients.

(see http://de.mathworks.com/help/images/ref/normxcorr2.html#f6-308857)

In contrast, the Octave version of normxcorr2 does simply use the convn function, always in the spatial domain.

Question: Are there also significant differences between Matlab and Octave output for "center pixels"? I mean differences for pixels that are further away from the image border than the width of the template? Or is this always only an issue for pixels near the image border?

Hartmut <hardy>
Thu 26 Jan 2017 04:45:59 AM UTC, original submission:  


For example, use the following script (check_norm.m):


s = [-1 0 0 1 1 1 0 -1 -1 0 1 0 0 -1];
t = [1 1 0];
x = normxcorr2(t,s)


Running in Matlab:


>> check_norm

x =

  Columns 1 through 8

         0   -1.0000   -0.5000   -1.0000   -0.5000         0    1.0000    0.8660

  Columns 9 through 16

    0.5000   -1.0000   -0.8660    0.5000    0.5000    1.0000    0.5000         0


Running in Octave:


>> check_norm
x =

Columns 1 through 11:

   1.00000  -0.50000  -0.50000  -1.00000  -0.50000   0.00000   1.00000   0.86603   0.50000  -1.00000  -0.86603

Columns 12 through 16:

   0.50000   0.50000   1.00000  -0.50000  -0.50000


The two first entries and the two last entries are different.

Avinoam Kalma <avinoam>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Updated the item)
  • -email is unavailable- added by hardy (Posted a comment)
  • -email is unavailable- added by avinoam (Submitted the item)
  • -email is unavailable- added by avinoam
  • -email is unavailable- added by avinoam
  • -email is unavailable- added by avinoam
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-08-12 jwe Summaryimage package: normxcorr2 is not compatible with Matlab [octave forge] (image) normxcorr2 is not compatible with Matlab
    2017-01-26 avinoam Carbon-Copy- Added -email is unavailable-
        Carbon-Copy- Added -email is unavailable-
        Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-cf05.
    Corresponding source code