Height Test

01. import numpy as np
02. from code.na_ni import*
03. from code.parent_s import*
04. import time
05. import os
06. 
07. imgs_path = '/awmedia/www/media/Attachments/homeroberto/maxtreeicip2015_height_test/sample_images/'
08. img_files = [ os.path.join(imgs_path,f) for f in os.listdir(imgs_path) if os.path.isfile(os.path.join(imgs_path,f))]
09. 
10. 
11. C8 = np.ones((3,3), dtype = bool)
12. #C8 = np.zeros((3,3), dtype = bool)
13. #C8[1,:] = True
14. #C8[:,1] = True
15. ratios = np.zeros((2,len(img_files)))
16. 
17. 
18. for (i,img_path) in enumerate(img_files):
19. 
20.     img = adreadgray(img_path)
21. 
22.     par,S_rev = max_tree_par_S(img,C8)
23. 
24.     t1 = time.time()
25.     height = compute_height(S_rev,par,img)
26.     t1 = time.time() - t1
27.     del height
28. 
29. 
30.     mxt = MaxTreeICIP2015(img,C8)
31. 
32.     t2 = time.time()
33.     height = mxt.computeHeight()
34.     t2 = time.time() - t2
35.     del height
36. 
37.     ratios[0,i] = t1/t2
38.     ratios[1,i] = img.size*1.0/mxt.node_array.shape[1]
39. 
40. print 'Avg speed-up: %f+-%f' %(ratios.mean(axis = 1)[0],ratios.std(axis = 1)[0])
41. print 'Min speed-up: ', ratios.min(axis = 1)[0]
42. print 'Max speed-up: ', ratios.max(axis = 1)[0]
43. 
44. print
45. 
46. print 'Avg N/M: %f+-%f' %(ratios.mean(axis = 1)[1],ratios.std(axis = 1)[1])
47. print 'Min N/M: ', ratios.min(axis = 1)[1]
48. print 'Max N/M: ', ratios.max(axis = 1)[1]
Avg speed-up: 11.414208+-15.101968
Min speed-up:  2.21052631579
Max speed-up:  107.197321429

Avg N/M: 9.165190+-8.085876
Min N/M:  2.75149537792
Max N/M:  53.3459137756