Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to return NaN if window contains NaN for medfilt2d, medfilt #10807

Open
nikkopante opened this issue Sep 11, 2019 · 0 comments
Open

Comments

@nikkopante
Copy link

Is your feature request related to a problem? Please describe.
I am porting a script from Matlab to Python. Matlab's version of 2D Median Filter assigns an element to NaN when being computed and a window contains NaN.

Describe the solution you'd like
Possibly an additional argument, Boolean if NaN must be considered or ignored in the evaluation.

Describe alternatives you've considered
The silx library has this option for their [medfilt2d]. (http://www.silx.org/doc/silx/dev/modules/math/medianfilter.html#silx.math.medianfilter.medfilt2d). However the results are not accurate as SciPy's or Matlab's. I also tried ndimage.median_filter. However, it also ignores NaN and results we'rent as close as Matlab's.

Additional context (e.g. screenshots)
In Matlab or GNU Octave (Open Source)

pkg load image;
m = [1,2,3,4,5;1,2,3,4,5;1,2,3,4,5;1,2,3,4,5;1,2,3,4,NaN];
fltrd = medfilt2(m, [5 5])
fltrd =

     0     0     1     0     0
     0     1     2     2     0
     1     2     3     3     3
     0     1     2     2     0
     0     0     1     0   NaN

>>

In Python:

from scipy.signal import medfilt2d
import numpy as np
m = np.array([[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,np.nan]])
fltrd = medfilt2d(m, 5)
fltrd
array([[0., 0., 1., 0., 0.],
       [0., 1., 2., 2., 0.],
       [1., 2., 3., 3., 3.],
       [0., 1., 2., 2., 0.],
       [0., 0., 1., 0., 0.]])
@nikkopante nikkopante changed the title Add option to return NaN if windows contain NaN for medfilt2d, medfilt Add option to return NaN if window contains NaN for medfilt2d, medfilt Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants