00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 import os
00011 import sys
00012 import time
00013
00014 from fulguro import *
00015
00016
00017
00018 def benchmark(function,nbiter,*args):
00019 t=time.time()
00020 for i in range(nbiter):
00021 function(*args)
00022 t2=time.time()
00023 return ((t2-t)*1000)/nbiter
00024
00025
00026
00027
00028
00029
00030
00031 imin = flgr2d_load_pgm('../../images/gray/beans.pgm')
00032 imtmp = FLGR_Data2D(imin)
00033 imFilter = FLGR_Data2D(imin)
00034 imDistance = FLGR_Data2D(imin)
00035 imMarker = FLGR_Data2D(imin)
00036 imMaxima = FLGR_Data2D(imin)
00037 imLabel = FLGR_Data2D(imin)
00038 imWatershed = FLGR_Data2D(imin)
00039
00040 nhb1 = FLGR_Data2D(3,3,imin.spp,imin.type,FLGR_RECT,FLGR_8_CONNEX)
00041 nhb2 = FLGR_Data2D(5,5,imin.spp,imin.type,FLGR_RECT,FLGR_8_CONNEX)
00042 nhb3 = FLGR_Data2D(7,7,imin.spp,imin.type,FLGR_RECT,FLGR_8_CONNEX)
00043 nhb4 = FLGR_Data2D(9,9,imin.spp,imin.type,FLGR_RECT,FLGR_8_CONNEX)
00044 nhb5 = FLGR_Data2D(11,11,imin.spp,imin.type,FLGR_RECT,FLGR_8_CONNEX)
00045
00046 flgr2d_replace(imin,imin,"==",255,254,imin)
00047
00048
00049
00050 speed = benchmark(flgr2d_open,100,imFilter,imin,nhb1)
00051 print 'Filter time:',speed,'ms'
00052
00053
00054 speed = benchmark(flgr2d_replace,1000,imtmp,imFilter,"<=",128,255,0)
00055 print 'Replace SSE2 time:',speed,'ms'
00056 flgr2d_distance(imDistance,imtmp,nhb1.connexity)
00057
00058
00059 flgr2d_regional_hmaxima(imMaxima,imDistance,1,nhb1.connexity)
00060 speed = benchmark(flgr2d_replace,1000,imtmp,imMaxima,">",0,255,0)
00061 print 'Replace time:',speed,'ms'
00062 flgr2d_dilate(imMaxima,imtmp,nhb4)
00063
00064
00065 flgr2d_label(imLabel, imMaxima, nhb1.connexity)
00066
00067
00068 speed = benchmark(flgr2d_watershed,1,imLabel, imin, nhb1.connexity)
00069 print 'Watershed time:',speed,'ms'
00070
00071
00072 flgr2d_watershed_build_line(imWatershed, imLabel, nhb1.connexity)
00073 flgr2d_replace(imWatershed,imWatershed,"==",1,255,imin)
00074
00075 vmin,vmax = flgr2d_measure_min_max(imLabel)
00076
00077 print 'Coffee Beans number : ',vmax[0]
00078
00079
00080
00081 flgr_display(imFilter,'filter',
00082 imDistance,'distance',
00083 imMaxima,'maxima',
00084 imLabel,'label',
00085 imWatershed,'watershed')
00086