# [Numpy-discussion] nd_image.affine_transform edge effects

James Turner jturner@gemini....
Wed Apr 4 19:04:46 CDT 2007

``` > OK, that was a one-line patch.  Please test to see if there are any
> subtle conditions on the border that I may have missed. I know of one
> already, but I'd be glad if you can find any others :)

Thanks, Stefan! That looks much better.

Today I finally had time to figure out the basics of SVN, make a patch and
apply your changes to my numarray version of nd_image (I'll switch to numpy
as soon as STScI does a full numpy-based release...). Your integer clipping
changes wouldn't compile under numarray unmodified, but my data are floating
point anyway, so I just applied and tested the array indexing changes.

It looks like there may still be some edge effects due to the mirroring
properties of the spline algorithm for higher orders, but the gross problem
of extrapolating 1 pixel into the mirrored data has gone away :-). I think
that's good enough for nd_image to be useful for me, but if I can find time
later it would be good to look into improving the behaviour further.

For my real data, mode="constant" now seems to work well, but I also tested
some simple examples (like in this thread) using "reflect" and "wrap". I'm
not 100% sure from the numarray manual what their correct behaviour is
supposed to be, but I noticed some things that seem anomalous. For example:

-----

import numarray as N
import numarray.nd_image as ndi

I = N.zeros((2,4),N.Float32)
I[:,:] = N.arange(4.0, 0.0, -1.0)

trmatrix = N.array([[1,0],[0,1]])
troffset1 = (0.0, -0.1)

I_off1 = ndi.affine_transform(I, trmatrix, troffset1, order=1,
mode='reflect', output_shape=(2,6))

print I
print I_off1

-----

produces

[[ 4.  3.  2.  1.]
[ 4.  3.  2.  1.]]
[[ 3.0999999   3.0999999   2.0999999   1.10000002  1.89999998
1.89999998]
[ 3.0999999   3.0999999   2.0999999   1.10000002  1.89999998
1.89999998]]

It looks like the last output value is produced by reflecting the
input and then interpolating, but presumably then the first value
should be 3.9, for consistency, not 3.1? Does that make sense?

Cheers,

James.
```