[Scipy-tickets] [SciPy] #796: ndimage.shift destroys data from edges

SciPy scipy-tickets@scipy....
Sat Nov 29 09:24:04 CST 2008


#796: ndimage.shift destroys data from edges
---------------------------+------------------------------------------------
 Reporter:  0ion9          |        Owner:  somebody
     Type:  defect         |       Status:  new     
 Priority:  normal         |    Milestone:          
Component:  scipy.ndimage  |      Version:  devel   
 Severity:  normal         |   Resolution:          
 Keywords:                 |  
---------------------------+------------------------------------------------
Comment (by NeilMuller):

 In ni_interpolate.c, map_coordinate normalises by len-1 rather than len
 when using wrap, so, when dealing with the n'th column of an array, the
 answer maps to 1 rather than 0.

 The following patch fixes this, and fixes the behaviour for the given
 example:

 --- scipy/ndimage/src/ni_interpolation.c        (revision 5203)
 +++ scipy/ndimage/src/ni_interpolation.c        (working copy)
 @@ -140,10 +140,14 @@
              if (len <= 1) {
                  in = 0;
              } else {
 -                maybelong sz = len - 1;
 +                maybelong sz = len;
                  // Integer division of -in/sz gives (-in mod sz)
                  // Note that 'in' is negative
                  in += sz * ((maybelong)(-in / sz) + 1);
 +                // This maps to the range [1, len], so we need to wrap to
 +                // make this [0, len-1]
 +                if (in == len)
 +                   in = 0;
              }
              break;
          case NI_EXTEND_NEAREST:
 @@ -179,7 +183,7 @@
              if (len <= 1) {
                  in = 0;
              } else {
 -                maybelong sz = len - 1;
 +                maybelong sz = len;
                  in -= sz * (maybelong)(in / sz);
              }
              break;


 However, this breaks the current tests for wrap. Given that the current
 test includes the assertation that:

 sni.geometric_transform(np.array([1,2,3,4]),lambda c: (c[0] - 0.9,),
         cval=-1,mode='wrap', output_shape=(4,)) == [3, 1, 2, 3]

 I think the current behaviour of 'wrap' is wrong, but that prehaps needs
 more discussion before changing anything.

-- 
Ticket URL: <http://scipy.org/scipy/scipy/ticket/796#comment:2>
SciPy <http://www.scipy.org/>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list