progAreaDifference

MainPage

Description: This method implements the progressive area difference filter.

Signature: MaxTreeAlpha.progAreaDifference(AD)

Input:
  • AD, int. Area difference threshold.

Output:

C++ Aux Function

OK
1 void prog_area_difference_aux_c(int AD, int DIM1, int *INPLACE_ARRAY1,int DIM1, int *INPLACE_ARRAY1, int DIM1, int *INPLACE_ARRAY1, int DIM1,
2                                 int *INPLACE_ARRAY1, int DIM1, int *INPLACE_ARRAY1);
OK [C/C++ extension is up-to-date]

Python Implementation

 1 import numpy as np
 2 
 3 def progAreaDifference(self, AD):
 4     parent = self.node_array[0, :]
 5     area = self.node_array[3, :]
 6     to_keep = np.zeros(self.node_array.shape[-1], np.int32)
 7     visited = np.zeros_like(to_keep)
 8     leaves = (np.nonzero(self.node_array[1,:] == 0)[0]).astype(np.int32)
 9     self.prog_area_difference_aux(AD,parent,area,to_keep,visited,leaves)
10     self.contractDR(to_keep>0)
11     return self
 1 import numpy as np
 2 import ia636 as ia
 3 from iamxt import MaxTreeAlpha
 4 from time import time
 5 
 6 f = adreadgray('homeluistavares/seg_icip2/placa_college_st.png')
 7 adshow(f,'original image')
 8 Bc = np.ones((3,3), dtype=np.bool)
 9 mxt = MaxTreeAlpha(f, Bc)
10 V = mxt.computeVolume()
11 Vext = mxt.computeExtinctionValues(V,"volume")
12 mxt.extinctionFilter(Vext, 200)
13 print 'number of nodes before filtering: ',  mxt.node_array.shape[-1]
14 AD = 15 # interactive parameter
15 mxt.progAreaDifference(AD)
16 adshow(mxt.getImage(),'filtering result')
17 print 'number of nodes after filtering: ',  mxt.node_array.shape[-1]
number of nodes before filtering:  2978
number of nodes after filtering:  822

original image

filtering result

Example MRI

 1 f = adreadgray('homeluistavares/luistavares_app_seg3/sagittal-agnalda.png')
 2 adshow(f,'original image')
 3 Bc = np.ones((3,3), dtype=np.bool)
 4 mxt = MaxTreeAlpha(f, Bc)
 5 V = mxt.computeVolume()
 6 Vext = mxt.computeExtinctionValues(V,"volume")
 7 mxt.extinctionFilter(Vext, 200)
 8 print 'number of nodes before filtering: ',  mxt.node_array.shape[-1], ' | NL: ', np.count_nonzero(mxt.node_array[1,:])
 9 
10 AD = 11 # interactive parameter
11 mxt.areaDifference(AD)
12 print 'number of nodes after filtering: ',  mxt.node_array.shape[-1], ' | NL: ', np.count_nonzero(mxt.node_array[1,:])
13 adshow(mxt.getImage(),'after area difference filter, AD=%d' % AD)
number of nodes before filtering:  3441  | NL:  3241
number of nodes after filtering:  1425  | NL:  1245

original image

after area difference filter, AD=11

Example - Cameraman

 1 f = adreadgray('cameraman.tif')
 2 adshow(f,'original image')
 3 Bc = np.ones((3,3), dtype=np.bool)
 4 mxt = MaxTreeAlpha(f, Bc)
 5 V = mxt.computeVolume()
 6 Vext = mxt.computeExtinctionValues(V,"volume")
 7 mxt.extinctionFilter(Vext, 200)
 8 print 'number of nodes before filtering: ',  mxt.node_array.shape[-1], ' | NL: ', np.count_nonzero(mxt.node_array[1,:])
 9 
10 AD = 10 # interactive parameter
11 mxt.areaDifference(AD)
12 print 'number of nodes after filtering: ', mxt.node_array.shape[-1], ' | NL: ', np.count_nonzero(mxt.node_array[1,:])
13 adshow(mxt.getImage(),'after area difference filter, AD=%d' % AD)
number of nodes before filtering:  3925  | NL:  3725
number of nodes after filtering:  2065  | NL:  1879

original image

after area difference filter, AD=10

Example - Sintetic image

 1 f = adreadgray('homeluistavares/sintetic_image/f.png')
 2 adshow(f,'original image')
 3 Bc = np.ones((3,3), dtype=np.bool)
 4 mxt = MaxTreeAlpha(f, Bc)
 5 V = mxt.computeVolume()
 6 Vext = mxt.computeExtinctionValues(V,"volume")
 7 mxt.extinctionFilter(Vext, 200)
 8 print 'number of nodes before filtering: ',  mxt.node_array.shape[-1], ' | NL: ', np.count_nonzero(mxt.node_array[1,:])
 9 
10 AD = 20000 # interactive parameter
11 mxt.areaDifference(AD)
12 print 'number of nodes after filtering: ', mxt.node_array.shape[-1], ' | NL: ', np.count_nonzero(mxt.node_array[1,:])
13 adshow(mxt.getImage(),'after area difference filter, AD=%d' % AD)
number of nodes before filtering:  9  | NL:  4
number of nodes after filtering:  7  | NL:  2

original image

after area difference filter, AD=20000

Example Gaussian image

 1 import ia636 as ia
 2 
 3 f = ia.iagaussian((200,200), np.transpose([[100,100]]), [[10*10,0],[0,20*20]])
 4 f = ia.ianormalize(f, [0,255]).astype(uint8)
 5 adshow(f,'original image')
 6 Bc = np.ones((3,3), dtype=np.bool)
 7 mxt = MaxTreeAlpha(f, Bc)
 8 V = mxt.computeVolume()
 9 Vext = mxt.computeExtinctionValues(V,"volume")
10 mxt.extinctionFilter(Vext, 200)
11 print 'number of nodes before filtering: ',  mxt.node_array.shape[-1], ' | NL: ', np.count_nonzero(mxt.node_array[1,:])
12 
13 AD = 20 # interactive parameter
14 mxt.areaDifference(AD)
15 print 'number of nodes after filtering: ',  mxt.node_array.shape[-1], ' | NL: ', np.count_nonzero(mxt.node_array[1,:])
16 adshow(mxt.getImage(),'after area difference filter, AD=%d' % AD)
number of nodes before filtering:  230  | NL:  229
number of nodes after filtering:  175  | NL:  174

original image

after area difference filter, AD=20