Thomas Robitaille
2009-04-24 14:58:22 UTC
Hello,
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. Consider
the following example:
---
import numpy as np
from scipy.ndimage import gaussian_filter
a = np.ones((9,9))
a[4,4] = np.nan
b = gaussian_filter(a,sigma=2)
print "Original:"
print a
print "Smoothed:"
print b
---
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
scratch!)
Thanks for any help,
Thomas
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. Consider
the following example:
---
import numpy as np
from scipy.ndimage import gaussian_filter
a = np.ones((9,9))
a[4,4] = np.nan
b = gaussian_filter(a,sigma=2)
print "Original:"
print a
print "Smoothed:"
print b
---
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
scratch!)
Thanks for any help,
Thomas