bugGNU Octave - Bugs: bug #50122, image package: normxcorr2...


bug #50122: image package: normxcorr2 sometimes returns inf values

Submitter:  Hartmut <hardy>
Submitted:  Sun 22 Jan 2017 07:28:24 PM UTC
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 4.2.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup

Jump to the original submission

Wed 12 Apr 2017 12:36:34 PM UTC, comment #7: 

Pushed after removing trailing whitespace


Thank you guys

Carnë Draug <carandraug>
Group Member
Thu 26 Jan 2017 04:47:21 AM UTC, comment #6: 

See also bug #50151

Avinoam Kalma <avinoam>
Group Member
Tue 24 Jan 2017 09:40:53 PM UTC, comment #5: 

I have tested this patch:
It solves the original issue of this bug report and it adds (passing) tests for the bug.

I would be happy to see this one applied to the image repository.

Note that normxcorr2 still has a problem of Matlab compatibility in
the margins. It is not related to this bug, so I will open a new bug report for this.

Changing status to "Patch Reviewed" (By Mike and by me).

Avinoam Kalma <avinoam>
Group Member
Mon 23 Jan 2017 07:05:09 PM UTC, comment #4: 

Here is a new version (V2) of my PATCH, that includes Mike's hints from comment #3.

(file #39543)

Hartmut <hardy>
Mon 23 Jan 2017 06:10:05 PM UTC, comment #3: 

Hartmut - you could combine your change into one line, may be slightly more efficient since it will be assigning the zeros all at the same time:

c(isinf (c) | isnan (c)) = 0;

You could also change the test to assert that c is exactly what you expect it to be, something like

%! assert (c, [-1 -.5 0 1 -1/sqrt(13) -.5], eps)

or at least test that c(3) is exactly zero. Just my two cents, makes it clear exactly what this test was added for.

Other than that, patch and test look good to me.

Mike Miller <mtmiller>
Group Member
Mon 23 Jan 2017 05:29:18 PM UTC, comment #2: 

(adding people to cc who care about the image package)

Hartmut <hardy>
Sun 22 Jan 2017 07:43:14 PM UTC, comment #1: 

Here is a PATCH to fix this behavior, including a new test for it.

(file #39533)

Hartmut <hardy>
Sun 22 Jan 2017 07:28:24 PM UTC, original submission:  

This bug was mentioned on the Octave help list:


The behavior is still present with Octave 4.2.0 and image-2.6.1.

The reason for this behavior is that the current Octave version of normxcorr2.m does not properly treat the special case of a constant value in the image part.

Here is what Matlab does:


Normalized cross-correlation is an undefined operation in regions where A has zero variance over the full extent of the template. In these regions, we assign correlation coefficients of zero to the output C.

A solution to this is to add the following line to the code to the end of normxcorr2.m:

  c(isinf (c)) = 0;

I will prepare a patch for this soon.

Hartmut <hardy>


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

Attach Files:

Attached Files
file #39533:  normxcorr2_no_infs.patch added by hardy (990B - text/x-diff)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by avinoam (Posted a comment)
  • -email is unavailable- added by hardy (adding people to cc who care about the image package)
  • -email is unavailable- added by hardy (adding people to cc who care about the image package)
  • -email is unavailable- added by hardy (Submitted the item)

    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 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-03-03 mtmiller Carbon-CopyRemoved 80942 -
    2017-04-12 carandraug StatusPatch Reviewed Fixed
        Open/ClosedOpen Closed
    2017-01-24 avinoam StatusPatch Submitted Patch Reviewed
    2017-01-23 hardy Attached File- Added normxcorr2_no_infs_V2.patch, #39543
    2017-01-23 mtmiller StatusNone Patch Submitted
    2017-01-23 hardy Carbon-Copy- Added avinoam
        Carbon-Copy- Added carandraug
    2017-01-22 hardy Attached File- Added normxcorr2_no_infs.patch, #39533

    Back to the top

    Powered by Savane 3.13-f762.
    Corresponding source code