Re: GLCM with scikit-image
I wouldn't worry too much about the warning. Whenever you convert an image from floating point (64 bits per pixel) to bytes (8 bits per pixel), there may be a loss of precision. The lines: im = skimage.img_as_ubyte(im) im /= 32 are just a quick way to scale the pixel intensities to have 8 different levels. The first step converts the image from floats to bytes (this is where you get the warning). We now have an image with 256 levels (from 0 to 255). After dividing by 32, there are only 8 possible levels (from 0 to 7). It is likely that matlab use a different procedure for converting from a floating point image to an image with only 8 levels. The [0][0] is to specify which offset you want. The first 0 gives the index for the distances, and the second is the index for the angles. In this example, we are only computing one offset (distance=1 and angle=0). However, in many real-life applications you will want to compute the statistics for a number of offsets to capture differences in scale and orientation. Neil On Monday, 8 July 2013 14:00:11 UTC+1, ely...@mail.com wrote:
Hi,
Thanks a lot for the reply.
Indeed graycoprops normalizes the gray-level co-occurrence matrix:
“graycoprops normalizes the gray-level co-occurrence matrix (GLCM) so that the sum of its elements is equal to 1. Each element (r,c) in the normalized GLCM is the joint probability occurrence of pixel pairs with a defined spatial relationship having gray level values r and c in the image. graycoprops uses the normalized GLCM to calculate properties.” ( http://www.mathworks.co.uk/help/images/ref/graycoprops.html)
The modified script: import skimage
from skimage.io import imread from skimage.feature import greycomatrix from skimage.feature import greycoprops
im = imread('C:/Users/Asher_dell/Desktop/ImgTemp/python.jpg', as_grey=True)
im = skimage.img_as_ubyte(im) im /= 32 g = skimage.feature.greycomatrix(im, [1], [0], levels=8, symmetric=False, normed=True)
contrast= skimage.feature.greycoprops(g, 'contrast')[0][0] energy= skimage.feature.greycoprops(g, 'energy')[0][0] homogeneity= skimage.feature.greycoprops(g, 'homogeneity')[0][0] correlation=skimage.feature.greycoprops(g, 'correlation')[0][0] dissimilarity=skimage.feature.greycoprops(g, 'dissimilarity')[0][0] ASM=skimage.feature.greycoprops(g, 'ASM')[0][0]
print('contrast is: ', contrast) print('energy is: ', energy) print('homogeneity is: ', homogeneity) print('correlation is: ', correlation) print('dissimilarity is: ', dissimilarity) print('ASM is: ', ASM)
Output: skimage.dtype_converter: WARNING: Possible precision loss when converting from float64 to uint8 contrast is: 0.301542207792 energy is: 0.29069020973 homogeneity is: 0.883463991917 correlation is: 0.971624675221 dissimilarity is: 0.243464091878 ASM is: 0.0845007980331
Based on the output I have few more questions on the modified script: - Does the "skimage.dtype_converter: WARNING: Possible precision loss when converting from float64 to uint8" means that the output values are wrong? - Can you please explain me why you use these lines:
im = skimage.img_as_ubyte(im) im /= 32 - Why do you use the [0][0] when you call skimage.feature.greycoprops (e.g.,skimage.feature.greycoprops(g, 'contrast')[0][0])?
Thanks a lot again.
Cheers and thanks a lot for the help.
How can I cancel the "skimage.dtype_converter: WARNING: Possible precision loss when converting from float64 to uint8" warning in the output?, is it possible?
On Wed, Jul 17, 2013 at 4:56 AM, <wishmen@walla.co.il> wrote:
How can I cancel the "skimage.dtype_converter: WARNING: Possible precision loss when converting from float64 to uint8" warning in the output?, is it possible?
The warning messages are a bit annoying. We're discussing ways of making it less annoying here: https://github.com/scikit-image/scikit-image/issues/543 For now you can just disable that logger: from skimage.util import dtype dtype.log.disabled = True Cheers, -Tony
Is there a way/command to avoiding printing out the warning message "skimage.dtype_converter: WARNING: Possible precision loss when converting from float64 to uint8" in the output?
participants (4)
-
elyraz@mail.com
-
Neil
-
Tony Yu
-
wishmen@walla.co.il