[SciPy-dev] ndimage problems
Stefan van der Walt
stefan@sun.ac...
Tue Oct 9 19:07:51 CDT 2007
Hi Chris
On Tue, Jul 03, 2007 at 12:25:55PM -0400, Christopher Hanley wrote:
> We have found two problems with ndimage. I have filed a ticket #455 on
> the scipy trac page. The first problem can be seen with this example:
>
> > import numpy as n
> > from scipy import ndimage as nd
> > a = n.ones((10,5),dtype=n.float32) * 12.3
> > x = nd.rotate(a,90.0)
> > x
> Out[17]:
> array([[ 12.30000019, 12.30000019, 12.30000019, 12.30000019,
> 12.30000019, 12.30000019, 12.30000019, 12.30000019,
> 0. , 0. ],
> [ 12.30000019, 12.30000019, 12.30000019, 12.30000019,
> 12.30000019, 12.30000019, 12.30000019, 12.30000019,
> 12.30000019, 12.30000019],
> [ 12.30000019, 12.30000019, 12.30000019, 12.30000019,
> 12.30000019, 12.30000019, 12.30000019, 12.30000019,
> 12.30000019, 12.30000019],
> [ 12.30000019, 12.30000019, 12.30000019, 12.30000019,
> 12.30000019, 12.30000019, 12.30000019, 12.30000019,
> 12.30000019, 12.30000019],
> [ 12.30000019, 12.30000019, 12.30000019, 12.30000019,
> 12.30000019, 12.30000019, 12.30000019, 12.30000019,
> 12.30000019, 12.30000019]], dtype=float32)
> }}}
>
> Notice that the last two entries of the first row are now 0.
This is due to a slight round-off error when calculating the affine
transformation matrix. cos(pi/180 * angle) isn't exactly zero, so you
find that elements that fall *just* outside the boundary gets
converted to the cval (0). You can work around the problem in two
ways.
The first is to setup your own transformation matrix:
nd.affine_transform(a,[[0,1],[-1,0]],offset=[0,4],output_shape=(5,10))
The second is to use 'mirror' boundary mode, instead of 'cval',
thereby nudging those outliers back into place.
> The second problem has to do with the reversing of byte order if you
> have big-endian data on a little endian machine. Please see the example
> below:
Thanks, I'll have a look at that.
Regards
Stéfan
More information about the Scipy-dev
mailing list