Sorry, below I meant to write:"Say I have an 16x1 1D array. I make 5 copies 
of it to get a 16x5 2D array..."

On Friday, December 16, 2016 at 11:13:20 AM UTC-7, Matteo wrote:
>
> I am very new to GLCM.
>
> I have some 1D array I would like to calculate dissimilarity in the 
> vertical direction, so I am trying to trick scikit-image by converting my 
> 1D array into 2D.
>
> Say I have an 16x5 2D array. I make 5 copies of it to get a 16x5 array. I 
> want to pass rows 0-4, then rows 5-9 and so on to run greycomatrix, by 
> just lookign at the vertical direction,  append to output, and ultimately 
> calculate dissimilarity.
>
> Example array:
>
>     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
>
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send an email to scikit-image@googlegroups.com.
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/scikit-image/4f02799e-53fb-4a53-9031-c5c4b247310a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to