Area-open

001. from code.na_ni import*
002. from code.parent_s import*
003. import numpy as np
004. import time
005. import matplotlib.pyplot as plt
006. import ia636
007. import cv2
008. import os
009. 
010. 
011. #number of repetitions
012. nrepetitions = 1
013. 
014. # number of image concatenations
015. nconcatenations = 5 #1
016. 
017. 
018. #Images to be tested, all must have the same initial size
019. imgs_path = '/awmedia/www/media/Attachments/homeroberto/maxtreeicip2015_height_test/sample_images/'
020. imgs = [ os.path.join(imgs_path,f) for f in os.listdir(imgs_path) if os.path.isfile(os.path.join(imgs_path,f)) ]
021. a = len(imgs)
022. 
023. value = 200.1 # area threshold for the area-open filter
024. Bc = np.ones((3,3), dtype = bool) # structuring element
025. 
026. #Arrays to store the results
027. sizes = np.zeros(nconcatenations, dtype = np.float)
028. par_s = np.zeros((a,nconcatenations), dtype = np.float)
029. na_ni = np.zeros((a,nconcatenations), dtype = np.float)
030. na_ni_p =  np.zeros((a,nconcatenations), dtype = np.float)
031. 
032. for (kk,img_name) in enumerate(imgs):
033.     img = adreadgray(img_name)
034.     img = cv2.resize(img, (1024, 1024), interpolation = cv2.INTER_NEAREST)
035.     img[0,:] = 0
036.     img[-1,:] = 0
037.     img[:,0] = 0
038.     img[:,-1] = 0
039.     temp = np.zeros((3,nrepetitions), dtype = np.float)
040. 
041.     for i in xrange(1,nconcatenations+1):
042. 
043.         if i == 1:
044.             pass
045.         else:
046.             img = np.concatenate((img,img), axis = i%2)
047.         for k in xrange(nrepetitions):
048. 
049.             t1 = time.time()
050.             par,S_rev = max_tree_par_S(img,Bc)
051.             t1 = time.time() - t1
052.             t = time.time()
053.             area2 = compute_area(S_rev,par)
054.             out = direct_filter(int(value),S_rev,par,img,area2)
055.             t = time.time() - t
056.             temp[0,k] = t
057.             del par
058.             del S_rev
059.             del area2
060.             del out
061.             t = time.time()
062.             mxt = MaxTreeICIP2015(img,Bc)
063.             mxt.contractDR2(mxt.node_array[2,:] > value)
064.             out = mxt.getImage2()
065.             t = time.time() -t - t1
066.             del mxt
067.             del out
068.             temp[1,k] = t
069. 
070. 
071.             t = time.time()
072.             mxt2 = MaxTreeICIP2015(img,Bc)
073.             mxt2.contractDR(mxt2.node_array[2,:] > value)
074.             out2 = mxt2.getImage()
075.             t = time.time() -t - t1
076.             del mxt2
077.             del out2
078.             temp[2,k] = t
079.         sizes[i-1] = img.size
080.         par_s[kk,i-1] = temp[0].mean()
081.         na_ni_p[kk,i-1] = temp[1].mean()
082.         na_ni[kk,i-1] = temp[2].mean()
083. 
084. 
085. 
086. 
087. print "Avereage processing time parent/S:", par_s.mean(axis = 0)
088. print "Avereage processing time NA/NI:",na_ni.mean(axis = 0)
089. print "Avereage processing time NA/NI OpenMP:", na_ni_p.mean(axis = 0)
090. 
091. 
092. fig = plt.figure(figsize = (8,5),dpi = 900, facecolor= 'w')
093. ax = fig.add_subplot(1,1,1)
094. plt.plot(sizes, par_s.mean(axis = 0) ,  marker='^', linestyle = '-', markersize=12,linewidth = 2.0, label = 'Parent/S ')
095. plt.plot(sizes, na_ni_p.mean(axis = 0) ,  marker='>',linestyle = '--', markersize=12,linewidth = 2.0, label = 'Node array/Node index OpenMP ')
096. plt.plot(sizes, na_ni.mean(axis = 0) ,  marker='x', linestyle = '-.', markersize=12,linewidth = 2.0, label = 'Node array/Node index')
097. 
098. plt.grid()
099. plt.xlabel("Number of pixels",fontweight='bold',fontsize = 12)
100. plt.ylabel("Average processing time (s)",fontweight='bold',fontsize = 12)
101. plt.title("Area-open filter")
102. ax.set_xscale('log')
103. ax.set_yscale('log')
104. plt.axis('tight')
105. legend = ax.legend(loc='top left', shadow=True)
106. adshow(ia636.iafig2img(fig))
Avereage processing time parent/S: [ 0.02966544  0.07041237  0.17685592  0.46569281  1.08863095]
Avereage processing time NA/NI: [ 0.02859013  0.08745195  0.22008507  0.51511321  1.29704167]
Avereage processing time NA/NI OpenMP: [ 0.02341151  0.05719226  0.13690469  0.42206363  0.99383062]