Re: [scikitimage] Observed difference between skimage.filters.rank.mean and scipy.signal.convolve2d
Hi Victor, The biggest problem is that you’re getting bitten by datatypes. Please read the following document: http://scikitimage.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 realworld 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@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
_______________________________________________ scikitimage mailing list scikitimage@python.org https://mail.python.org/mailman/listinfo/scikitimage
Thank you, that makes sense. Your link does not explain why float images are restricted to [1; 1] though? So with my data I can't just do: image = np.array(data.coins(), dtype=np.float) I guess skimage makes an assumption that images are within a fixed range? Best, Victor Poughon ________________________________ De : scikitimage [scikitimagebounces+victor.poughon=cnes.fr@python.org] de la part de Juan NunezIglesias [jni.soma@gmail.com] Envoyé : vendredi 3 novembre 2017 14:56 À : Mailing list for scikitimage (http://scikitimage.org) Objet : Re: [scikitimage] Observed difference between skimage.filters.rank.mean and scipy.signal.convolve2d Hi Victor, The biggest problem is that you’re getting bitten by datatypes. Please read the following document: http://scikitimage.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: [cid:47EBAC9317A4470AA3DEF2C02C973463] 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 realworld 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@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 _______________________________________________ scikitimage mailing list scikitimage@python.org https://mail.python.org/mailman/listinfo/scikitimage
participants (2)

Juan NunezIglesias

Poughon Victor