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