Help with using filter.rank.median

Juan Nunez-Iglesias jni.soma at gmail.com
Fri Jan 31 20:15:07 EST 2014


Hi Aman,

Could you post a minimal example? I've tried the following and it seems to
work fine on my machine:

```python
>>> import numpy as np
>>> im = np.random.rand(5, 5)
>>> im[0, 0] = -1
>>> im[1, 1] = 1
>>> from skimage import morphology as mor, filter as fil
>>> selem = mor.disk(2)
>>> med = fil.rank.median(im, selem)
>>> med
array([[220, 220, 180, 216, 166],
       [220, 180, 216, 200, 200],
       [126, 180, 171, 180, 200],
       [119, 126, 155, 171, 216],
       [104, 119, 126, 171, 171]], dtype=uint8)
```

Also, please post the version of scikit-image you're using.

 But anyway, off the top of my head, no, I don't have any clear idea of
what's going wrong!

Juan.



On Sat, Feb 1, 2014 at 9:15 AM, Aman Thakral <aman.thakral at gmail.com> wrote:

> Hi all,
>
> I'm currently trying to use a median filter on my data, an am getting an
> error that I can't seem to debug.
>
> I'm taking the difference of two images (both numpy.float64), scaling them
> between -1 and 1, and trying to apply a median filter.  My image satisfies
> the conditions for being between -1 and 1 when I do the following test:
>
> print diff.min()/dmax < -1.0 -> returns False  (LHS evals to -1.0)
> print diff.max()/dmax > 1.0 -> returns False  (LHS evals to 0.663919388648)
>
> The statement causing the error:
>
> filtered = fltr.median(diff/dmax, selem)
>
> where diff is my difference, and dmax is my scaling adjustment, selem is a
> disk of radius 2
>
> This gives me the following traceback.
>
> Traceback (most recent call last):
>
>   File "/home/clustering.py", line 138, in image_ratio
>     filtered = fltr.median(diff/dmax/2.+0.5, selem, mask=m.astype(np.bool))
>   File
> "/usr/local/lib/python2.7/dist-packages/skimage/filter/rank/generic.py",
> line 369, in median
>     out=out, mask=mask, shift_x=shift_x, shift_y=shift_y)
>   File
> "/usr/local/lib/python2.7/dist-packages/skimage/filter/rank/generic.py",
> line 71, in _apply
>     out_dtype)
>   File
> "/usr/local/lib/python2.7/dist-packages/skimage/filter/rank/generic.py",
> line 34, in _handle_input
>     image = img_as_ubyte(image)
>   File "/usr/local/lib/python2.7/dist-packages/skimage/util/dtype.py",
> line 358, in img_as_ubyte
>     return convert(image, np.uint8, force_copy)
>   File "/usr/local/lib/python2.7/dist-packages/skimage/util/dtype.py",
> line 191, in convert
>     raise ValueError("Images of type float must be between -1 and 1.")
> ValueError: Images of type float must be between -1 and 1.
>
> Has anyone else experienced this problem before? I tried searching in the
> groups, but couldn't find anything relevant.
>
> Any help would be greatly appreciated!
>
> Thanks,
> Aman
>
> --
> 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+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20140201/6e8612c3/attachment.html>


More information about the scikit-image mailing list