# Shape and size filtering

In this example, we use size and shape criteria to segment the interior of the carotid artery wall. We use area, bounding-box, eccentricty, rectangularity ratio to obtain the segmentation result.

``` 1 import numpy as np
2 import iamxt
3 import time
4
7
8 img_neg = 255-img
10
11 #Filtering thresholds
12 a_min,a_max = 100,300
13 dx_max,dy_max = 22,22
14 rr_max = 0.5
15 ar_min = 0.75
16 ecc_min = 0.7
17 rr_min = 0.55
18
19 Bc = np.ones((3,3),dtype = bool)
20 Bc[1,:] = True
21 Bc[:,1] = True
22 t = time.time()
23 #Building the min-tree
24 mxt = iamxt.MaxTreeAlpha(img_neg,Bc)
25
26 #Area filtering
27 area = mxt.node_array[3,:]
28 mxt.contractDR(np.logical_and(area>a_min,area< a_max))
29 img2_neg = mxt.getImage()
30 adshow(img2_neg,"Only nodes with %d < area < %d" %(a_min,a_max))
31
32 #Bounding-box filtering
33 xmin,xmax = mxt.node_array[6,:],mxt.node_array[7,:]
34 ymin,ymax = mxt.node_array[9,:],mxt.node_array[10,:]
35 dx = xmax - xmin
36 dy = ymax - ymin
37
38 mxt.contractDR(np.logical_and(dy<dy_max,dx< dx_max))
39 img3_neg = mxt.getImage()
40 adshow(img3_neg,"Only nodes with dx < %d and dy < %d" %(dx_max,dy_max))
41
42 #Aspect ratio filtering
43 xmin,xmax = mxt.node_array[6,:],mxt.node_array[7,:]
44 ymin,ymax = mxt.node_array[9,:],mxt.node_array[10,:]
45 AR = np.asarray([xmax-xmin,ymax - ymin], dtype = float)
46 AR = 1.0*AR.min(axis = 0)/AR.max(axis = 0)
47 mxt.contractDR(AR>ar_min)
48 img4_neg = mxt.getImage()
49 adshow(img4_neg,"Only nodes with aspect ratio > %f" %ar_min)
50
51 L1,L2,ecc = mxt.computeEccentricity()
52 mxt.contractDR(ecc>ecc_min)
53 img5_neg = mxt.getImage()
54 adshow(img5_neg,"Only nodes with eccentricity > %f" %ecc_min)
55
56 rr = mxt.computeRR()
57 mxt.contractDR(rr>rr_min)
58 img6_neg = mxt.getImage()
59 adshow(img6_neg,"Only nodes with rectangularity ratio > %f" %rr_min)
```

# Do it yourself

Use size and shape criteria to segment the carotid wall.

```1 mxt = iamxt.MaxTreeAlpha(img_neg,Bc)