[SciPy-user] Ignoring pixels with gaussian_filter
Fri Apr 24 14:12:36 CDT 2009
> I am currently using gaussian_filter to smooth an image stored in a
> numpy array. My problem is that some pixels have no defined value, and
> are set to NaN. If gaussian_filter stumbles upon a NaN value, it will
> set all pixels within a certain radius of that value to NaN.
> Of course, I can simply use
> a[np.where(np.isnan(a))] = 0.
> to reset all NaN pixels to zero, but then the result depends on the
> value I replace NaNs by.
> Is there a way to get gaussian_filter to simply ignore such pixels
> when smoothing? (apart from writing a gaussian filter algorithm from
No simple way to get gaussian_filter to ignore nan pixels when doing
You could write your own convolution function in cython (not as bad as
it sounds, or you could fill in the missing data with something
reasonable (like the median of the neighbors) before gaussian
filtering. These should give pretty similar results.
You could check out an earlier thread on numpy-discussion titled "Help
with interpolating missing values from a 3D scanner" for some
discussion about filling in missing values.
More information about the SciPy-user