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?
De : scikit-image [email@example.com] de la part de Juan Nunez-Iglesias [firstname.lastname@example.org]
Envoyé : vendredi 3 novembre 2017 14:56
À : Mailing list for scikit-image (http://scikit-image.org)
Objet : Re: [scikit-image] Observed difference between skimage.filters.rank.mean and scipy.signal.convolve2d
The biggest problem is that you’re getting bitten by datatypes. Please read the following document:
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 : naive_convolve_float = naive_convolve / 255
In : rank_mean_float = rank_mean / 255
In : plt.imshow(np.abs(naive_convolve_float - rank_mean_float), cmap='magma')
Out: <matplotlib.image.AxesImage at 0x10d098fd0>
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!
On 2 Nov 2017, 7:54 PM +1100, Poughon Victor <Victor.Poughon@cnes.fr>, wrote:
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:
Am I doing something wrong?
scikit-image mailing list