areaDifference

MainPage

Description: This method implements the area difference filter.

Signature: MaxTreeAlpha.areaDifference(AD)

Input:
  • AD, int. Area difference threshold.

Output:

C++ Aux Function

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

Python Implementation

 1 import numpy as np
 2 def areaDifference(self,AD):
 3     """
 4     Implementation of the area difference filter proposed by Tavares et al.
 5     """
 6     n = self.node_array.shape[-1]
 7     parent = self.node_array[0, :]
 8     area = self.node_array[3, :]
 9     to_keep = np.zeros(n, dtype = np.int32)
10     self.area_difference_aux(AD,parent,area,to_keep)
11     self.contractDR(to_keep>0)
12     return self

Example

 1 import numpy as np
 2 import ia636 as ia
 3 from iamxt import MaxTreeAlpha
 4 f = adreadgray(find_attachment_file('Attachments/iamxt/MainPage/objects.png'))
 5 adshow(f,'original image')
 6 Bc = np.ones((3,3), dtype=np.bool)
 7 mxt = MaxTreeAlpha(f, Bc)
 8 
 9 
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], ' | NL: ', np.count_nonzero(mxt.node_array[1,:])
14 AD = 10 # interactive parameter
15 mxt.areaDifference(AD)
16 print 'number of nodes after filtering: ',  mxt.node_array.shape[-1], ' | NL: ', np.count_nonzero(mxt.node_array[1,:])
17 adshow(mxt.getImage(),'after area difference filter, AD=%d' % AD)
number of nodes before filtering:  2491  | NL:  2291
number of nodes after filtering:  1002  | NL:  803

original image

after area difference filter, AD=10

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