[SciPy-User] bug in ndimage grey_dilation?
Tony S Yu
Sat Aug 29 22:58:01 CDT 2009
On Aug 29, 2009, at 9:48 PM, email@example.com wrote:
> Message: 1
> Date: Sat, 29 Aug 2009 15:30:59 -0400
> From: Zachary Pincus <firstname.lastname@example.org>
> Subject: Re: [SciPy-User] bug in ndimage grey_dilation?
> To: SciPy Users List <email@example.com>
> Message-ID: <C36F4C5B-58CA-40A7-87C4-4485490140D6@yale.edu>
> Content-Type: text/plain; charset=US-ASCII; format=flowed
> That looks good and reasonable!
Oops! I really didn't test my fix. This patch causes a failure if
footprint is specified without specifying a size (which should be
allowed). Also, the function seems to fail (both before and after the
patch) if the structure is specified without specifying a size (which
the docstring suggests is allowed).
I'll work on another patch, but it may require me to understand the
code a bit better (I don't even understand the difference between
footprint and structure at this point). (Also, ``if not sz & 1``---at
the bottom of the diff---seems really weird to me).
> Any other morphological filters that have this inconsistency?
This seems to be the only filter affected with this inconsistency b/c
all other filters delegate their handling of size/footprint/structure
arguments to filters._min_or_max_filter (which handles the scalar
sizes without problems).
> 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.
>> --- morphology.py (revision 5911)
>> +++ morphology.py (working copy)
>> @@ -347,13 +347,14 @@
>> footprint = footprint[tuple([slice(None, None, -1)] *
>> 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]
>> - sz = size[ii]
>> + sz = sizes[ii]
>> if not sz & 1:
>> origin[ii] -= 1
>> return filters._min_or_max_filter(input, size, footprint,
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-User