example3.py
- See also:
- example3.c
import time
from fulguro import *
def benchmark(function,nbiter,*args):
import time
t=time.time()
for i in range(nbiter):
function(*args)
t2=time.time()
return ((t2-t)*1000)/nbiter
def mydistance(imout,imin,connexity):
nhb = FLGR_Data2D(imin.spp, imin.type, connexity)
imtmp = FLGR_Data2D(imin)
imtmp2 = FLGR_Data2D(imin)
flgr2d_replace(imtmp2,imin,"==",0,0,1)
flgr2d_copy(imout,imtmp2)
while (flgr2d_measure_volume(imtmp)[0]!=0):
flgr2d_erode(imtmp,imtmp2,nhb)
flgr2d_arith_add(imout,imtmp,imout)
flgr2d_copy(imtmp2,imtmp)
imin = flgr2d_load_pgm('../../images/bin/bubble.pgm')
imDest1 = FLGR_Data2D(imin)
imDest2 = FLGR_Data2D(imin)
print "Image size :",imin.size_x,"x",imin.size_y
speed = benchmark(mydistance,10,imDest2, imin, FLGR_4_CONNEX)
print "Python layer (iterative algorithm) distance time = ",speed,' ms'
speed = benchmark(flgr2d_distance,100,imDest1, imin, FLGR_4_CONNEX)
print "Native Recursive distance (2 pass) time = ",speed,' ms'
flgr2d_save_pgm(imDest1,"it_distance")
flgr_display(imDest1,"distance",imDest2,"distance_reference")