Skip to content

ndimage.filters and ndimage.interpolation is incompatible with masked_array (Trac #1155) #1682

@scipy-gitbot

Description

@scipy-gitbot

Original ticket http://projects.scipy.org/scipy/ticket/1155 on 2010-04-20 by trac user sam, assigned to unknown.

When processing 2D images where some pixels are missing (coming from an optical profilometer), some of the functions of ndimage give rather unexpected results when used with masked array.

Example:

import scipy
import scipy.ndimage.interpolation as interp
L=asarray(scipy.lena(),dtype=double)
L[100,100]=NaN
Lm=ma.masked_array(L,isnan(L))
Lr=interp.rotate(Lm,5)

When looking at the resulting Lr, we see that all values have become NaN (or the cval, 0).

On the contrary, when I do

Lr=interp.rotate(Lm,5,prefilter=False)

The result of this operation is much better and Lena is visible again. However, the gap of 1 pixel has now become 4x4 pixels large. while this is a much better result, in my case these 'exploding' missing data boxes are destroying a lot of the few data points I have. Thus, it seems that the filters in ndimage seem to be partly to blame.

Alternatively, if I use ma.fix_invalid as so:

Lf=ma.fix_invalid(Lm,fill_value=0)
Lfr=interp.rotate(Lf,5)

then the missing pixel is almost completely filtered out. However, this modifies the results significantly as, in my case, I introduce a lot of artificial data and my scientific data depends on the fill_value I introduce.

All of this, seems to suggest to me that the mask in the masked array is not used in the filtering stage and the mapping stage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Migrated from TracdefectA clear bug or issue that prevents SciPy from being installed or used as expectedscipy.ndimage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions