GLCM calculation using scikit-learn. Error when using greycomatrix

Juan Nunez-Iglesias jni.soma at gmail.com
Sun Sep 18 20:03:23 EDT 2016


Hi Ioannis,

Unfortunately the levels keyword is used as a hint to the function about
the number of levels when the image is uint16, because the possible number
of levels is huge. But if you want to convert the image to those levels,
you have to do it manually. I suggest you look at the "rescale_intensity"
function:

http://scikit-image.org/docs/dev/api/skimage.exposure.html#skimage.exposure.rescale_intensity

and process your image before passing it to the glcm function.

I hope this helps! Keep pinging if you have more questions. =)

Juan.

On Sun, Sep 18, 2016 at 4:57 AM, <ioannisgkan259 at gmail.com> wrote:

> Hello everyone,
>
> I am using a SAR image (16-bit) and trying to implement GLCM algorithm
> using sciki-learn. When trying to calculate the GLCM using greycomatrix i
> get the following error:
>
> assert image.max() < levels. It says that the maximum value of the image intensity must be less than the number of grey levels.
> Because the SAR image is really big, i want to reduce the calculation time by reducing the levels to 8.
> Even if i remove the parameter 'level=8' when using greycomatrix, still gives me the same error
>
> My code is the following:
>
> from skimage.feature import greycomatrix, greycoprops
> import numpy as np
> from skimage import data
> import rasterio
>
> path = 'C:\Users\GLCM_implementation\glasgow.tif'
>
> with rasterio.open(path, 'r') as src:
>     import_file = src.read()
>     img = import_file[0,:,:] #i need only the two dimentions (height, width)
>     print img.shape
>
>
> #calculate the GLCM specifying the distance, direction(4 directions) and number of grey levels
> GLCM = greycomatrix(img, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4],levels=8, symmetric=False, normed=True)
> #list(GLCM[:,:,0,2])
>
>
> #Calculate texture statistics
> contrast = greycoprops(GLCM, 'contrast')
>
> dissimilarity = greycoprops(GLCM, 'dissimilarity')
>
> homogeneity = greycoprops(GLCM, 'homogeneity')
>
> energy = greycoprops(GLCM, 'energy')
>
> correlation = greycoprops(GLCM, 'correlation')
>
> ASM = greycoprops(GLCM, 'ASM')
>
>
>
> Error message:
>
>  101     image = np.ascontiguousarray(image)    102     assert image.min() >= 0--> 103     assert image.max() < levels    104     image = image.astype(np.uint8)    105     distances = np.ascontiguousarray(distances, dtype=np.float64)
> AssertionError:
>
>
> I would appreciate any help.
> Thank you in advance
>
> Ioannis
>
> --
> You received this message because you are subscribed to the Google Groups
> "scikit-image" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scikit-image+unsubscribe at googlegroups.com.
> To post to this group, send email to scikit-image at googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/
> msgid/scikit-image/520f5f2b-4750-4b56-a40b-28b938b750d8%40googlegroups.com
> <https://groups.google.com/d/msgid/scikit-image/520f5f2b-4750-4b56-a40b-28b938b750d8%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20160919/0ab4a6cb/attachment.html>


More information about the scikit-image mailing list