Fulguro Logo Support This Project

example6.py

See also:
example6.c
#!/usr/bin/env python
## @example example6.py
#  @see example6.c

##################################################################
# Example for testing user defined kernel computation            #
##################################################################

import time

from fulguro import *

### PROCEDURES #########################################################
def benchmark(function,nbiter,*args):
    t=time.time()
    for i in range(nbiter):
        function(*args)
    t2=time.time()
    return ((t2-t)*1000)/nbiter

def getNhbMin(result,extr):
    flgr2d_get_nhb_minimum(result,extr)
        



##################################################################
### MAIN #########################################################
##################################################################

imin = flgr2d_load_pgm('../../images/gray/lena.pgm')
imout1 = FLGR_Data2D(imin)
imout2 = FLGR_Data2D(imin)
nhb1 = FLGR_Data2D(3,3,imin.spp,imin.type,FLGR_RECT,FLGR_8_CONNEX)

### Setting shape to FLGR_USER_SHAPE prevent to use optimization for erosion
### in order to compare c-layer and python-layer slidding window function
flgr2d_data_set_shape(nhb1,FLGR_USER_SHAPE)


speed = benchmark(flgr2d_erode,10,imout1,imin,nhb1)
print 'C layer neighborhood operation speed: ',speed,'ms'

speed = benchmark(flgr2d_raster_slide_window,1,imout2,imin,nhb1,FLGR_NHB_NO_SYM,getNhbMin)
print 'Python layer neighborhood operation speed: ',speed,'ms'

# For prototyping, flgr2d_raster_slide_window is very powerful experiment tool,
# but for efficiency it must be implemented in C/C++

flgr_display(imout1,'erode',
             imout2,'erode_user_filter')

SourceForge.net Logo
Generated on Tue Nov 11 19:17:22 2008 for Fulguro by doxygen 1.5.6