x =np.array([7, 2, 0, 8, 8, 3, 2, 2, 0, 5, 3, 3, 4, 8, 7, 0])
w=5
s = np.array([x,]*w,dtype=np.uint8).transpose()
array([
[7, 7, 7, 7, 7],
[2, 2, 2, 2, 2],
[0, 0, 0, 0, 0],
[8, 8, 8, 8, 8],
[8, 8, 8, 8, 8],
[3, 3, 3, 3, 3],
[2, 2, 2, 2, 2],
[2, 2, 2, 2, 2],
[0, 0, 0, 0, 0],
[5, 5, 5, 5, 5],
[3, 3, 3, 3, 3],
[3, 3, 3, 3, 3],
[4, 4, 4, 4, 4],
[8, 8, 8, 8, 8],
[7, 7, 7, 7, 7],
[0, 0, 0, 0, 0]], dtype=uint8)
Below I test rolling:
test = np.roll(s[:, :], -5)
test
array([[2, 2, 2, 2, 2],
[0, 0, 0, 0, 0],
[8, 8, 8, 8, 8],
[8, 8, 8, 8, 8],
[3, 3, 3, 3, 3],
[2, 2, 2, 2, 2],
[2, 2, 2, 2, 2],
[0, 0, 0, 0, 0],
[5, 5, 5, 5, 5],
[3, 3, 3, 3, 3],
[3, 3, 3, 3, 3],
[4, 4, 4, 4, 4],
[8, 8, 8, 8, 8],
[7, 7, 7, 7, 7],
[0, 0, 0, 0, 0],
[7, 7, 7, 7, 7]], dtype=uint8)
Now I roll and pass top 5 rows to greycomatrix:
levels = 9# this rolls the 2D array up one row at a time, each time calculating GLCM on the top 5x5 elements
out = []
counter = 0
while counter < np.shape(s)[0]:
s = np.roll(s[:, :], -5)
glcm = greycomatrix(s[:5,:], [1], [np.pi/2], levels = levels, symmetric = True, normed = True)
out.append(glcm)
counter +=1
But unfortunately output is a 5D array:
print np.shape(out)
(16, 9, 9, 1, 1)
I tried to recast into a 4D array to pass to greycoprops in different ways, but unsuccessfully.
With:
out1 = np.array(out).reshape((16, 9, 9, 1))
np.shape(out1)
(16, 9, 9, 1)
diss = greycoprops(out1, 'dissimilarity')I get this error:
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-15-a88f05b0e3e2> in <module>()
----> 1 diss = greycoprops(out1, 'dissimilarity')
2 diss
/Users/matteoniccoli/anaconda2/lib/python2.7/site-packages/skimage/feature/texture.pyc in greycoprops(P, prop)
187
188 (num_level, num_level2, num_dist, num_angle) = P.shape
--> 189 assert num_level == num_level2
190 assert num_dist > 0
191 assert num_angle > 0
AssertionError:It may be that I do not really understand the shape of the output, and the requirements of greycoprops.
print np.shape(np.array(out))
print np.shape(np.array(out[0][:][:][:][:]))
print np.shape(np.array(out[:][0][:][:][:]))
print np.shape(np.array(out[:][:][0][:][:]))
print np.shape(np.array(out[:][:][:][0][:]))
print np.shape(np.array(out[:][:][:][:][0]))(16, 9, 9, 1, 1)
(9, 9, 1, 1)
(9, 9, 1, 1)
(9, 9, 1, 1)
(9, 9, 1, 1)
(9, 9, 1, 1)Can anybody suggest a way to make this work?Thanks
diss = []
for i in np.arange(np.shape(out)[0]):
ds = greycoprops(out[i], 'dissimilarity')
diss.append(ds)
diss
[array([[ 3.75]]),
array([[ 3.5]]),
array([[ 1.5]]),
array([[ 2.]]),
array([[ 2.]]),
array([[ 2.25]]),
array([[ 2.25]]),
array([[ 2.]]),
array([[ 1.75]]),
array([[ 1.5]]),
array([[ 3.25]]),
array([[ 4.75]]),
array([[ 5.]]),
array([[ 5.25]]),
array([[ 5.5]]),
array([[ 3.75]])]