back to iatexture

textComp

Synopse

The textcomp function computes the mean of descriptors extracted in different orientations (glcm and run length)

  • att = textComp(desc,img_dim=2)
    • Output
      • att: compiled texture descriptors
    • Input
      • desc: raw texture descriptors
      • img_dim: original image dimension

Description

This function computes the mean of the decriptors computed on different orientation, making them orientation invariant

Function Code

 1 from numpy import *
 2 
 3 def textComp(desc,img_dim=2):
 4 
 5     comp_desc = array([])
 6     d = 3 # number os distances uses
 7     if img_dim==3:
 8         q = 13
 9     else:
10         q = 4 # orientations
11 
12     nhist = 12
13     nglcm = 11*d*q
14     nrl = 5*q
15     ngrad = 5
16 
17     ## histogram ##
18     comp_desc = desc[:nhist]
19 
20     ## GLCM ##
21     glcmdesc = desc[nhist:nhist+nglcm]# 11 descriptors to each distance and each orientation
22     for i in xrange(d): # distances
23         glcmd = glcmdesc[i*11*q:(i+1)*11*q] # all glcm descriptors of distance i
24         aux = 0
25         for j in xrange(q):
26             aux += (glcmd[j*11:(j+1)*11])/q # mean of all orientations on distance i
27         comp_desc = concatenate((comp_desc,aux))
28     ## RL ##
29     rldesc = desc[nhist+nglcm:nhist+nglcm+nrl] # rl corresponds to the descriptors after glcm + 5 descriptors*number_of_orientations
30     aux = 0
31     for j in xrange(q):
32         aux += (rldesc[j*5:(j+1)*5])/q # mean of all orientations
33     comp_desc = concatenate((comp_desc,aux))
34 
35     ## Gradient ##
36     comp_desc = concatenate((comp_desc,desc[-ngrad:]))
37     return comp_desc

Examples

2d examples

1 from textComp import textComp
2 
3 from iatexture import *
4 
5 img = adreadgray('/awmedia/www/media/p/LesionMRI/EM/Agnaldo Jose Costa - 808572-1 - 38A/22.png')
6 roi = adreadgray('/awmedia/www/media/p/LesionMRI/EM/Agnaldo Jose Costa - 808572-1 - 38A/Peri_22_1.png')>0
7 
8 desc = textpipe(img,roi,comp = 0)
9 print 'compiled attributes\n', textComp(desc)
compiled attributes
[  9.22777778e+01   1.88654784e+03  -1.05601415e+00   1.64170412e-01
   2.00000000e+00   4.00000000e+00   1.05000000e+02   1.32000000e+02
   1.56000000e+02   1.79258011e+00   2.00000000e+00   1.05000000e+02
   9.36060901e-03   2.12785961e+02   8.42725687e-01   8.76605160e+02
   9.67905022e-02   2.15432718e+02   3.28035832e+03   1.84819974e+00
   2.03362636e+00   8.15496400e+01   1.39833910e+00   1.09951181e-02
   4.88204221e+02   5.99658908e-01   7.29528019e+02   6.13381291e-02
   2.21161461e+02   2.40482852e+03   1.77616698e+00   1.96260854e+00
   1.75319481e+02   1.52215987e+00   1.35759615e-02   7.24066280e+02
   3.99139590e-01   6.90440481e+02   2.82647311e-02   2.23041520e+02
   1.93056811e+03   1.69214204e+00   1.87579541e+00   2.27372278e+02
   1.51810298e+00   1.32983577e+02   2.66427489e+00   1.08055809e+00
   9.79860476e-01   9.73958333e-01   2.53484745e+01   1.66903118e+02
   5.37502239e-01   2.33356852e-01   1.00000000e+00]

3d examples

1 f = array([[[1,2,2,0,0,1],[0,0,1,2,2,1],[1,1,0,0,0,2],[1,1,1,2,2,2],[1,1,2,2,0,0]],
2          [[1,2,2,0,0,1],[0,0,1,2,2,1],[1,1,0,0,0,2],[1,1,1,2,2,2],[1,1,2,2,0,0]],
3          [[1,2,2,0,0,1],[0,0,1,2,2,1],[1,1,0,0,0,2],[1,1,1,2,2,2],[1,1,2,2,0,0]]], dtype=uint8)
4 desc = textpipe(f,comp=0)
5 print 'compiled attributes\n', textComp(desc,img_dim=len(f.shape))
compiled attributes
[  1.03333333e+00   6.32222222e-01  -5.95309703e-02  -1.41606308e+00
   0.00000000e+00   0.00000000e+00   1.00000000e+00   2.00000000e+00
   2.00000000e+00   4.75671184e-01   1.00000000e+00   1.00000000e+00
   1.66945299e-01   1.40384615e+00  -7.51535280e-02   6.50816453e-01
   6.29000000e-01   4.07743590e+00   1.21241197e+00   5.50482697e-01
   8.28618405e-01   5.75451282e-01   4.23865459e-01   1.74729345e-01
   1.30769231e+00   4.43114772e-02   6.55170940e-01   6.06153846e-01
   4.00769231e+00   1.36138177e+00   6.14325421e-01   8.16957586e-01
   4.51039886e-01   3.92139224e-01   6.52136752e-02   4.11538462e-01
   6.60198018e-01   1.84615385e-01   1.71153846e-01   1.29358974e+00
   3.44423077e-01   1.65144172e-01   2.19476777e-01   1.10235043e-01
   1.09402669e-01   4.44453697e+01   2.26169829e+01   2.55163603e+00
   7.45719231e-01   7.45299145e-01   1.64624362e+00   8.17659720e-01
  -3.82476247e-01  -7.15635781e-01   8.61111111e-01]