00001 /**************************************************************** 00002 * Fulguro 00003 * Copyright (C) 2004 Christophe Clienti 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the 00017 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 * Boston, MA 02111-1307, USA. 00019 ***************************************************************/ 00020 00021 00022 #include <stdio.h> 00023 #include <stdlib.h> 00024 #include <string.h> 00025 00026 #include <flgrCoreSlideWindow.h> 00027 #include <flgrCoreNhbManage.h> 00028 #include <flgrCoreCopy.h> 00029 #include <flgrCoreDispatch.h> 00030 #include <flgrCoreCompare.h> 00031 #include <flgrCoreReplace.h> 00032 00033 #include <flgrArith.h> 00034 00035 #include <flgrMorphoLabel.h> 00036 #include <flgrHistogram.h> 00037 #include "skiz.h" 00038 00039 #define max(x,y) (x<y?y:x) 00040 00041 /* //////////////////////////////////////////////////////////////// */ 00042 /* // Macro for different type of dilateSeparateLabelNhb */ 00043 /* //////////////////////////////////////////////////////////////// */ 00044 /* #define dilSepLblNhb(dtype) \ */ 00045 /* int i,size; \ */ 00046 /* dtype maxi; \ */ 00047 /* dtype *pextr; \ */ 00048 /* dtype center; \ */ 00049 /* \ */ 00050 /* pextr=(dtype *) extr->listValue; \ */ 00051 /* center = *((dtype *) (extr->centerValue)); \ */ 00052 /* size=extr->size; \ */ 00053 /* maxi=pextr[0]; \ */ 00054 /* \ */ 00055 /* for(i=0 ; i<extr->size; i++) { \ */ 00056 /* maxi=max(maxi,pextr[i]); \ */ 00057 /* } \ */ 00058 /* \ */ 00059 /* if(center==maxi) return center; \ */ 00060 /* \ */ 00061 /* for(i=0 ; i<extr->size ; i++) { \ */ 00062 /* if((pextr[i]!=maxi) && (pextr[i]!=0)) return 0; \ */ 00063 /* \ */ 00064 /* } \ */ 00065 /* \ */ 00066 /* return maxi */ 00067 00068 /* fgUINT8 dilateSeparateLabelNhb_fgUINT8(FLGR_Data2D *nhb, FLGR_NhbBox2D *extr) { */ 00069 /* dilSepLblNhb(fgUINT8); */ 00070 /* } */ 00071 00072 /* fgUINT16 dilateSeparateLabelNhb_fgUINT16(FLGR_Data2D *nhb, FLGR_NhbBox2D *extr) { */ 00073 /* dilSepLblNhb(fgUINT16); */ 00074 /* } */ 00075 00076 /* fgUINT32 dilateSeparateLabelNhb_fgUINT32(FLGR_Data2D *nhb, FLGR_NhbBox2D *extr) { */ 00077 /* dilSepLblNhb(fgUINT32); */ 00078 /* } */ 00079 00080 /* fgINT8 dilateSeparateLabelNhb_fgINT8(FLGR_Data2D *nhb, FLGR_NhbBox2D *extr) { */ 00081 /* dilSepLblNhb(fgINT8); */ 00082 /* } */ 00083 00084 /* fgINT16 dilateSeparateLabelNhb_fgINT16(FLGR_Data2D *nhb, FLGR_NhbBox2D *extr) { */ 00085 /* dilSepLblNhb(fgINT16); */ 00086 /* } */ 00087 00088 /* fgINT32 dilateSeparateLabelNhb_fgINT32(FLGR_Data2D *nhb, FLGR_NhbBox2D *extr) { */ 00089 /* dilSepLblNhb(fgINT32); */ 00090 /* } */ 00091 00092 /* fgFLOAT32 dilateSeparateLabelNhb_fgFLOAT32(FLGR_Data2D *nhb, FLGR_NhbBox2D *extr) { */ 00093 /* dilSepLblNhb(fgFLOAT32); */ 00094 /* } */ 00095 00096 /* fgFLOAT64 dilateSeparateLabelNhb_fgFLOAT64(FLGR_Data2D *nhb, FLGR_NhbBox2D *extr) { */ 00097 /* dilSepLblNhb(fgFLOAT64); */ 00098 /* } */ 00099 00100 00101 00102 00103 00104 00105 /* void ImGeoSkizByLabelDilate_fgUINT8(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *imgmarker, FLGR_Data2D *nhb) { */ 00106 /* FLGR_Data2D *imglabel,*imgtmp1,*imgtmp2,*imgtmp3; */ 00107 /* int nblabel; */ 00108 /* fgUINT8 _254=254; */ 00109 /* fgUINT8 _255=255; */ 00110 /* fgUINT8 _0=0; */ 00111 /* int raiselevel; */ 00112 00113 /* imglabel = flgr2d_create_pixmap(imgdest->size_y, imgdest->size_x, imgdest->type); */ 00114 /* imgtmp1=flgr2d_create_pixmap(imgdest->size_y, imgdest->size_x, imgdest->type); */ 00115 /* imgtmp2=flgr2d_create_pixmap(imgdest->size_y, imgdest->size_x, imgdest->type); */ 00116 /* imgtmp3=flgr2d_create_pixmap(imgdest->size_y, imgdest->size_x, imgdest->type); */ 00117 00118 /* nblabel=flgr2d_label(imglabel,imgmarker,nhb->connexity); */ 00119 00120 /* flgr2d_arith_const_addsat_fgUINT8(imgsrc,imgsrc,1); */ 00121 /* flgr2d_replace_I_with_C_C_I(imgsrc,imgsrc,"==",&_255,&_254,imgsrc); */ 00122 /* flgr2d_replace_I_with_C_C_I(imgsrc,imgmarker,"==",&_255,&_0,imgsrc); */ 00123 00124 00125 /* for(raiselevel=0 ; raiselevel<255; raiselevel++) { */ 00126 00127 /* flgr2d_replace_I_with_C_C_C(imgtmp1,imgsrc,"<=",&raiselevel,&_255,&_0); */ 00128 00129 00130 /* while(1) { */ 00131 /* flgr2d_copy(imgtmp2,imglabel); */ 00132 00133 /* flgr2d_raster_slide_window_fgUINT8(imglabel,imgtmp2,nhb,FLGR_NHB_NO_SYM,dilateSeparateLabelNhb_fgUINT8); */ 00134 /* flgr2d_arith_inf_fgUINT8(imglabel,imglabel,imgtmp1); */ 00135 00136 /* if(flgr2d_compare(imglabel,"==",imgtmp2)==0) break; */ 00137 /* } */ 00138 00139 /* } */ 00140 00141 /* flgr2d_copy(imgdest,imglabel); */ 00142 00143 /* flgr2d_destroy(imglabel); */ 00144 /* flgr2d_destroy(imgtmp1); */ 00145 /* flgr2d_destroy(imgtmp2); */ 00146 /* flgr2d_destroy(imgtmp3); */ 00147 /* } */ 00148 00149 /* void ImGeoSkizBiasByLabelDilate_fgUINT8(FLGR_Data2D *imgdest, */ 00150 /* FLGR_Data2D *imgsrc, */ 00151 /* FLGR_Data2D *imgmarker, */ 00152 /* FLGR_Data2D *nhb, */ 00153 /* int graymax, int stepbylevel) { */ 00154 00155 /* FLGR_Data2D *imglabel,*imgtmp1,*imgtmp2,*imgtmp3; */ 00156 /* int nblabel; */ 00157 /* fgUINT8 _255=255; */ 00158 /* fgUINT8 _0=0; */ 00159 /* fgUINT8 graymax_m1= graymax - 1; */ 00160 /* int raiselevel,j,k=0; */ 00161 /* char name[30]; */ 00162 00163 /* imglabel=flgr2d_create_pixmap(imgdest->size_y, imgdest->size_x, imgdest->type); */ 00164 /* imgtmp1=flgr2d_create_pixmap(imgdest->size_y, imgdest->size_x, imgdest->type); */ 00165 /* imgtmp2=flgr2d_create_pixmap(imgdest->size_y, imgdest->size_x, imgdest->type); */ 00166 /* imgtmp3=flgr2d_create_pixmap(imgdest->size_y, imgdest->size_x, imgdest->type); */ 00167 00168 /* nblabel=flgr2d_label(imglabel,imgmarker,nhb->connexity); */ 00169 /* flgr_normalize_str(imglabel,imglabel,"80","255"); */ 00170 00171 /* flgr2d_arith_const_addsat_fgUINT8(imgsrc,imgsrc,1); */ 00172 /* flgr2d_replace_I_with_C_C_I(imgsrc,imgsrc,"==",&graymax,&graymax_m1,imgsrc); */ 00173 /* flgr2d_replace_I_with_C_C_I(imgsrc,imgmarker,"==",&_255,&_0,imgsrc); */ 00174 00175 /* raiselevel=0; */ 00176 /* //for(raiselevel=0 ; raiselevel<graymax; raiselevel++) { */ 00177 /* while(1) { */ 00178 /* raiselevel++; */ 00179 /* if(raiselevel==graymax) raiselevel=graymax-1; */ 00180 00181 /* flgr2d_replace_I_with_C_C_C(imgtmp1,imgsrc,"<=",&raiselevel,&_255,&_0); */ 00182 00183 /* for(j=0;j<stepbylevel;j++) { */ 00184 /* flgr2d_copy(imgtmp2,imglabel); */ 00185 00186 /* flgr2d_raster_slide_window_fgUINT8(imglabel,imgtmp2,nhb,FLGR_NHB_NO_SYM,dilateSeparateLabelNhb_fgUINT8); */ 00187 /* flgr2d_arith_inf_fgUINT8(imglabel,imglabel,imgtmp1); */ 00188 00189 00190 /* } */ 00191 /* if(raiselevel==graymax-1) */ 00192 /* if(flgr2d_compare(imglabel,"==",imgtmp2)==0) break; */ 00193 00194 /* sprintf(name,"label_%04d",k++); */ 00195 /* //flgr_image_save_pgm(imglabel,name); */ 00196 00197 /* } */ 00198 00199 00200 /* while(1) { */ 00201 /* flgr2d_copy(imgtmp2,imglabel); */ 00202 00203 /* flgr2d_raster_slide_window_fgUINT8(imglabel,imgtmp2,nhb,FLGR_NHB_NO_SYM,dilateSeparateLabelNhb_fgUINT8); */ 00204 /* //flgr2d_arith_inf_fgUINT8(imglabel,imglabel,imgtmp1); */ 00205 00206 /* sprintf(name,"label_%04d",k++); */ 00207 /* //saveImage2DToPgm(imglabel,name); */ 00208 00209 /* if(flgr2d_compare(imglabel,"==",imgtmp2)==0) break; */ 00210 /* } */ 00211 00212 /* flgr2d_copy(imgdest,imglabel); */ 00213 00214 /* flgr2d_destroy(imglabel); */ 00215 /* flgr2d_destroy(imgtmp1); */ 00216 /* flgr2d_destroy(imgtmp2); */ 00217 /* flgr2d_destroy(imgtmp3); */ 00218 /* } */