[SciPy-Dev] Documentation error for scipy.ndimage?

Benjamin Root ben.root at ou.edu
Tue Jul 19 14:21:17 EDT 2011


Hello,

I have been using the binary morphology functions in ndimage in a project.
I noticed that the docs for binary_opening() (and others) stated that it
accepts an integer or float for the iterations kwarg.  Also, that values
less than 1 would result in the binary_opening iteration to occur
successively until there were no more changes in the image.  However, if I
set iterations to 0.5, I get an error saying that it was expecting an
integer, and setting iterations to zero just obliterates the image.

>>> import numpy as np
>>> import scipy.ndimage as ndimg
>>> a = np.zeros((10, 10), dtype=bool)
>>> a[3:5, 2:5] = True
>>> a[5:7, 5:7] = True
>>> a[7:10, 2:8] = True
>>> a
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, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 1, 1, 0, 0, 0],
       [0, 0, 0, 0, 0, 1, 1, 0, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0]])
>>> ndimg.binary_opening(a, iterations=0).astype(int)
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, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
>>> ndimg.binary_opening(a, iterations=0.5).astype(int)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/bvr/Programs/scipy/scipy/ndimage/morphology.py", line 654, in
binary_opening
    origin)
  File "/home/bvr/Programs/scipy/scipy/ndimage/morphology.py", line 402, in
binary_erosion
    output, border_value, origin, 0, brute_force)
  File "/home/bvr/Programs/scipy/scipy/ndimage/morphology.py", line 278, in
_binary_erosion
    origin, invert, coordinate_list)
TypeError: integer argument expected, got float


Manually performing iterations reveals that the final result shouldn't be an
obliterated image:

>>> ndimg.binary_opening(a).astype(int)
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, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 1, 1, 0, 0, 0],
       [0, 0, 0, 0, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 1, 1, 0, 0, 0],
       [0, 0, 0, 0, 0, 1, 1, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 0, 0, 0]])
>>> ndimg.binary_opening(ndimg.binary_opening(a))
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, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 1, 1, 0, 0, 0],
       [0, 0, 0, 0, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 1, 1, 0, 0, 0],
       [0, 0, 0, 0, 0, 1, 1, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 0, 0, 0]])


Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20110719/b2ec1c3d/attachment.html>


More information about the SciPy-Dev mailing list