Hi all,
I’m trying to measure the standard deviation of labelled regions using scikit-image. The documentation unfortunately doesn’t contain the terms “standard deviation” and “variance” and google is also not very helpful. Thus, I’m asking here.
Assume this is our image:
1 2 3
4 5 6
7 8 9
Depending on if you use the equation for a population or a sample of pixels, you can determine a standard deviation of 2.58 or 2.74, respectively. numpy.std
returns the first. So far, so good. But how to do this for multiple labels using skimage.measure.regionprops ? The variance is also known as the second moment and thus, I would expect to find the variance of my image in its moments.
Here is some python code for printing out moments. Again my question: How can I retrieve the standard deviation from these?
import numpy as np
image = np.asarray([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
])
labels = np.asarray([
[1, 1, 1],
[1, 1, 1],
[1, 1, 1]
])
print("numpy standard deviation", np.std(image))
print("numpy variance", np.var(image))
from skimage.measure import regionprops
stats = regionprops(labels, intensity_image=image)
print(stats[0].moments)
print(stats[0].moments_central)
print(stats[0].moments_normalized)
Output:
numpy standard deviation 2.581988897471611
numpy variance 6.666666666666667
[[ 9. 9. 15. 27.]
[ 9. 9. 15. 27.]
[15. 15. 25. 45.]
[27. 27. 45. 81.]]
[[9. 0. 6. 0.]
[0. 0. 0. 0.]
[6. 0. 4. 0.]
[0. 0. 0. 0.]]
[[ nan nan 0.07407407 0. ]
[ nan 0. 0. 0. ]
[0.07407407 0. 0.00548697 0. ]
[0. 0. 0. 0. ]]
Thanks for your help and Merry Christmas btw.!
Cheers,
Robert