Haralick features over an image

147 views
Skip to first unread message

Solimyr

unread,
Oct 2, 2015, 11:40:12 AM10/2/15
to pythonvision
Dear All,

I was looking at a fast implementation of the Haralick features. At the moment I'm using scikit to compute the haralick features over an image. I would try to use mahotas but I have some implementation problem. I would really like to avoid the 'for' loop over the two dimensions of the image. 

My idea was to compute  a rolling window using the 'strides' tricks, and then compute the Haralick features. Using the code:

a = np.arange(16).reshape((4,4))
b = rolling_window(a,(3,3))

>>>print b
array([[[[ 0,  1,  2],
         [ 4,  5,  6],
         [ 8,  9, 10]],

        [[ 1,  2,  3],
         [ 5,  6,  7],
         [ 9, 10, 11]]],


       [[[ 4,  5,  6],
         [ 8,  9, 10],
         [12, 13, 14]],

        [[ 5,  6,  7],
         [ 9, 10, 11],
         [13, 14, 15]]]])

Once I have 'b', I would like to compute the haralick features for each windows. I have tried something like this:

>>> c[:,:] = mh.features.haralick(b[:,:])

Traceback (most recent call last):
  File "<pyshell#10>", line 1, in <module>
    c[:,:] = mh.features.haralick(b[:,:])
  File "C:\Python27\lib\site-packages\mahotas\features\texture.py", line 110, in haralick
    raise ValueError('mahotas.texture.haralick: Can only handle 2D and 3D images.')
ValueError: mahotas.texture.haralick: Can only handle 2D and 3D images.

I can manage using two 'for' loop but I will have no time advantage...Maybe it is better to go directly straight on and manage it using cython. 

What do you think?
Thanks!

Luis Pedro Coelho

unread,
Oct 4, 2015, 9:03:40 AM10/4/15
to python...@googlegroups.com
> I can manage using two 'for' loop but I will have no time
> advantage...Maybe
> it is better to go directly straight on and manage it using cython.

The overhead of Python is probably not relevant as computing the
features takes enough time that it'll overwhelm the python/cython
benefits.

To get significantly better results, you'd need some fancy algorithm to
update the co-occurrence matrices as you shift your window instead of
recomputing from scratch each time.

Cheers,

--
Luis Pedro Coelho | EMBL | http://luispedro.org
My blog: http://metarabbit.wordpress.com
Reply all
Reply to author
Forward
0 new messages