00001
00002
00003
00004 #include <flgrCoreTypes.h>
00005 #include <flgrCoreErrors.h>
00006 #include <flgrCoreData.h>
00007 #include <flgrCoreIO.h>
00008 #include <flgrCoreCompare.h>
00009 #include <flgrCoreReplace.h>
00010 #include <flgrImageIO.h>
00011 #include <flgrMeasureBase.h>
00012 #include <flgrMorphoBase.h>
00013 #include <flgrMorphoWatershed.h>
00014 #include <flgrMorphoGeodesy.h>
00015 #include <flgrMorphoLabel.h>
00016 #include <flgrMorphoDistance.h>
00017 #include <time.h>
00018
00019 #define BENCH_FUCTION(nbtime,textinfo,function,...) \
00020 { \
00021 clock_t before, after; \
00022 int i; \
00023 before=clock(); \
00024 for(i=0;i<nbtime;i++) { \
00025 function(__VA_ARGS__); \
00026 } \
00027 after=clock(); \
00028 printf(textinfo " time : %d us \n", \
00029 (int) ((after - before)/(CLOCKS_PER_SEC/1000000)/nbtime)); \
00030 }
00031
00032
00033 int main(void) {
00034 FLGR_Data2D *imin,*imtmp,*imFilter,*imDistance,*imMarker,*imMaxima,*imLabel,*imWatershed;
00035 FLGR_Data2D *nhb1,*nhb2,*nhb3,*nhb4,*nhb5;
00036
00037 FLGR_Vector *vec_min, *vec_max;
00038 FLGR_Vector *vec_hmin;
00039
00040 imin = flgr2d_load_pgm("../../images/gray/beans.pgm");
00041 imtmp = flgr2d_create_from(imin);
00042 imFilter = flgr2d_create_from(imin);
00043 imDistance = flgr2d_create_from(imin);
00044 imMarker = flgr2d_create_from(imin);
00045 imMaxima = flgr2d_create_from(imin);
00046 imLabel = flgr2d_create_from(imin);
00047 imWatershed = flgr2d_create_from(imin);
00048
00049 vec_min = flgr_vector_create(imin->spp,imin->type);
00050 vec_max = flgr_vector_create(imin->spp,imin->type);
00051 vec_hmin = flgr_vector_create(imin->spp,imin->type);
00052 flgr_vector_populate_from_string(vec_hmin,"1");
00053
00054
00055 nhb1 = flgr2d_create_neighborhood(3,3,imin->spp,imin->type,FLGR_RECT,FLGR_8_CONNEX);
00056 nhb2 = flgr2d_create_neighborhood(5,5,imin->spp,imin->type,FLGR_RECT,FLGR_8_CONNEX);
00057 nhb3 = flgr2d_create_neighborhood(7,7,imin->spp,imin->type,FLGR_RECT,FLGR_8_CONNEX);
00058 nhb4 = flgr2d_create_neighborhood(9,9,imin->spp,imin->type,FLGR_RECT,FLGR_8_CONNEX);
00059 nhb5 = flgr2d_create_neighborhood(11,11,imin->spp,imin->type,FLGR_RECT,FLGR_8_CONNEX);
00060
00061 flgr2d_replace_I_with_S_S_I(imin,imin,"==","255","254",imin);
00062
00063
00064 BENCH_FUCTION(1000,"Open Filter",flgr2d_open,imtmp,imin,nhb1);
00065 flgr2d_close(imFilter,imtmp,nhb1);
00066
00067
00068 flgr2d_replace_I_with_S_S_S(imtmp,imFilter,"<","128","255","0");
00069 flgr2d_distance(imDistance,imtmp,nhb1->connexity);
00070
00071
00072 flgr2d_regional_hmaxima(imMaxima,imDistance,vec_hmin,nhb1->connexity);
00073 flgr2d_replace_I_with_S_S_S(imtmp,imMaxima,">","0","255","0");
00074 flgr2d_dilate(imMaxima,imtmp,nhb5);
00075
00076
00077 flgr2d_label(imLabel, imMaxima, nhb1->connexity);
00078
00079
00080 BENCH_FUCTION(1,"Watershed",flgr2d_watershed,imLabel, imin, nhb1->connexity);
00081
00082
00083 flgr2d_watershed_build_line(imWatershed, imLabel, nhb1->connexity);
00084 flgr2d_replace_I_with_S_S_I(imWatershed,imWatershed,"==","1","255",imin);
00085
00086 flgr2d_measure_min_max(imLabel,vec_min,vec_max);
00087
00088 printf("Coffee Beans number : %d\n", flgr_get_array_fgUINT8(vec_max->array,0));
00089
00090 flgr2d_save_pgm(imFilter,"filter.pgm",5);
00091 flgr2d_save_pgm(imDistance,"distance.pgm",5);
00092 flgr2d_save_pgm(imMaxima,"maxima.pgm",5);
00093 flgr2d_save_pgm(imLabel,"label.pgm",5);
00094 flgr2d_save_pgm(imWatershed,"watershed.pgm",5);
00095
00096 flgr2d_destroy(imin);
00097 flgr2d_destroy(imtmp);
00098 flgr2d_destroy(imFilter);
00099 flgr2d_destroy(imDistance);
00100 flgr2d_destroy(imMarker);
00101 flgr2d_destroy(imMaxima);
00102 flgr2d_destroy(imLabel);
00103 flgr2d_destroy(imWatershed);
00104 flgr2d_destroy(nhb1);
00105 flgr2d_destroy(nhb2);
00106 flgr2d_destroy(nhb3);
00107 flgr2d_destroy(nhb4);
00108 flgr2d_destroy(nhb5);
00109
00110 flgr_vector_destroy(vec_max);
00111 flgr_vector_destroy(vec_min);
00112 flgr_vector_destroy(vec_hmin);
00113
00114 return 0;
00115 }
00116
00117