[SciPy-User] Bug in scipy.ndimage.grey_dilate(structure)

Zachary Pincus zachary.pincus at yale.edu
Mon Mar 22 12:12:37 EDT 2010


> 2) How to use the 'structure' argument of  
> scipy.ndimage.grey_dilate() correctly?
> There are some explanations at
> http://docs.scipy.org/doc/scipy/reference/tutorial/ndimage.html
> but I think they are inconsistent with the implementation:

Oh dear, I think this is a bug that was previously reported by Tony Yu  
months ago (along with a patch!), which I said I would open a ticket  
about and look over the patch provided, but I seem to have entirely  
forgotten about (because I'm a flake).

http://projects.scipy.org/scipy/ticket/1135

Could someone who uses grey_dilation frequently (any cellprofiler  
people?) check the proposed changes over and make sure it makes sense  
in the grey case? The tests are only for binary cases.

Zach



On Mar 22, 2010, at 10:44 AM, Christoph Deil wrote:

> Hi,
>
> I am having some trouble figuring out how to use the following two  
> aspects of scipy:
>
> 1) How can I  create a random distribution given by some python  
> formula, e.g. pdf(x) = x**2 in the range x = 1 to 2.
>
> The example given in the rv_continuous docstring doesn't work for me:
> In [1]: import matplotlib.pyplot as plt
> In [2]: numargs = generic.numargs
> AttributeError: type object 'numpy.generic' has no attribute 'numargs'
>
> Is it also possible to use rv_continuous for multidimensional  
> distributions, say pdf(x,y)=x*y in the range x = 1 to 2 and y = 0 to  
> 3?
> Or for pdfs that are just given numerically on a grid (say as the  
> result of a gaussian_kde() ), not by a python function?
>
> It would be nice if someone could add a few examples that show  
> rv_continuous usage to the docstring or tutorial.
>
> 2) How to use the 'structure' argument of  
> scipy.ndimage.grey_dilate() correctly?
> There are some explanations at
> http://docs.scipy.org/doc/scipy/reference/tutorial/ndimage.html
> but I think they are inconsistent with the implementation:
>
> --------------------------------------------------------------
> In [98]: a = zeros((7,7)); a[3,3]=1; a
> Out[98]:
> array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
>       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
>       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
>       [ 0.,  0.,  0.,  1.,  0.,  0.,  0.],
>       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
>       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
>       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.]])
> In [100]: s = generate_binary_structure(2,2); s
> Out[100]:
> array([[ True,  True,  True],
>       [ True,  True,  True],
>       [ True,  True,  True]], dtype=bool)
>
> In [101]: grey_dilation(a,size=(3,3))
> Out[101]:
> array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
>       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
>       [ 0.,  0.,  1.,  1.,  1.,  0.,  0.],
>       [ 0.,  0.,  1.,  1.,  1.,  0.,  0.],
>       [ 0.,  0.,  1.,  1.,  1.,  0.,  0.],
>       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
>       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.]])
>
> In [102]: grey_dilation(a,size=(3,3),structure=s)
> Out[102]:
> array([[ 1.,  1.,  1.,  1.,  1.,  1.,  1.],
>       [ 1.,  1.,  1.,  1.,  1.,  1.,  1.],
>       [ 1.,  1.,  2.,  2.,  2.,  1.,  1.],
>       [ 1.,  1.,  2.,  2.,  2.,  1.,  1.],
>       [ 1.,  1.,  2.,  2.,  2.,  1.,  1.],
>       [ 1.,  1.,  1.,  1.,  1.,  1.,  1.],
>       [ 1.,  1.,  1.,  1.,  1.,  1.,  1.]])
>
> In [103]: grey_dilation(a,structure=s)
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent  
> call last)
>
> /Users/deil/<ipython console> in <module>()
>
> /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ 
> python2.6/site-packages/scipy/ndimage/morphology.pyc in  
> grey_dilation(input, size, footprint, structure, output, mode, cval,  
> origin)
>    354             sz = footprint.shape[ii]
>    355         else:
> --> 356             sz = size[ii]
>    357         if not sz & 1:
>    358             origin[ii] -= 1
>
> TypeError: 'NoneType' object is unsubscriptable
>
> In [104]: grey_dilation(a,footprint=s)
> Out[104]:
> array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
>       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
>       [ 0.,  0.,  1.,  1.,  1.,  0.,  0.],
>       [ 0.,  0.,  1.,  1.,  1.,  0.,  0.],
>       [ 0.,  0.,  1.,  1.,  1.,  0.,  0.],
>       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
>       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.]])
> --------------------------------------------------------------
>
> Why doesn't  grey_dilation(a,structure=s) work?
> Why doesn't grey_dilation(a,size=(3,3),structure=s) give the same  
> result as grey_dilation(a,size=(3,3),footprint=s)?
>
> I am running on numpy version 1.4.0 and scipy version 0.7.1
>
> Thanks!
> --Christoph
>
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user




More information about the SciPy-User mailing list