[SciPy-User] bug in ndimage grey_dilation?

Zachary Pincus zachary.pincus at yale.edu
Sat Aug 29 15:30:59 EDT 2009


That looks good and reasonable!

Any other morphological filters that have this inconsistency?

Zach


On Aug 29, 2009, at 1:00 PM, Tony S Yu wrote:

> ndimage.grey_dilation doesn't handle scalar size arguments (in
> contrast to other filters). For example:
>
>>>> ndimage.grey_dilation(np.ones((5,5)), size=2)
> TypeError: 'int' object is unsubscriptable
>
> Below is a simple patch which seems to fix the issue (I basically
> copied the behavior of ndimage.filters._min_or_max_filter). The diff
> below is taken against the 0.7.x branch.
>
> I guess this may not technically be a bug since filters in
> morphology.py don't specify they can handle scalar size arguments
> (filters in filters.py do document this behavior). In any case, this
> fix would make the API more consistent.
>
> Cheers,
> -Tony
>
> ===================================================================
> --- morphology.py	(revision 5911)
> +++ morphology.py	(working copy)
> @@ -347,13 +347,14 @@
>          footprint = footprint[tuple([slice(None, None, -1)] *
>                                      footprint.ndim)]
>      input = numpy.asarray(input)
> +    sizes = _ni_support._normalize_sequence(size, input.ndim)
>      origin = _ni_support._normalize_sequence(origin, input.ndim)
>      for ii in range(len(origin)):
>          origin[ii] = -origin[ii]
>          if footprint is not None:
>              sz = footprint.shape[ii]
>          else:
> -            sz = size[ii]
> +            sz = sizes[ii]
>          if not sz & 1:
>              origin[ii] -= 1
>      return filters._min_or_max_filter(input, size, footprint,
> structure,
>
> _______________________________________________
> 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