[scikit-image] Observed difference between skimage.filters.rank.mean and scipy.signal.convolve2d

Juan Nunez-Iglesias jni.soma at gmail.com
Fri Nov 3 09:56:37 EDT 2017


Hi Victor,

The biggest problem is that you’re getting bitten by datatypes. Please read the following document:

http://scikit-image.org/docs/dev/user_guide/data_types.html

Specifically, rank_mean is a uint8 image, so only contains integers between 0 and 255. naive_convolve is a float image, with continuous values between 0 and 255. Try this:

In [17]: naive_convolve_float = naive_convolve / 255

In [18]: rank_mean_float = rank_mean / 255

In [19]: plt.imshow(np.abs(naive_convolve_float - rank_mean_float), cmap='magma')
Out[19]: <matplotlib.image.AxesImage at 0x10d098fd0>

Result:


There is a smaller difference also. Internally, filters.rank uses a fancy rolling histogram algorithm with integer data values. This means that the result of the rank_mean is only approximately accurate, essentially to within integer rounding (good enough for most real-world uses), while the convolve2d code gives you an exact value (to within floating point error).

Hope this helps!

Juan.

On 2 Nov 2017, 7:54 PM +1100, Poughon Victor <Victor.Poughon at cnes.fr>, wrote:
> Hello,
>
> I looks like skimage.filters.rank.mean and scipy.signal.convolve2d don't output exactly the same images. When doing:
>
> image = data.coins()
> K = np.ones((11, 11))
>
> rank_mean = rank.mean(image, selem=K)
> naive_convolve = convolve2d(image, K, mode="same") / K.sum()
>
> All output pixel are different, with an absolute difference varying randomly between 0 and 1. Of course there's also a massive difference at the border, but that's expected because convolve2d treats image boundaries differently. But even in the center of the image all pixels are different. I've made a test script with an illustrated output image, you can check it out in this gist:
>
> https://gist.github.com/vpoughon/b4afc76ce5dc681fda9d0550d41359d3
>
> Am I doing something wrong?
>
> Thanks,
>
> Victor Poughon
>
>
>
>
> _______________________________________________
> scikit-image mailing list
> scikit-image at python.org
> https://mail.python.org/mailman/listinfo/scikit-image
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20171104/0adf3366/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2017-11-04 at 12.52.04 am.png
Type: image/png
Size: 54739 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20171104/0adf3366/attachment-0001.png>


More information about the scikit-image mailing list