On Wednesday, September 4, 2013 10:44:21 PM UTC-7, Juan Nunez-Iglesias wrote:
Hi Michael,
It makes a lot of sense that this would fail, but skimage.filter.rank.mean<http://scikit-image.org/docs/dev/api/skimage.filter.rank.html#mean>has a `mask` keyword argument that can do what you want. However, it only works for uint8 or uint16 images, *and* if I remember correctly, it will be much slower if values exceed 12 bits, that is, your image intensity values should be in [0, 4096).
Hi!
Thanks for your reply! Could you explain why it makes sense that the uniform_filter fails in my example? Using a window of 3, I expect the following in this simple 1d example: input: [nan, 1, 2, 3, 4, 5, nan] output: [nan, nan, 2, 3, 4, nan, nan] Why should this not work? Michael
from skimage.filter import rank
arr = array([[np.nan, 1, 2, 3, 4, 5, np.nan]]) # make sure this is 2D selem = np.ones((3, 3)) arr_mean1 = rank.mean(arr.astype(np.uint8), selem) arr_mean1 array([[0, 1, 2, 3, 4, 3, 2]], dtype=uint8)
arr.astype(np.uint8) # nan's are actually converted to 0... Not good! array([[0, 1, 2, 3, 4, 5, 0]], dtype=uint8)
nan_mask = True - np.isnan(arr) arr_mean2 = rank.mean(arr.astype(np.uint8), selem, mask=nan_mask) arr_mean2 # using the nan mask produces the correct output array([[1, 1, 2, 3, 4, 4, 5]], dtype=uint8)
Hope this helps!
Juan.
On Mon, Sep 2, 2013 at 10:12 PM, Michael Aye <kmicha...@gmail.com<javascript:>
wrote:
Hi!
I am trying to use ndimage's uniform_filter (for a simple local mean filtering) on a map-projected image that has NAN's at the border (basically the corners where the rotated map projected image does not fit into the rectangular grid). Is there a way, maybe in skimage, to use a uniform_filter on an array that contains NANs? ndimage' version does not cope with it correctly:
arr = array([np.nan, 1,2,3,4,5,np.nan]) arr
array([ nan, 1., 2., 3., 4., 5., nan])
nd.filters.uniform_filter(arr, 3)
array([ nan, nan, nan, nan, nan, nan, nan])
Cheers,
Michael
-- You received this message because you are subscribed to the Google Groups "scikit-image" group. To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image...@googlegroups.com <javascript:>. For more options, visit https://groups.google.com/groups/opt_out.