##### Contents

back to iatexture

# Function textpipe

## Synopse

The textpipe function computes a set of texture descriptors given an image, roi and a quantization rate

• att = textpipe(img,roi,rate=8,comp = 1)
• Output
• att: texture attributes. [0-11] Histogram attrs, [12-44] GLCM attrs, [45-49] RL attrs, [50-54] Gradient attrs.
• Input
• img: input image
• roi: binary ROI
• rate: quantization rate
• comp: =1 to compile the attributes by computing the mean of different orientation attributes; comp = 0 to raw texture attributes

## Description

The textpipe function computes a set of texture descriptors given an image, roi and a quantization rate. The output can be the raw texture attributes or a compilation version, in which it is computed the mean of different orientations.

## Function Code

``` 1 from iatexture import *
2 import ia870
3 import numpy as np
4
5 import multiprocessing as mp
6 import psutil
7
8 def textpipe(f,roi=[],rate=8,comp=1,bb_use=1):
9
10     desc = np.array([])
11
12     d = [1,2,3] # distances
13     q = [0,np.pi/4,np.pi/2,3*np.pi/4] # theta
14
15     img = f.copy()# do not process the original image
16     if len(img.shape) == 3:
17         ## parameter ##
18         o = np.array([[0,0,1],[0,1,-1],[0,1,0],[0,1,1],[1,0,-1],[1,0,0],[1,0,1],[1,1,0],[1,-1,0],[1,1,-1],[1,-1,1],[1,1,1],[1,-1,-1]],dtype=np.int32) # offsets
19         p = [0,np.pi/4,np.pi/2,3*np.pi/4] # phi
20
21         ## quantization ##
22         for i in xrange(img.shape[0]):
23             img[i] = quantimg(img[i],rate) # image quantization slice by slice
24         img = img.astype('uint8')
25         ## bb ##
26         if roi!= [] and bb_use:
27             bb = np.zeros((6))
28             aux = np.argwhere(roi>0)
29             bb[0] = aux[:,0].min()-3 # larger bb
30             bb[1] = aux[:,0].max()+3
31             bb[2] = aux[:,1].min()-3
32             bb[3] = aux[:,1].max()+3
33             bb[4] = aux[:,2].min()-3
34             bb[5] = aux[:,2].max()+3
35             img = img[bb[0]:bb[1],bb[2]:bb[3],bb[4]:bb[5]]
36             roi = roi[bb[0]:bb[1],bb[2]:bb[3],bb[4]:bb[5]]
37
38
39     else:
40         ## parameters ##
41
42         o = np.array([[0,1],[1,1],[1,0],[1,-1]],dtype=np.int32) # offsets
43         p = [2] # phi is not used on 3D cases (this value can be any value different of zero)
44
45         ## quantization ##
46         img = quantimg(img,rate).astype('uint8') # image quantization
47
48         ## bb ##
49         if roi != [] and bb_use:
50             bb = ia870.iablob(roi,'boundingbox','data')[0]
51             bb = bb+[-3,-3,+3,+3]
52             img = img[bb[1]:bb[3],bb[0]:bb[2]]
53             roi = roi[bb[1]:bb[3],bb[0]:bb[2]]
54
55     ## histogram ##
56     _,desc = histstat(img,roi)
57     ## GLCM ##
58     for d_i in d:
59         for o_i in o:
60             _,glcmDesc = glcmdesc(img,offset = o_i*d_i,mask=roi)
61             desc = np.concatenate((desc,glcmDesc))
62     ## RL ##
63     for q_i in q:
64         for p_i in p:
65             if p_i != 0 or p_i==0 and q_i==0:#if theta=0, phi must be zero. There is no (45,0),(90,0),(135,0)
67                 desc = np.concatenate((desc,rlDesc))
71
72     if comp ==1:
73         return textComp(desc,img_dim=len(img.shape)) # texture attributes compilation
74     else:
75         return desc
```

## 2D Example

``` 1 from iatexture import *
2 import ia870
3 from textpipe import textpipe
4 import time
5
8
9 aux = ia870.ialabel(roi)
10 aux = ia870.iablob(aux,'area')
11 roi2 = aux>aux.max()-1 # ensure that it is only one lesion, use the biggest blob, avoid manual segmentation mistakes.
12
13 rate = 8
14
17 print 'texture attributes = '
18 desc = textpipe(img,roi,rate,comp=1)
19 print desc
```
```texture 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]
```
```1 import homemariana.att_lib as att_lib
2
3 # compare with previous library result - difference (we add 3 new histogram attributes)
4 desc2 = att_lib.textureAtt(img,roi)
5 desc2 = att_lib.textComp(desc2)
6 print desc2
7 #print desc2-desc[]
```
```[  9.32777778e+01   1.88654784e+03  -1.05601415e+00   1.64170412e-01
3.00000000e+00   5.00000000e+00   1.06000000e+02   1.33000000e+02
1.57000000e+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.76805220e-02   9.07233714e+02
2.81980397e-01   6.91957235e+02   3.64073875e-02   2.22437166e+02
1.71163589e+03   1.63575637e+00   1.77287402e+00   2.70970412e+02
1.50938182e+00   2.58030990e-02   1.06791322e+03   3.03462646e-01
6.85654281e+02   2.89199569e-02   2.20518887e+02   1.61760978e+03
1.53256119e+00   1.64217947e+00   3.09931355e+02   1.43956474e+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 example

### Numerical example

```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 'desc:\n',desc
```
```desc:
[  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.48800000e-01   8.00000000e-01   4.14324508e-01   6.40000000e-01
7.44000000e-01   4.08000000e+00   1.91360000e+00   6.84676004e-01
8.77528010e-01   4.86400000e-01   4.09864962e-01   1.80000000e-01
1.70000000e+00  -3.10834936e-01   6.90000000e-01   5.70000000e-01
4.10000000e+00   8.90000000e-01   4.81953330e-01   7.83792310e-01
7.00000000e-01   4.76015993e-01   1.52777778e-01   1.83333333e+00
-4.70752089e-01   6.23263889e-01   5.33333333e-01   4.08333333e+00
6.59722222e-01   4.81291814e-01   8.53732752e-01   6.59722222e-01
4.74853377e-01   1.30000000e-01   1.75000000e+00  -2.91736105e-01
6.47500000e-01   5.45000000e-01   4.05000000e+00   9.47500000e-01
5.78946810e-01   9.17069623e-01   6.47500000e-01   4.76015993e-01
1.48800000e-01   8.00000000e-01   4.14324508e-01   7.13600000e-01
7.44000000e-01   4.08000000e+00   1.91360000e+00   6.84676004e-01
8.77528010e-01   4.86400000e-01   4.09864962e-01   3.35555556e-01
0.00000000e+00   1.00000000e+00   6.32222222e-01   1.00000000e+00
4.06666667e+00   2.52888889e+00   4.75671184e-01   4.75671184e-01
0.00000000e+00  -9.64327467e-17   1.48800000e-01   8.00000000e-01
4.14324508e-01   6.40000000e-01   7.44000000e-01   4.08000000e+00
1.91360000e+00   6.84676004e-01   8.77528010e-01   4.86400000e-01
4.09864962e-01   1.52777778e-01   1.83333333e+00  -4.70752089e-01
6.23263889e-01   5.33333333e-01   4.08333333e+00   6.59722222e-01
4.81291814e-01   8.53732752e-01   6.59722222e-01   4.74853377e-01
1.52777778e-01   1.83333333e+00  -4.70752089e-01   6.23263889e-01
5.33333333e-01   4.08333333e+00   6.59722222e-01   4.81291814e-01
8.53732752e-01   6.59722222e-01   4.74853377e-01   1.80000000e-01
1.70000000e+00  -3.10834936e-01   6.90000000e-01   5.70000000e-01
4.10000000e+00   8.90000000e-01   4.81953330e-01   7.83792310e-01
7.00000000e-01   4.76015993e-01   1.80000000e-01   1.70000000e+00
-3.10834936e-01   6.00000000e-01   5.70000000e-01   4.10000000e+00
8.90000000e-01   4.81953330e-01   7.83792310e-01   7.00000000e-01
4.76015993e-01   1.30000000e-01   1.75000000e+00  -2.91736105e-01
6.47500000e-01   5.45000000e-01   4.05000000e+00   9.47500000e-01
5.78946810e-01   9.17069623e-01   6.47500000e-01   4.76015993e-01
1.30000000e-01   1.75000000e+00  -2.91736105e-01   6.90000000e-01
5.45000000e-01   4.05000000e+00   9.47500000e-01   5.78946810e-01
9.17069623e-01   6.47500000e-01   4.76015993e-01   1.70000000e-01
1.75000000e+00  -3.11708219e-01   5.47500000e-01   4.85000000e-01
4.15000000e+00   9.27500000e-01   5.89049369e-01   8.56863624e-01
4.27500000e-01   4.23250456e-01   1.66666667e-01   1.00000000e+00
1.63615882e-01   7.43055556e-01   6.00000000e-01   4.00000000e+00
1.33333333e+00   6.27636253e-01   8.40620619e-01   3.05555556e-01
3.57840941e-01   1.41975309e-01   1.16666667e+00   9.78653497e-02
6.54320988e-01   6.83333333e-01   3.94444444e+00   1.38580247e+00
6.27963205e-01   8.74722300e-01   6.45061728e-01   4.50201807e-01
1.66666667e-01   1.75000000e+00  -9.10899447e-02   6.38888889e-01
5.25000000e-01   3.91666667e+00   1.40972222e+00   6.58870937e-01
8.09385935e-01   5.76388889e-01   4.67976767e-01   1.70000000e-01
1.75000000e+00  -3.11708219e-01   7.90000000e-01   4.85000000e-01
4.15000000e+00   9.27500000e-01   5.89049369e-01   8.56863624e-01
4.27500000e-01   4.23250456e-01   3.35555556e-01   0.00000000e+00
1.00000000e+00   6.32222222e-01   1.00000000e+00   4.06666667e+00
2.52888889e+00   4.75671184e-01   4.75671184e-01   0.00000000e+00
-9.64327467e-17   1.70000000e-01   1.75000000e+00  -3.11708219e-01
5.47500000e-01   4.85000000e-01   4.15000000e+00   9.27500000e-01
5.89049369e-01   8.56863624e-01   4.27500000e-01   4.23250456e-01
1.41975309e-01   1.16666667e+00   9.78653497e-02   6.54320988e-01
6.83333333e-01   3.94444444e+00   1.38580247e+00   6.27963205e-01
8.74722300e-01   6.45061728e-01   4.50201807e-01   1.41975309e-01
1.16666667e+00   9.78653497e-02   6.08024691e-01   6.83333333e-01
3.94444444e+00   1.38580247e+00   6.27963205e-01   8.74722300e-01
6.45061728e-01   4.50201807e-01   1.66666667e-01   1.00000000e+00
1.63615882e-01   7.43055556e-01   6.00000000e-01   4.00000000e+00
1.33333333e+00   6.27636253e-01   8.40620619e-01   3.05555556e-01
3.57840941e-01   1.66666667e-01   1.00000000e+00   1.63615882e-01
4.09722222e-01   6.00000000e-01   4.00000000e+00   1.33333333e+00
6.27636253e-01   8.40620619e-01   3.05555556e-01   3.57840941e-01
1.66666667e-01   1.75000000e+00  -9.10899447e-02   6.38888889e-01
5.25000000e-01   3.91666667e+00   1.40972222e+00   6.58870937e-01
8.09385935e-01   5.76388889e-01   4.67976767e-01   1.66666667e-01
1.75000000e+00  -9.10899447e-02   9.09722222e-01   5.25000000e-01
3.91666667e+00   1.40972222e+00   6.58870937e-01   8.09385935e-01
5.76388889e-01   4.67976767e-01   2.08888889e-01   1.93333333e+00
-5.67595761e-01   4.00000000e-01   4.33333333e-01   4.06666667e+00
5.95555556e-01   4.71291426e-01   7.19431013e-01   3.28888889e-01
3.70555752e-01   2.77777778e-01   8.33333333e-01   3.29384355e-17
6.66666667e-01   5.83333333e-01   4.16666667e+00   8.05555556e-01
4.39247291e-01   5.77464587e-01   1.38888889e-01   1.95676247e-01
1.38888889e-01   1.58333333e+00  -2.82842712e-01   6.66666667e-01
5.08333333e-01   4.25000000e+00   8.54166667e-01   5.58527605e-01
8.78494582e-01   4.09722222e-01   4.16755410e-01   2.22222222e-01
1.00000000e+00   4.33012702e-01   6.66666667e-01   7.00000000e-01
4.33333333e+00   2.22222222e+00   6.77807918e-01   6.77807918e-01
5.55555556e-01   4.39247291e-01   0.00000000e+00   0.00000000e+00
1.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
0.00000000e+00  -0.00000000e+00  -0.00000000e+00   0.00000000e+00
-0.00000000e+00   0.00000000e+00   0.00000000e+00   1.00000000e+00
0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
-0.00000000e+00  -0.00000000e+00   0.00000000e+00  -0.00000000e+00
0.00000000e+00   0.00000000e+00   1.00000000e+00   0.00000000e+00
0.00000000e+00   0.00000000e+00   0.00000000e+00  -0.00000000e+00
-0.00000000e+00   0.00000000e+00  -0.00000000e+00   0.00000000e+00
0.00000000e+00   1.00000000e+00   0.00000000e+00   0.00000000e+00
0.00000000e+00   0.00000000e+00  -0.00000000e+00  -0.00000000e+00
0.00000000e+00  -0.00000000e+00   0.00000000e+00   0.00000000e+00
1.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
0.00000000e+00  -0.00000000e+00  -0.00000000e+00   0.00000000e+00
-0.00000000e+00   0.00000000e+00   0.00000000e+00   1.00000000e+00
0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
-0.00000000e+00  -0.00000000e+00   0.00000000e+00  -0.00000000e+00
0.00000000e+00   0.00000000e+00   1.00000000e+00   0.00000000e+00
0.00000000e+00   0.00000000e+00   0.00000000e+00  -0.00000000e+00
-0.00000000e+00   0.00000000e+00  -0.00000000e+00   0.00000000e+00
0.00000000e+00   1.00000000e+00   0.00000000e+00   0.00000000e+00
0.00000000e+00   0.00000000e+00  -0.00000000e+00  -0.00000000e+00
0.00000000e+00  -0.00000000e+00   0.00000000e+00   0.00000000e+00
1.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
0.00000000e+00  -0.00000000e+00  -0.00000000e+00   0.00000000e+00
-0.00000000e+00   3.00000000e+01   1.00666667e+01   9.00000000e+00
1.11111111e-01   3.33333333e-01   3.00322581e+01   2.11935484e+01
2.45161290e+00   6.90860215e-01   6.88888889e-01   1.83750000e+01
1.68750000e+01   4.00000000e+00   4.58333333e-01   5.33333333e-01
3.00322581e+01   2.11935484e+01   2.45161290e+00   6.90860215e-01
6.88888889e-01   5.52631579e+01   2.53947368e+01   1.60526316e+00
8.77923977e-01   8.44444444e-01   4.39565217e+01   2.33478261e+01
2.08695652e+00   8.24879227e-01   7.66666667e-01   5.52631579e+01
2.53947368e+01   1.60526316e+00   8.77923977e-01   8.44444444e-01
5.52631579e+01   2.54473684e+01   1.60526316e+00   8.77923977e-01
8.44444444e-01   4.39565217e+01   2.36086957e+01   2.08695652e+00
8.24879227e-01   7.66666667e-01   5.52631579e+01   2.54473684e+01
1.60526316e+00   8.77923977e-01   8.44444444e-01   5.76923077e+01
2.60256410e+01   1.46153846e+00   8.84615385e-01   8.66666667e-01
4.50000000e+01   2.40000000e+01   1.75000000e+00   8.12500000e-01
8.00000000e-01   5.76923077e+01   2.60256410e+01   1.46153846e+00
8.84615385e-01   8.66666667e-01   1.64624362e+00   8.17659720e-01
-3.82476247e-01  -7.15635781e-01   8.61111111e-01]
```

### Numerical example with compilation

```1 print 'compiled descriptors\n', textpipe(f,comp=1)
```
```compiled descriptors
[  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]
```