00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 import time
00012 from fulguro import *
00013
00014
00015
00016 def benchmark(function,nbiter,*args):
00017 import time
00018 t=time.time()
00019 for i in range(nbiter):
00020 function(*args)
00021 t2=time.time()
00022 return ((t2-t)*1000)/nbiter
00023
00024
00025 def mydistance(imout,imin,connexity):
00026 nhb = FLGR_Data2D(imin.spp, imin.type, connexity)
00027 imtmp = FLGR_Data2D(imin)
00028 imtmp2 = FLGR_Data2D(imin)
00029
00030 flgr2d_replace(imtmp2,imin,"==",0,0,1)
00031
00032 flgr2d_copy(imout,imtmp2)
00033
00034 while (flgr2d_measure_volume(imtmp)[0]!=0):
00035 flgr2d_erode(imtmp,imtmp2,nhb)
00036 flgr2d_arith_add(imout,imtmp,imout)
00037
00038 flgr2d_copy(imtmp2,imtmp)
00039
00040
00041
00042
00043
00044
00045
00046 imin = flgr2d_load_pgm('../../images/bin/bubble.pgm')
00047 imDest1 = FLGR_Data2D(imin)
00048 imDest2 = FLGR_Data2D(imin)
00049
00050 print "Image size :",imin.size_x,"x",imin.size_y
00051
00052 speed = benchmark(mydistance,10,imDest2, imin, FLGR_4_CONNEX)
00053 print "Python layer (iterative algorithm) distance time = ",speed,' ms'
00054
00055 speed = benchmark(flgr2d_distance,100,imDest1, imin, FLGR_4_CONNEX)
00056 print "Native Recursive distance (2 pass) time = ",speed,' ms'
00057
00058
00059 flgr2d_save_pgm(imDest1,"it_distance")
00060
00061 flgr_display(imDest1,"distance",imDest2,"distance_reference")