00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <flgrCoreIO.h>
00025 #include <flgrCoreMalloc.h>
00026 #include <flgrCoreCopy.h>
00027 #include <flgrCoreDispatch.h>
00028 #include <flgrArith.h>
00029
00030 #include <flgrCoreTranspose.h>
00031
00032 #include "flgrMorphoBaseSegment.h"
00033 #include "flgrMorphoBaseSegmentFast.h"
00034
00035
00036 #define max(x,y) ((x)>(y)?(x):(y))
00037 #define min(x,y) ((x)<(y)?(x):(y))
00038
00046
00047
00049 #define FLGR_MACRO_INTERNAL_DILATE_ROW_Lemonnier(dtype) \
00050 int j; \
00051 int nbprop; \
00052 dtype T, T_pre; \
00053 dtype G, G_pre; \
00054 dtype rowval; \
00055 dtype rowval_pre; \
00056 \
00057 \
00058 \
00059 sesize_x=sesize_x/2; \
00060 \
00061 T=0; \
00062 G=0; \
00063 nbprop=0; \
00064 \
00065 for( j=0 ; j<row_size ; j++) { \
00066 T_pre=T; \
00067 G_pre=G; \
00068 rowval=flgr_get_array_##dtype(psrc,j); \
00069 \
00070 if(j>(row_size-sesize_x-1)) { \
00071 if(T_pre<rowval){ \
00072 T=rowval; \
00073 }else { \
00074 T=T_pre; \
00075 } \
00076 }else{ \
00077 T=0; \
00078 } \
00079 \
00080 \
00081 if( (G_pre>rowval) && (nbprop<sesize_x) ) { \
00082 G=G_pre; \
00083 nbprop++; \
00084 }else { \
00085 if( (j>(row_size-sesize_x-1)) && (nbprop>=sesize_x) ) { \
00086 G=T; \
00087 }else { \
00088 G=rowval; \
00089 } \
00090 T=0; \
00091 nbprop=0; \
00092 } \
00093 \
00094 if(j-sesize_x<0) { \
00095 flgr_set_array_##dtype(tmp1,row_size-j-1,G); \
00096 }else { \
00097 flgr_set_array_##dtype(tmp1, \
00098 row_size-j-1, \
00099 max(G,flgr_get_array_##dtype(psrc,j-sesize_x))); \
00100 } \
00101 \
00102 } \
00103 \
00104 T=0; \
00105 G=0; \
00106 nbprop=0; \
00107 rowval=0; \
00108 rowval_pre=0; \
00109 \
00110 for( j=0 ; j<row_size ; j++) { \
00111 T_pre=T; \
00112 G_pre=G; \
00113 \
00114 rowval_pre=rowval; \
00115 rowval=flgr_get_array_##dtype(tmp1,j); \
00116 \
00117 if(j==0) { \
00118 T=rowval; \
00119 }else { \
00120 if( (rowval>rowval_pre) && (T<rowval) ) { \
00121 T=rowval; \
00122 }else { \
00123 T=T_pre; \
00124 } \
00125 } \
00126 \
00127 \
00128 if( (G_pre>rowval) && (nbprop<sesize_x) ) { \
00129 G=G_pre; \
00130 nbprop++; \
00131 }else { \
00132 if (nbprop>=sesize_x) { \
00133 G=T; \
00134 }else{ \
00135 G=rowval; \
00136 } \
00137 T=0; \
00138 nbprop=0; \
00139 } \
00140 \
00141 if(j<sesize_x) { \
00142 flgr_set_array_##dtype(pdest,row_size-j-1,G); \
00143 }else { \
00144 flgr_set_array_##dtype(pdest, \
00145 row_size-j-1, \
00146 max(G,flgr_get_array_##dtype(tmp1,j-sesize_x))); \
00147 } \
00148 } \
00149 \
00150 return
00151
00152
00153
00155
00157 #define FLGR_MACRO_INTERNAL_ERODE_ROW_Lemonnier(dtype) \
00158 int j; \
00159 int nbprop; \
00160 dtype T, T_pre; \
00161 dtype G, G_pre; \
00162 dtype rowval; \
00163 dtype rowval_pre; \
00164 \
00165 \
00166 \
00167 sesize_x=sesize_x/2; \
00168 \
00169 \
00170 \
00171 T=0; \
00172 G=0; \
00173 nbprop=0; \
00174 \
00175 for( j=0 ; j<row_size ; j++) { \
00176 T_pre=T; \
00177 G_pre=G; \
00178 rowval=MAX_##dtype - flgr_get_array_##dtype(psrc,j); \
00179 \
00180 if(j>(row_size-sesize_x-1)) { \
00181 if(T_pre<rowval){ \
00182 T=rowval; \
00183 }else { \
00184 T=T_pre; \
00185 } \
00186 }else{ \
00187 T=0; \
00188 } \
00189 \
00190 \
00191 if( (G_pre>rowval) && (nbprop<sesize_x) ) { \
00192 G=G_pre; \
00193 nbprop++; \
00194 }else { \
00195 if( (j>(row_size-sesize_x-1)) && (nbprop>=sesize_x) ) { \
00196 G=T; \
00197 }else { \
00198 G=rowval; \
00199 } \
00200 T=0; \
00201 nbprop=0; \
00202 } \
00203 \
00204 \
00205 if(j-sesize_x<0) { \
00206 flgr_set_array_##dtype(tmp1,row_size-j-1,G); \
00207 }else { \
00208 flgr_set_array_##dtype(tmp1, \
00209 row_size-j-1, \
00210 max(G,MAX_##dtype - flgr_get_array_##dtype(psrc,j-sesize_x))); \
00211 } \
00212 \
00213 } \
00214 \
00215 T=0; \
00216 G=0; \
00217 nbprop=0; \
00218 rowval=0; \
00219 rowval_pre=0; \
00220 \
00221 for( j=0 ; j<row_size ; j++) { \
00222 T_pre=T; \
00223 G_pre=G; \
00224 \
00225 rowval_pre=rowval; \
00226 rowval=flgr_get_array_##dtype(tmp1,j); \
00227 \
00228 if(j==0) { \
00229 T=rowval; \
00230 }else { \
00231 if( (rowval>rowval_pre) && (T<rowval) ) { \
00232 T=rowval; \
00233 }else { \
00234 T=T_pre; \
00235 } \
00236 } \
00237 \
00238 \
00239 if( (G_pre>rowval) && (nbprop<sesize_x) ) { \
00240 G=G_pre; \
00241 nbprop++; \
00242 }else { \
00243 if (nbprop>=sesize_x) { \
00244 G=T; \
00245 }else{ \
00246 G=rowval; \
00247 } \
00248 T=0; \
00249 nbprop=0; \
00250 } \
00251 \
00252 if(j<sesize_x) { \
00253 flgr_set_array_##dtype(pdest,row_size-j-1,MAX_##dtype - G); \
00254 }else { \
00255 flgr_set_array_##dtype(pdest, \
00256 row_size-j-1, \
00257 MAX_##dtype - max(G,flgr_get_array_##dtype(tmp1,j-sesize_x))); \
00258 } \
00259 } \
00260 \
00261 return
00262
00264
00266 #define FLGR_MACRO_INTERNAL_DILATE_ROW_HGW(dtype) \
00267 int j,k,l,m=0,n=0,p=0,se2=sesize_x/2; \
00268 int kpad; \
00269 dtype *pbufg,*pbufh; \
00270 dtype tmp; \
00271 \
00272 \
00273 \
00274 pbufg=tmp1; \
00275 pbufh=tmp2; \
00276 \
00277 tmp = flgr_get_array_##dtype(psrc,0); \
00278 flgr_set_array_##dtype(pbufg,0,tmp); \
00279 \
00280 tmp = flgr_get_array_##dtype(psrc,row_size-1); \
00281 flgr_set_array_##dtype(pbufh,row_size-1,tmp); \
00282 \
00283 \
00284 for( j=1,k=row_size-2,l=row_size-1 ; j<row_size ; j++,k--,l--) { \
00285 if(j%sesize_x==0) { \
00286 tmp = flgr_get_array_##dtype(psrc,j); \
00287 flgr_set_array_##dtype(pbufg,j,tmp); \
00288 }else { \
00289 tmp = flgr_get_array_##dtype(pbufg,j-1); \
00290 tmp = max(tmp, flgr_get_array_##dtype(psrc,j)); \
00291 flgr_set_array_##dtype(pbufg,j,tmp); \
00292 } \
00293 \
00294 if(l%sesize_x==0) { \
00295 tmp = flgr_get_array_##dtype(psrc,k); \
00296 flgr_set_array_##dtype(pbufh,k,tmp); \
00297 }else { \
00298 tmp = flgr_get_array_##dtype(pbufh,l); \
00299 tmp = max(tmp, flgr_get_array_##dtype(psrc,k)); \
00300 flgr_set_array_##dtype(pbufh,k,tmp); \
00301 } \
00302 } \
00303 \
00304 n=se2;p=0;m=0; \
00305 for( j=0; j<se2 ; j++) { \
00306 tmp = flgr_get_array_##dtype(pbufg,n++); \
00307 flgr_set_array_##dtype(pdest,m++,tmp); \
00308 } \
00309 for( j=se2; j<row_size-se2 ;j++) { \
00310 tmp = flgr_get_array_##dtype(pbufg,n); \
00311 tmp = max(tmp, flgr_get_array_##dtype(pbufh,p)); \
00312 flgr_set_array_##dtype(pdest,m,tmp); \
00313 n++;p++;m++; \
00314 } \
00315 n--; \
00316 kpad = row_size%sesize_x; \
00317 kpad = (kpad==0) ? 0 : sesize_x-kpad; \
00318 for( j=0 ; (j < kpad) && ( m < row_size); j++) { \
00319 tmp = flgr_get_array_##dtype(pbufg,n); \
00320 tmp = max(tmp, flgr_get_array_##dtype(pbufh,p)); \
00321 flgr_set_array_##dtype(pdest,m,tmp); \
00322 m++;p++; \
00323 } \
00324 for( j=m ; j<row_size ; j++) { \
00325 tmp = flgr_get_array_##dtype(pbufh,p++); \
00326 flgr_set_array_##dtype(pdest,j,tmp); \
00327 } \
00328 \
00329 return
00330
00331
00332
00334
00336 #define FLGR_MACRO_INTERNAL_ERODE_ROW_HGW(dtype) \
00337 int j,k,l,m=0,n=0,p=0,se2=sesize_x/2; \
00338 int kpad; \
00339 dtype *pbufg,*pbufh; \
00340 dtype tmp; \
00341 \
00342 \
00343 \
00344 pbufg=tmp1; \
00345 pbufh=tmp2; \
00346 \
00347 tmp = flgr_get_array_##dtype(psrc,0); \
00348 flgr_set_array_##dtype(pbufg,0,tmp); \
00349 \
00350 tmp = flgr_get_array_##dtype(psrc,row_size-1); \
00351 flgr_set_array_##dtype(pbufh,row_size-1,tmp); \
00352 \
00353 \
00354 for( j=1,k=row_size-2,l=row_size-1 ; j<row_size ; j++,k--,l--) { \
00355 if(j%sesize_x==0) { \
00356 tmp = flgr_get_array_##dtype(psrc,j); \
00357 flgr_set_array_##dtype(pbufg,j,tmp); \
00358 }else { \
00359 tmp = flgr_get_array_##dtype(pbufg,j-1); \
00360 tmp = min(tmp, flgr_get_array_##dtype(psrc,j)); \
00361 flgr_set_array_##dtype(pbufg,j,tmp); \
00362 } \
00363 \
00364 if(l%sesize_x==0) { \
00365 tmp = flgr_get_array_##dtype(psrc,k); \
00366 flgr_set_array_##dtype(pbufh,k,tmp); \
00367 }else { \
00368 tmp = flgr_get_array_##dtype(pbufh,l); \
00369 tmp = min(tmp, flgr_get_array_##dtype(psrc,k)); \
00370 flgr_set_array_##dtype(pbufh,k,tmp); \
00371 } \
00372 } \
00373 \
00374 n=se2;p=0;m=0; \
00375 for( j=0; j<se2 ; j++) { \
00376 tmp = flgr_get_array_##dtype(pbufg,n++); \
00377 flgr_set_array_##dtype(pdest,m++,tmp); \
00378 } \
00379 for( j=se2; j<row_size-se2 ;j++) { \
00380 tmp = flgr_get_array_##dtype(pbufg,n); \
00381 tmp = min(tmp, flgr_get_array_##dtype(pbufh,p)); \
00382 flgr_set_array_##dtype(pdest,m,tmp); \
00383 n++;p++;m++; \
00384 } \
00385 n--; \
00386 kpad = row_size%sesize_x; \
00387 kpad = (kpad==0) ? 0 : sesize_x-kpad; \
00388 for( j=0 ; (j<kpad) && (m<row_size); j++) { \
00389 tmp = flgr_get_array_##dtype(pbufg,n); \
00390 tmp = min(tmp, flgr_get_array_##dtype(pbufh,p)); \
00391 flgr_set_array_##dtype(pdest,m,tmp); \
00392 m++;p++; \
00393 } \
00394 for( j=m ; j<row_size ; j++) { \
00395 tmp = flgr_get_array_##dtype(pbufh,p++); \
00396 flgr_set_array_##dtype(pdest,j,tmp); \
00397 } \
00398 \
00399 return
00400
00401
00402
00403
00404
00405
00406 void flgr1d_internal_dilate_line_fgBIT(fgBIT *pdest,fgBIT *psrc,
00407 fgBIT *tmp1, fgBIT *tmp2,
00408 int row_size, int sesize_x) {
00409 FLGR_MACRO_INTERNAL_DILATE_ROW_Lemonnier(fgBIT);
00410 }
00411 void flgr1d_internal_dilate_line_fgUINT8(fgUINT8 *pdest,fgUINT8 *psrc,
00412 fgUINT8 *tmp1, fgUINT8 *tmp2,
00413 int row_size, int sesize_x) {
00414 FLGR_MACRO_INTERNAL_DILATE_ROW_HGW(fgUINT8);
00415 }
00416 void flgr1d_internal_dilate_line_fgUINT16(fgUINT16 *pdest,fgUINT16 *psrc,
00417 fgUINT16 *tmp1, fgUINT16 *tmp2,
00418 int row_size, int sesize_x) {
00419 FLGR_MACRO_INTERNAL_DILATE_ROW_Lemonnier(fgUINT16);
00420 }
00421 void flgr1d_internal_dilate_line_fgUINT32(fgUINT32 *pdest,fgUINT32 *psrc,
00422 fgUINT32 *tmp1, fgUINT32 *tmp2,
00423 int row_size, int sesize_x) {
00424 FLGR_MACRO_INTERNAL_DILATE_ROW_Lemonnier(fgUINT32);
00425 }
00426 void flgr1d_internal_dilate_line_fgINT8(fgINT8 *pdest,fgINT8 *psrc,
00427 fgINT8 *tmp1, fgINT8 *tmp2,
00428 int row_size, int sesize_x) {
00429 FLGR_MACRO_INTERNAL_DILATE_ROW_Lemonnier(fgINT8);
00430 }
00431 void flgr1d_internal_dilate_line_fgINT16(fgINT16 *pdest,fgINT16 *psrc,
00432 fgINT16 *tmp1, fgINT16 *tmp2,
00433 int row_size, int sesize_x) {
00434 FLGR_MACRO_INTERNAL_DILATE_ROW_Lemonnier(fgINT16);
00435 }
00436 void flgr1d_internal_dilate_line_fgINT32(fgINT32 *pdest,fgINT32 *psrc,
00437 fgINT32 *tmp1, fgINT32 *tmp2,
00438 int row_size, int sesize_x) {
00439 FLGR_MACRO_INTERNAL_DILATE_ROW_Lemonnier(fgINT32);
00440 }
00441 void flgr1d_internal_dilate_line_fgFLOAT32(fgFLOAT32 *pdest,fgFLOAT32 *psrc,
00442 fgFLOAT32 *tmp1, fgFLOAT32 *tmp2,
00443 int row_size, int sesize_x) {
00444 FLGR_MACRO_INTERNAL_DILATE_ROW_Lemonnier(fgFLOAT32);
00445 }
00446 void flgr1d_internal_dilate_line_fgFLOAT64(fgFLOAT64 *pdest,fgFLOAT64 *psrc,
00447 fgFLOAT64 *tmp1, fgFLOAT64 *tmp2,
00448 int row_size, int sesize_x) {
00449 FLGR_MACRO_INTERNAL_DILATE_ROW_Lemonnier(fgFLOAT64);
00450 }
00451
00452
00453 void flgr1d_internal_erode_line_fgBIT(fgBIT *pdest,fgBIT *psrc,
00454 fgBIT *tmp1, fgBIT *tmp2,
00455 int row_size, int sesize_x) {
00456 FLGR_MACRO_INTERNAL_ERODE_ROW_Lemonnier(fgBIT);
00457 }
00458 void flgr1d_internal_erode_line_fgUINT8(fgUINT8 *pdest,fgUINT8 *psrc,
00459 fgUINT8 *tmp1, fgUINT8 *tmp2,
00460 int row_size, int sesize_x) {
00461 FLGR_MACRO_INTERNAL_ERODE_ROW_Lemonnier(fgUINT8);
00462 }
00463 void flgr1d_internal_erode_line_fgUINT16(fgUINT16 *pdest,fgUINT16 *psrc,
00464 fgUINT16 *tmp1, fgUINT16 *tmp2,
00465 int row_size, int sesize_x) {
00466 FLGR_MACRO_INTERNAL_ERODE_ROW_Lemonnier(fgUINT16);
00467 }
00468 void flgr1d_internal_erode_line_fgUINT32(fgUINT32 *pdest,fgUINT32 *psrc,
00469 fgUINT32 *tmp1, fgUINT32 *tmp2,
00470 int row_size, int sesize_x) {
00471 FLGR_MACRO_INTERNAL_ERODE_ROW_Lemonnier(fgUINT32);
00472 }
00473 void flgr1d_internal_erode_line_fgINT8(fgINT8 *pdest,fgINT8 *psrc,
00474 fgINT8 *tmp1, fgINT8 *tmp2,
00475 int row_size, int sesize_x) {
00476 FLGR_MACRO_INTERNAL_ERODE_ROW_Lemonnier(fgINT8);
00477 }
00478 void flgr1d_internal_erode_line_fgINT16(fgINT16 *pdest,fgINT16 *psrc,
00479 fgINT16 *tmp1, fgINT16 *tmp2,
00480 int row_size, int sesize_x) {
00481 FLGR_MACRO_INTERNAL_ERODE_ROW_Lemonnier(fgINT16);
00482 }
00483 void flgr1d_internal_erode_line_fgINT32(fgINT32 *pdest,fgINT32 *psrc,
00484 fgINT32 *tmp1, fgINT32 *tmp2,
00485 int row_size, int sesize_x) {
00486 FLGR_MACRO_INTERNAL_ERODE_ROW_Lemonnier(fgINT32);
00487 }
00488 void flgr1d_internal_erode_line_fgFLOAT32(fgFLOAT32 *pdest,fgFLOAT32 *psrc,
00489 fgFLOAT32 *tmp1, fgFLOAT32 *tmp2,
00490 int row_size, int sesize_x) {
00491 FLGR_MACRO_INTERNAL_ERODE_ROW_HGW(fgFLOAT32);
00492 }
00493 void flgr1d_internal_erode_line_fgFLOAT64(fgFLOAT64 *pdest,fgFLOAT64 *psrc,
00494 fgFLOAT64 *tmp1, fgFLOAT64 *tmp2,
00495 int row_size, int sesize_x) {
00496 FLGR_MACRO_INTERNAL_ERODE_ROW_HGW(fgFLOAT64);
00497 }
00498
00499
00500
00501
00503
00505 #define FLGR_MACRO_DILATE1D_LINE(dtype) \
00506 dtype *psrc = (dtype*) datsrc->array; \
00507 dtype *pdest = (dtype*) datdest->array; \
00508 dtype *tmp1; \
00509 dtype *tmp2; \
00510 \
00511 \
00512 \
00513 tmp1 = (dtype*) flgr_malloc_align(datsrc->length*sizeof(dtype), 16); \
00514 tmp2 = (dtype*) flgr_malloc_align(datsrc->length*sizeof(dtype), 16); \
00515 \
00516 flgr1d_internal_dilate_line_##dtype(pdest,psrc,tmp1,tmp2, \
00517 datsrc->length,sesize_x); \
00518 \
00519 flgr_free_align(tmp1); \
00520 flgr_free_align(tmp2)
00521
00522 void flgr1d_dilate_line_fgBIT(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00523 FLGR_MACRO_DILATE1D_LINE(fgBIT);
00524 }
00525 void flgr1d_dilate_line_fgUINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00526 FLGR_MACRO_DILATE1D_LINE(fgUINT8);
00527 }
00528 void flgr1d_dilate_line_fgUINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00529 FLGR_MACRO_DILATE1D_LINE(fgUINT16);
00530 }
00531 void flgr1d_dilate_line_fgUINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00532 FLGR_MACRO_DILATE1D_LINE(fgUINT32);
00533 }
00534 void flgr1d_dilate_line_fgINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00535 FLGR_MACRO_DILATE1D_LINE(fgINT8);
00536 }
00537 void flgr1d_dilate_line_fgINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00538 FLGR_MACRO_DILATE1D_LINE(fgINT16);
00539 }
00540 void flgr1d_dilate_line_fgINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00541 FLGR_MACRO_DILATE1D_LINE(fgINT32);
00542 }
00543 void flgr1d_dilate_line_fgFLOAT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00544 FLGR_MACRO_DILATE1D_LINE(fgFLOAT32);
00545 }
00546 void flgr1d_dilate_line_fgFLOAT64(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00547 FLGR_MACRO_DILATE1D_LINE(fgFLOAT64);
00548 }
00550
00556
00557 FLGR_Ret flgr1d_dilate_line(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00558 FLGR_Ret ret;
00559
00560
00561
00562 if((datdest==NULL) || (datsrc==NULL)) {
00563 POST_ERROR("Null object\n");
00564 return FLGR_RET_NULL_OBJECT;
00565 }
00566
00567 if((ret=flgr1d_is_data_same_attributes(datdest,datsrc,__FUNCTION__))!=FLGR_RET_OK) return ret;
00568
00569 if(datsrc->spp!=1) {
00570 POST_ERROR("Could not process data with spp != 1!\n");
00571 return FLGR_RET_PARAM_ERROR;
00572 }
00573
00574 if(sesize_x>datsrc->length) {
00575 POST_ERROR("fast dilation could not be done with se width > image width\n");
00576 return FLGR_RET_PARAM_ERROR;
00577 }
00578
00579 FLGR_DISPATCH_PROCEDURE(datsrc->type,flgr1d_dilate_line,datdest,datsrc,sesize_x);
00580 }
00581
00582
00583
00585
00587 #define FLGR_MACRO_ERODE1D_LINE(dtype) \
00588 dtype *psrc = (dtype*) datsrc->array; \
00589 dtype *pdest = (dtype*) datdest->array; \
00590 dtype *tmp1; \
00591 dtype *tmp2; \
00592 \
00593 \
00594 \
00595 tmp1 = (dtype*) flgr_malloc_align(datsrc->length*sizeof(dtype), 16); \
00596 tmp2 = (dtype*) flgr_malloc_align(datsrc->length*sizeof(dtype), 16); \
00597 \
00598 flgr1d_internal_erode_line_##dtype(pdest,psrc,tmp1,tmp2, \
00599 datsrc->length,sesize_x); \
00600 \
00601 flgr_free_align(tmp1); \
00602 flgr_free_align(tmp2)
00603
00604 void flgr1d_erode_line_fgBIT(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00605 FLGR_MACRO_ERODE1D_LINE(fgBIT);
00606 }
00607 void flgr1d_erode_line_fgUINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00608 FLGR_MACRO_ERODE1D_LINE(fgUINT8);
00609 }
00610 void flgr1d_erode_line_fgUINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00611 FLGR_MACRO_ERODE1D_LINE(fgUINT16);
00612 }
00613 void flgr1d_erode_line_fgUINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00614 FLGR_MACRO_ERODE1D_LINE(fgUINT32);
00615 }
00616 void flgr1d_erode_line_fgINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00617 FLGR_MACRO_ERODE1D_LINE(fgINT8);
00618 }
00619 void flgr1d_erode_line_fgINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00620 FLGR_MACRO_ERODE1D_LINE(fgINT16);
00621 }
00622 void flgr1d_erode_line_fgINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00623 FLGR_MACRO_ERODE1D_LINE(fgINT32);
00624 }
00625 void flgr1d_erode_line_fgFLOAT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00626 FLGR_MACRO_ERODE1D_LINE(fgFLOAT32);
00627 }
00628 void flgr1d_erode_line_fgFLOAT64(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00629 FLGR_MACRO_ERODE1D_LINE(fgFLOAT64);
00630 }
00632
00638
00639 FLGR_Ret flgr1d_erode_line(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00640 FLGR_Ret ret;
00641
00642
00643
00644 if((datdest==NULL) || (datsrc==NULL)) {
00645 POST_ERROR("Null object\n");
00646 return FLGR_RET_NULL_OBJECT;
00647 }
00648
00649 if((ret=flgr1d_is_data_same_attributes(datdest,datsrc,__FUNCTION__))!=FLGR_RET_OK) return ret;
00650
00651 if(datsrc->spp!=1) {
00652 POST_ERROR("Could not process data with spp != 1!\n");
00653 return FLGR_RET_PARAM_ERROR;
00654 }
00655
00656 if(sesize_x>datsrc->length) {
00657 POST_ERROR("fast erosion could not be done with se width > image width\n");
00658 return FLGR_RET_PARAM_ERROR;
00659 }
00660
00661 FLGR_DISPATCH_PROCEDURE(datsrc->type,flgr1d_erode_line,datdest,datsrc,sesize_x);
00662 }
00663
00664
00666
00672
00673 FLGR_Ret flgr1d_open_line(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00674 FLGR_Ret ret;
00675 FLGR_Data1D *dattmp;
00676
00677
00678
00679 if((datdest==NULL) || (datsrc==NULL)){
00680 POST_ERROR("Null objects!\n");
00681 return FLGR_RET_NULL_OBJECT;
00682 }
00683
00684 dattmp =flgr1d_create_signal(datsrc->length, datsrc->spp, datsrc->type);
00685 if(dattmp==NULL) return FLGR_RET_ALLOCATION_ERROR;
00686
00687
00688 if((ret=flgr1d_erode_line(dattmp,datsrc,sesize_x))!=0)
00689 return ret;
00690 if((ret=flgr1d_dilate_line(datdest,dattmp,sesize_x))!=0)
00691 return ret;
00692
00693 flgr1d_destroy(dattmp);
00694
00695 return ret;
00696 }
00697
00699
00705
00706 FLGR_Ret flgr1d_close_line(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00707 FLGR_Ret ret;
00708 FLGR_Data1D *dattmp;
00709
00710
00711
00712 if((datdest==NULL) || (datsrc==NULL)){
00713 POST_ERROR("Null objects!\n");
00714 return FLGR_RET_NULL_OBJECT;
00715 }
00716
00717 dattmp =flgr1d_create_signal(datsrc->length, datsrc->spp, datsrc->type);
00718 if(dattmp==NULL) return FLGR_RET_ALLOCATION_ERROR;
00719
00720
00721 if((ret=flgr1d_dilate_line(dattmp,datsrc,sesize_x))!=0)
00722 return ret;
00723 if((ret=flgr1d_erode_line(datdest,dattmp,sesize_x))!=0)
00724 return ret;
00725
00726 flgr1d_destroy(dattmp);
00727
00728 return ret;
00729 }
00730
00731
00733
00739
00740 FLGR_Ret flgr1d_open_tophat_line(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00741 FLGR_Ret ret;
00742 FLGR_Data1D *dattmp;
00743
00744
00745
00746 if((datdest==NULL) || (datsrc==NULL)){
00747 POST_ERROR("Null objects!\n");
00748 return FLGR_RET_NULL_OBJECT;
00749 }
00750
00751 dattmp =flgr1d_create_signal(datsrc->length, datsrc->spp, datsrc->type);
00752 if(dattmp==NULL) return FLGR_RET_ALLOCATION_ERROR;
00753
00754
00755 if((ret=flgr1d_erode_line(dattmp,datsrc,sesize_x))!=0)
00756 return ret;
00757 if((ret=flgr1d_dilate_line(datdest,dattmp,sesize_x))!=0)
00758 return ret;
00759 if((ret=flgr1d_arith_sub(datdest,datsrc,datdest))!=0)
00760 return ret;
00761
00762
00763 flgr1d_destroy(dattmp);
00764
00765 return ret;
00766 }
00767
00769
00775
00776 FLGR_Ret flgr1d_close_tophat_line(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, int sesize_x) {
00777 FLGR_Ret ret;
00778 FLGR_Data1D *dattmp;
00779
00780
00781
00782 if((datdest==NULL) || (datsrc==NULL)){
00783 POST_ERROR("Null objects!\n");
00784 return FLGR_RET_NULL_OBJECT;
00785 }
00786
00787 dattmp =flgr1d_create_signal(datsrc->length, datsrc->spp, datsrc->type);
00788 if(dattmp==NULL) return FLGR_RET_ALLOCATION_ERROR;
00789
00790
00791 if((ret=flgr1d_dilate_line(dattmp,datsrc,sesize_x))!=0)
00792 return ret;
00793 if((ret=flgr1d_erode_line(datdest,dattmp,sesize_x))!=0)
00794 return ret;
00795 if((ret=flgr1d_arith_sub(datdest,datdest,datsrc))!=0)
00796 return ret;
00797
00798
00799 flgr1d_destroy(dattmp);
00800
00801 return ret;
00802 }
00803
00804
00805
00806
00807
00809
00811 #define FLGR_MACRO_DILATE2D_LINE(dtype) \
00812 dtype *psrc; \
00813 dtype *pdest; \
00814 dtype *tmp1; \
00815 dtype *tmp2; \
00816 int i; \
00817 \
00818 \
00819 \
00820 tmp1 = (dtype*) flgr_malloc_align(datsrc->size_x*sizeof(dtype), 16); \
00821 tmp2 = (dtype*) flgr_malloc_align(datsrc->size_x*sizeof(dtype), 16); \
00822 \
00823 for(i=0 ; i<datsrc->size_y ; i++) { \
00824 psrc = (dtype*) datsrc->array[i]; \
00825 pdest = (dtype*) datdest->array[i]; \
00826 flgr1d_internal_dilate_line_##dtype(pdest,psrc,tmp1,tmp2, \
00827 datsrc->size_x,sesize_x); \
00828 } \
00829 \
00830 \
00831 flgr_free_align(tmp1); \
00832 flgr_free_align(tmp2)
00833
00834 void flgr2d_dilate_line_horizontal_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int sesize_x) {
00835 FLGR_MACRO_DILATE2D_LINE(fgBIT);
00836 }
00837 void flgr2d_dilate_line_horizontal_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int sesize_x) {
00838 #if defined(__SSE2__) || (defined(__SSE__) && defined(__MMX__))
00839
00840 flgr2d_dilate_segment_horizontal_fast_fgUINT8(datdest,datsrc,sesize_x);
00841 #else
00842 FLGR_MACRO_DILATE2D_LINE(fgUINT8);
00843 #endif
00844 }
00845 void flgr2d_dilate_line_horizontal_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int sesize_x) {
00846 FLGR_MACRO_DILATE2D_LINE(fgUINT16);
00847 }
00848 void flgr2d_dilate_line_horizontal_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int sesize_x) {
00849 FLGR_MACRO_DILATE2D_LINE(fgUINT32);
00850 }
00851 void flgr2d_dilate_line_horizontal_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int sesize_x) {
00852 FLGR_MACRO_DILATE2D_LINE(fgINT8);
00853 }
00854 void flgr2d_dilate_line_horizontal_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int sesize_x) {
00855 FLGR_MACRO_DILATE2D_LINE(fgINT16);
00856 }
00857 void flgr2d_dilate_line_horizontal_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int sesize_x) {
00858 FLGR_MACRO_DILATE2D_LINE(fgINT32);
00859 }
00860 void flgr2d_dilate_line_horizontal_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int sesize_x) {
00861 FLGR_MACRO_DILATE2D_LINE(fgFLOAT32);
00862 }
00863 void flgr2d_dilate_line_horizontal_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int sesize_x) {
00864 FLGR_MACRO_DILATE2D_LINE(fgFLOAT64);
00865 }
00867
00873
00874 FLGR_Ret flgr2d_dilate_line_horizontal(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int sesize_x) {
00875 FLGR_Ret ret;
00876
00877
00878
00879 if((datdest==NULL) || (datsrc==NULL)) {
00880 POST_ERROR("Null object\n");
00881 return FLGR_RET_NULL_OBJECT;
00882 }
00883
00884 if((ret=flgr2d_is_data_same_attributes(datdest,datsrc,__FUNCTION__))!=FLGR_RET_OK) return ret;
00885
00886 if(datsrc->spp!=1) {
00887 POST_ERROR("Could not process data with spp != 1!\n");
00888 return FLGR_RET_PARAM_ERROR;
00889 }
00890
00891 if(sesize_x>datsrc->size_x) {
00892 POST_ERROR("fast dilation could not be done with se width > image width\n");
00893 return FLGR_RET_PARAM_ERROR;
00894 }
00895
00896 FLGR_DISPATCH_PROCEDURE(datsrc->type,flgr2d_dilate_line_horizontal,datdest,datsrc,sesize_x);
00897 }
00898
00899
00900
00901
00903
00905 #define FLGR_MACRO_ERODE2D_LINE(dtype) \
00906 dtype *psrc; \
00907 dtype *pdest; \
00908 dtype *tmp1; \
00909 dtype *tmp2; \
00910 int i; \
00911 \
00912 \
00913 \
00914 tmp1 = (dtype*) flgr_malloc_align(datsrc->size_x*sizeof(dtype), 16); \
00915 tmp2 = (dtype*) flgr_malloc_align(datsrc->size_x*sizeof(dtype), 16); \
00916 \
00917 for(i=0 ; i<datsrc->size_y ; i++) { \
00918 psrc = (dtype*) datsrc->array[i]; \
00919 pdest = (dtype*) datdest->array[i]; \
00920 flgr1d_internal_erode_line_##dtype(pdest,psrc,tmp1,tmp2, \
00921 datsrc->size_x,sesize_x); \
00922 } \
00923 \
00924 \
00925 flgr_free_align(tmp1); \
00926 flgr_free_align(tmp2)
00927
00928 void flgr2d_erode_line_horizontal_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int sesize_x) {
00929 FLGR_MACRO_ERODE2D_LINE(fgBIT);
00930 }
00931 void flgr2d_erode_line_horizontal_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int sesize_x) {
00932 #if defined(__SSE2__) || (defined(__SSE__) && defined(__MMX__))
00933
00934 flgr2d_erode_segment_horizontal_fast_fgUINT8(datdest,datsrc,sesize_x);
00935 #else
00936 FLGR_MACRO_ERODE2D_LINE(fgUINT8);
00937 #endif
00938 }
00939 void flgr2d_erode_line_horizontal_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int sesize_x) {
00940 FLGR_MACRO_ERODE2D_LINE(fgUINT16);
00941 }
00942 void flgr2d_erode_line_horizontal_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int sesize_x) {
00943 FLGR_MACRO_ERODE2D_LINE(fgUINT32);
00944 }
00945 void flgr2d_erode_line_horizontal_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int sesize_x) {
00946 FLGR_MACRO_ERODE2D_LINE(fgINT8);
00947 }
00948 void flgr2d_erode_line_horizontal_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int sesize_x) {
00949 FLGR_MACRO_ERODE2D_LINE(fgINT16);
00950 }
00951 void flgr2d_erode_line_horizontal_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int sesize_x) {
00952 FLGR_MACRO_ERODE2D_LINE(fgINT32);
00953 }
00954 void flgr2d_erode_line_horizontal_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int sesize_x) {
00955 FLGR_MACRO_ERODE2D_LINE(fgFLOAT32);
00956 }
00957 void flgr2d_erode_line_horizontal_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int sesize_x) {
00958 FLGR_MACRO_ERODE2D_LINE(fgFLOAT64);
00959 }
00961
00967
00968 FLGR_Ret flgr2d_erode_line_horizontal(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int sesize_x) {
00969 FLGR_Ret ret;
00970
00971
00972
00973 if((datdest==NULL) || (datsrc==NULL)) {
00974 POST_ERROR("Null object\n");
00975 return FLGR_RET_NULL_OBJECT;
00976 }
00977
00978 if((ret=flgr2d_is_data_same_attributes(datdest,datsrc,__FUNCTION__))!=FLGR_RET_OK) return ret;
00979
00980 if(datsrc->spp!=1) {
00981 POST_ERROR("Could not process data with spp != 1!\n");
00982 return FLGR_RET_PARAM_ERROR;
00983 }
00984
00985 if(sesize_x>datsrc->size_x) {
00986 POST_ERROR("fast erosion could not be done with se width > image width\n");
00987 return FLGR_RET_PARAM_ERROR;
00988 }
00989
00990
00991 FLGR_DISPATCH_PROCEDURE(datsrc->type,flgr2d_erode_line_horizontal,datdest,datsrc,sesize_x);
00992 }
00993
00994
00995
00996
00998
01000 #define FLGR_MACRO_ERODE_DILATE_2D_RECTANGLE(op,dtype) \
01001 FLGR_Data2D *img1,*img2,*img3; \
01002 \
01003 \
01004 \
01005 img1 = flgr2d_create_##dtype(imgsrc->size_y,imgsrc->size_x, \
01006 imgsrc->spp, \
01007 FLGR_NO_SHAPE,FLGR_NO_CONNEX); \
01008 \
01009 img2 = flgr2d_create_##dtype(imgsrc->size_x,imgsrc->size_y, \
01010 imgsrc->spp, \
01011 FLGR_NO_SHAPE,FLGR_NO_CONNEX); \
01012 \
01013 img3 = flgr2d_create_##dtype(imgsrc->size_x,imgsrc->size_y, \
01014 imgsrc->spp, \
01015 FLGR_NO_SHAPE,FLGR_NO_CONNEX); \
01016 \
01017 flgr2d_##op##_line_horizontal_##dtype(img1,imgsrc,sesize_x); \
01018 \
01019 flgr2d_transpose_##dtype(img2,img1); \
01020 \
01021 flgr2d_##op##_line_horizontal_##dtype(img3,img2,sesize_y); \
01022 \
01023 flgr2d_transpose_##dtype(imgdest,img3); \
01024 \
01025 flgr2d_destroy(img1); \
01026 flgr2d_destroy(img2); \
01027 flgr2d_destroy(img3)
01028
01029
01030 void flgr2d_dilate_rectangle_fgBIT(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01031 FLGR_MACRO_ERODE_DILATE_2D_RECTANGLE(dilate,fgBIT);
01032 }
01033 void flgr2d_dilate_rectangle_fgUINT8(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01034 #if defined(__SSE2__) || ((defined(__SSE__) && defined(__MMX__)))
01035 FLGR_Data2D *imgtmp;
01036
01037
01038
01039 if((sesize_x==1) && (sesize_y==1)) {
01040 flgr2d_copy(imgdest,imgsrc);
01041 }else if((sesize_x==1) && (sesize_y!=1)) {
01042 flgr2d_dilate_segment_vertical_fast_fgUINT8(imgdest,imgsrc,sesize_y);
01043 }else if((sesize_x!=1) && (sesize_y==1)) {
01044 flgr2d_dilate_segment_horizontal_fast_fgUINT8(imgdest,imgsrc,sesize_x);
01045 }else{
01046 imgtmp = flgr2d_create_from(imgsrc);
01047 flgr2d_dilate_segment_horizontal_fast_fgUINT8(imgtmp,imgsrc,sesize_x);
01048 flgr2d_dilate_segment_vertical_fast_fgUINT8(imgdest,imgtmp,sesize_y);
01049 flgr2d_destroy(imgtmp);
01050 }
01051
01052 #else
01053 FLGR_MACRO_ERODE_DILATE_2D_RECTANGLE(dilate,fgUINT8);
01054 #endif
01055 }
01056 void flgr2d_dilate_rectangle_fgUINT16(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01057 FLGR_MACRO_ERODE_DILATE_2D_RECTANGLE(dilate,fgUINT16);
01058 }
01059 void flgr2d_dilate_rectangle_fgUINT32(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01060 FLGR_MACRO_ERODE_DILATE_2D_RECTANGLE(dilate,fgUINT32);
01061 }
01062 void flgr2d_dilate_rectangle_fgINT8(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01063 FLGR_MACRO_ERODE_DILATE_2D_RECTANGLE(dilate,fgINT8);
01064 }
01065 void flgr2d_dilate_rectangle_fgINT16(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01066 FLGR_MACRO_ERODE_DILATE_2D_RECTANGLE(dilate,fgINT16);
01067 }
01068 void flgr2d_dilate_rectangle_fgINT32(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01069 FLGR_MACRO_ERODE_DILATE_2D_RECTANGLE(dilate,fgINT32);
01070 }
01071 void flgr2d_dilate_rectangle_fgFLOAT32(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01072 FLGR_MACRO_ERODE_DILATE_2D_RECTANGLE(dilate,fgFLOAT32);
01073 }
01074 void flgr2d_dilate_rectangle_fgFLOAT64(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01075 FLGR_MACRO_ERODE_DILATE_2D_RECTANGLE(dilate,fgFLOAT64);
01076 }
01077
01078 void flgr2d_erode_rectangle_fgBIT(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01079 FLGR_MACRO_ERODE_DILATE_2D_RECTANGLE(erode,fgBIT);
01080 }
01081 void flgr2d_erode_rectangle_fgUINT8(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01082 #if defined(__SSE2__) || (defined(__SSE__) && defined(__MMX__))
01083 FLGR_Data2D *imgtmp;
01084
01085
01086
01087 if((sesize_x==1) && (sesize_y==1)) {
01088 flgr2d_copy(imgdest,imgsrc);
01089 }else if((sesize_x==1) && (sesize_y!=1)) {
01090 flgr2d_erode_segment_vertical_fast_fgUINT8(imgdest,imgsrc,sesize_y);
01091 }else if((sesize_x!=1) && (sesize_y==1)) {
01092 flgr2d_erode_segment_horizontal_fast_fgUINT8(imgdest,imgsrc,sesize_x);
01093 }else{
01094 imgtmp = flgr2d_create_from(imgsrc);
01095 flgr2d_erode_segment_horizontal_fast_fgUINT8(imgtmp,imgsrc,sesize_x);
01096 flgr2d_erode_segment_vertical_fast_fgUINT8(imgdest,imgtmp,sesize_y);
01097 flgr2d_destroy(imgtmp);
01098 }
01099
01100 #else
01101 FLGR_MACRO_ERODE_DILATE_2D_RECTANGLE(erode,fgUINT8);
01102 #endif
01103 }
01104 void flgr2d_erode_rectangle_fgUINT16(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01105 FLGR_MACRO_ERODE_DILATE_2D_RECTANGLE(erode,fgUINT16);
01106 }
01107 void flgr2d_erode_rectangle_fgUINT32(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01108 FLGR_MACRO_ERODE_DILATE_2D_RECTANGLE(erode,fgUINT32);
01109 }
01110 void flgr2d_erode_rectangle_fgINT8(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01111 FLGR_MACRO_ERODE_DILATE_2D_RECTANGLE(erode,fgINT8);
01112 }
01113 void flgr2d_erode_rectangle_fgINT16(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01114 FLGR_MACRO_ERODE_DILATE_2D_RECTANGLE(erode,fgINT16);
01115 }
01116 void flgr2d_erode_rectangle_fgINT32(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01117 FLGR_MACRO_ERODE_DILATE_2D_RECTANGLE(erode,fgINT32);
01118 }
01119 void flgr2d_erode_rectangle_fgFLOAT32(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01120 FLGR_MACRO_ERODE_DILATE_2D_RECTANGLE(erode,fgFLOAT32);
01121 }
01122 void flgr2d_erode_rectangle_fgFLOAT64(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01123 FLGR_MACRO_ERODE_DILATE_2D_RECTANGLE(erode,fgFLOAT64);
01124 }
01125
01126
01127
01129
01136
01137 FLGR_Ret flgr2d_dilate_rectangle(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01138 FLGR_Ret ret;
01139
01140
01141
01142 if((imgdest==NULL) || (imgsrc==NULL)){
01143 POST_ERROR("Null objects!\n");
01144 return FLGR_RET_NULL_OBJECT;
01145 }
01146
01147
01148 if((ret=flgr2d_is_data_same_attributes(imgdest,imgsrc,__FUNCTION__))!=FLGR_RET_OK) return ret;
01149
01150 if(imgsrc->spp!=1) {
01151 POST_ERROR("Could not process data with spp != 1!\n");
01152 return FLGR_RET_PARAM_ERROR;
01153 }
01154
01155 if(sesize_y>imgsrc->size_y) {
01156 POST_ERROR("fast dilation could not be done with se height > image height\n");
01157 return FLGR_RET_PARAM_ERROR;
01158 }
01159
01160 if(sesize_x>imgsrc->size_x) {
01161 POST_ERROR("fast dilation could not be done with se width > image width\n");
01162 return FLGR_RET_PARAM_ERROR;
01163 }
01164
01165 FLGR_DISPATCH_PROCEDURE(imgdest->type,flgr2d_dilate_rectangle,imgdest,imgsrc,sesize_x,sesize_y);
01166
01167 }
01168
01169
01171
01178
01179 FLGR_Ret flgr2d_erode_rectangle(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01180 FLGR_Ret ret;
01181
01182
01183
01184 if((imgdest==NULL) || (imgsrc==NULL)){
01185 POST_ERROR("Null objects!\n");
01186 return FLGR_RET_NULL_OBJECT;
01187 }
01188
01189 if((ret=flgr2d_is_data_same_attributes(imgdest,imgsrc,__FUNCTION__))!=FLGR_RET_OK) return ret;
01190
01191 if(imgsrc->spp!=1) {
01192 POST_ERROR("Could not process data with spp != 1!\n");
01193 return FLGR_RET_PARAM_ERROR;
01194 }
01195
01196 if(sesize_y>imgsrc->size_y) {
01197 POST_ERROR("fast erosion could not be done with se height > image height\n");
01198 return FLGR_RET_NOT_IMPLEMENTED;
01199 }
01200
01201 if(sesize_x>imgsrc->size_x) {
01202 POST_ERROR("fast erosion could not be done with se width > image width\n");
01203 return FLGR_RET_NOT_IMPLEMENTED;
01204 }
01205
01206 FLGR_DISPATCH_PROCEDURE(imgdest->type,flgr2d_erode_rectangle,imgdest,imgsrc,sesize_x,sesize_y);
01207
01208 }
01209
01210
01211
01212
01213
01215
01222
01223 FLGR_Ret flgr2d_open_line_horizontal(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x) {
01224 FLGR_Ret ret;
01225 FLGR_Data2D *imgtmp;
01226
01227
01228
01229 if((imgdest==NULL) || (imgsrc==NULL)){
01230 POST_ERROR("Null objects!\n");
01231 return FLGR_RET_NULL_OBJECT;
01232 }
01233
01234 imgtmp =flgr2d_create_pixmap(imgsrc->size_y, imgsrc->size_x,imgsrc->spp, imgsrc->type);
01235 if(imgtmp==NULL) return FLGR_RET_ALLOCATION_ERROR;
01236
01237
01238 if((ret=flgr2d_erode_line_horizontal(imgtmp,imgsrc,sesize_x))!=0)
01239 return ret;
01240 if((ret=flgr2d_dilate_line_horizontal(imgdest,imgtmp,sesize_x))!=0)
01241 return ret;
01242
01243 flgr2d_destroy(imgtmp);
01244
01245 return ret;
01246
01247 }
01248
01250
01256
01257 FLGR_Ret flgr2d_close_line_horizontal(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x) {
01258 FLGR_Ret ret;
01259 FLGR_Data2D *imgtmp;
01260
01261
01262
01263 if((imgdest==NULL) || (imgsrc==NULL)){
01264 POST_ERROR("Null objects!\n");
01265 return FLGR_RET_NULL_OBJECT;
01266 }
01267
01268 imgtmp =flgr2d_create_pixmap(imgsrc->size_y, imgsrc->size_x,imgsrc->spp, imgsrc->type);
01269 if(imgtmp==NULL) return FLGR_RET_ALLOCATION_ERROR;
01270
01271 if((ret=flgr2d_dilate_line_horizontal(imgtmp,imgsrc,sesize_x))!=0)
01272 return ret;
01273 if((ret=flgr2d_erode_line_horizontal(imgdest,imgtmp,sesize_x))!=0)
01274 return ret;
01275
01276 flgr2d_destroy(imgtmp);
01277
01278 return ret;
01279
01280 }
01281
01282
01284
01291
01292 FLGR_Ret flgr2d_open_rectangle(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01293 FLGR_Ret ret;
01294 FLGR_Data2D *imgtmp;
01295
01296
01297
01298 if((imgdest==NULL) || (imgsrc==NULL)){
01299 POST_ERROR("Null objects!\n");
01300 return FLGR_RET_NULL_OBJECT;
01301 }
01302
01303 imgtmp =flgr2d_create_pixmap(imgsrc->size_y, imgsrc->size_x,imgsrc->spp, imgsrc->type);
01304 if(imgtmp==NULL) return FLGR_RET_ALLOCATION_ERROR;
01305
01306 if((ret=flgr2d_erode_rectangle(imgtmp,imgsrc,sesize_x,sesize_y))!=0)
01307 return ret;
01308 if((ret=flgr2d_dilate_rectangle(imgdest,imgtmp,sesize_x,sesize_y))!=0)
01309 return ret;
01310
01311 flgr2d_destroy(imgtmp);
01312
01313 return ret;
01314
01315 }
01316
01317
01319
01326
01327 FLGR_Ret flgr2d_close_rectangle(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01328 FLGR_Ret ret;
01329 FLGR_Data2D *imgtmp;
01330
01331
01332
01333 if((imgdest==NULL) || (imgsrc==NULL)){
01334 POST_ERROR("Null objects!\n");
01335 return FLGR_RET_NULL_OBJECT;
01336 }
01337
01338 imgtmp =flgr2d_create_pixmap(imgsrc->size_y, imgsrc->size_x,imgsrc->spp, imgsrc->type);
01339 if(imgtmp==NULL) return FLGR_RET_ALLOCATION_ERROR;
01340
01341 if((ret=flgr2d_dilate_rectangle(imgtmp,imgsrc,sesize_x,sesize_y))!=0)
01342 return ret;
01343 if((ret=flgr2d_erode_rectangle(imgdest,imgtmp,sesize_x,sesize_y))!=0)
01344 return ret;
01345
01346 flgr2d_destroy(imgtmp);
01347
01348 return ret;
01349
01350 }
01351
01352
01353
01355
01361
01362 FLGR_Ret flgr2d_open_tophat_line_horizontal(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x) {
01363 FLGR_Ret ret;
01364 FLGR_Data2D *imgtmp;
01365
01366
01367
01368 if((imgdest==NULL) || (imgsrc==NULL)){
01369 POST_ERROR("Null objects!\n");
01370 return FLGR_RET_NULL_OBJECT;
01371 }
01372
01373 imgtmp =flgr2d_create_pixmap(imgsrc->size_y, imgsrc->size_x,imgsrc->spp, imgsrc->type);
01374 if(imgtmp==NULL) return FLGR_RET_ALLOCATION_ERROR;
01375
01376 if((ret=flgr2d_erode_line_horizontal(imgtmp,imgsrc,sesize_x))!=0)
01377 return ret;
01378 if((ret=flgr2d_dilate_line_horizontal(imgdest,imgtmp,sesize_x))!=0)
01379 return ret;
01380
01381 flgr2d_arith_sub(imgdest,imgsrc,imgdest);
01382
01383 flgr2d_destroy(imgtmp);
01384
01385 return ret;
01386
01387 }
01388
01390
01396
01397 FLGR_Ret flgr2d_close_tophat_line_horizontal(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x) {
01398 FLGR_Ret ret;
01399 FLGR_Data2D *imgtmp;
01400
01401
01402
01403 if((imgdest==NULL) || (imgsrc==NULL)){
01404 POST_ERROR("Null objects!\n");
01405 return FLGR_RET_NULL_OBJECT;
01406 }
01407
01408 imgtmp =flgr2d_create_pixmap(imgsrc->size_y, imgsrc->size_x,imgsrc->spp, imgsrc->type);
01409 if(imgtmp==NULL) return FLGR_RET_ALLOCATION_ERROR;
01410
01411 if((ret=flgr2d_dilate_line_horizontal(imgtmp,imgsrc,sesize_x))!=0)
01412 return ret;
01413 if((ret=flgr2d_erode_line_horizontal(imgdest,imgtmp,sesize_x))!=0)
01414 return ret;
01415
01416 flgr2d_arith_sub(imgdest,imgdest,imgsrc);
01417
01418 flgr2d_destroy(imgtmp);
01419
01420 return ret;
01421
01422 }
01423
01424
01425
01426
01428
01435
01436 FLGR_Ret flgr2d_open_tophat_rectangle(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01437 FLGR_Ret ret;
01438 FLGR_Data2D *imgtmp;
01439
01440
01441
01442 if((imgdest==NULL) || (imgsrc==NULL)){
01443 POST_ERROR("Null objects!\n");
01444 return FLGR_RET_NULL_OBJECT;
01445 }
01446
01447 imgtmp =flgr2d_create_pixmap(imgsrc->size_y, imgsrc->size_x,imgsrc->spp, imgsrc->type);
01448 if(imgtmp==NULL) return FLGR_RET_ALLOCATION_ERROR;
01449
01450 if((ret=flgr2d_erode_rectangle(imgtmp,imgsrc,sesize_x,sesize_y))!=0)
01451 return ret;
01452 if((ret=flgr2d_dilate_rectangle(imgdest,imgtmp,sesize_x,sesize_y))!=0)
01453 return ret;
01454
01455 if((ret=flgr2d_arith_sub(imgdest,imgsrc,imgdest))!=0)
01456 return ret;
01457
01458 flgr2d_destroy(imgtmp);
01459
01460 return ret;
01461
01462 }
01463
01465
01472
01473 FLGR_Ret flgr2d_close_tophat_rectangle(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, int sesize_x, int sesize_y) {
01474 FLGR_Ret ret;
01475 FLGR_Data2D *imgtmp;
01476
01477
01478
01479 if((imgdest==NULL) || (imgsrc==NULL)){
01480 POST_ERROR("Null objects!\n");
01481 return FLGR_RET_NULL_OBJECT;
01482 }
01483
01484 imgtmp =flgr2d_create_pixmap(imgsrc->size_y, imgsrc->size_x,imgsrc->spp, imgsrc->type);
01485 if(imgtmp==NULL) return FLGR_RET_ALLOCATION_ERROR;
01486
01487 if((ret=flgr2d_dilate_rectangle(imgtmp,imgsrc,sesize_x,sesize_y))!=0)
01488 return ret;
01489 if((ret=flgr2d_erode_rectangle(imgdest,imgtmp,sesize_x,sesize_y))!=0)
01490 return ret;
01491
01492 if((ret=flgr2d_arith_sub(imgdest,imgdest,imgsrc))!=0)
01493 return ret;
01494
01495
01496 flgr2d_destroy(imgtmp);
01497
01498 return ret;
01499
01500 }
01501
01502