1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
| /*---------------------------------------------------------------------------
Programme labelise1.c
Ce programme labelise un fichier image de type 8 bits (extension.ech,.cla)
et cree un fichier binaire (extension .lab)
qui contient l'image labelisee.
---------------------------------------------------------------------------*/
/* Bibliotheques */
#include "labelise1.h"
#include "outils_c.h"
#include "lect_inf.h"
/**********************/
/* VARIABLES GLOBALES */
/**********************/
/* Noms internes des fichiers */
FILE *FichInTxt; /* Nom interne du fichier d'entree */
/* contenant la taille de l'image */
FILE *Fichinv; /* Nom interne d'un fichier temporaire qui */
/* va contenir l'image ecrite a l'envers */
/* lors du parcour en sens inverse */
FILE *FichInCla; /* Nom interne du fichier d'entree */
/* contenant l'image */
FILE *FichTemp; /* Nom interne du fichier temporaire */
FILE *FichRes; /* Nom interne du fichier de sortie */
/* contenant l'image labelisee */
/* Tableau qui va servir a regrouper les labels */
float *regroup_label;
/***************************************************************************/
/******************************** PROCEDURE ********************************/
/***************************************************************************/
/***************************************************************************/
/* Cette procedure cree un fichier binaire contenant l'image ou ont ete */
/* tous les labels de necessaire pour l'image */
/***************************************************************************/
void Creation_Labels(NomFich EntreeCla,int lig_deb,int col_deb,int taille_lig,int taille_col,float *nb_labels)
{
int nolig,nocol,k; /* Numero de ligne et de colonne */
float **nlimCla; /* Matrice contenant temporairement */
/* une ligne de l'image a labeliser */
int **ImagEch; /* Matrice contenant temporairement */
/* 2 lignes de l'image a labeliser */
float *ImagLab; /* Vecteur contenant temporairement */
/* l'image ou ont ete cree les labels*/
float *Image; /* Vecteur contenant la ligne precedente */
/* de l'image ou ont ete cree les labels */
float nolab=0.0; /* Numero de label */
NomFich Temp; /* Nom du fichier temporaire ou */
/* va etre ecrite l'image labelisee */
/* Allocations dynamiques */
ImagEch=imatrix(0,1,0,taille_col-1);
ImagLab=vector(0,taille_col-1);
Image=vector(0,taille_col-1);
nlimCla=matrix(0,1,0,nbcol-1);
/* ouverture en lecture du fichier image */
ofl(&FichInCla,EntreeCla);
/* Creation du fichier temporaire pour creer les labels */
strcpy(Temp,EntreeCla);
strcat(Temp,".temp");
ofe(&FichTemp,Temp);
printf("\nCreation des labels ...\n");
/* Lecture pour arriver a la premiere ligne a traiter */
fseek(FichInCla,lig_deb*nbcol*sizeof(unsigned char),SEEK_SET);
nolig=lig_deb;
lect_1can(FichInCla,nolig,1,nlimCla,2);
//pour chaque colonne de la première ligne
for(nocol=0;nocol<nbcol;nocol++)
{
//si l'on ne dépasse pas les limites de l'image
if ((nocol>=col_deb) && (nocol<taille_col+col_deb))
{
ImagEch[1][nocol-col_deb]=(int)nlimCla[0][nocol];
//si c'est la première colonne
if (nocol==col_deb)
{
//Si l'on est dans la classe 0 le label du pixel courant devient 0
if (ImagEch[1][nocol-col_deb]==0)
ImagLab[nocol-col_deb]=0.0;
//sinon c'est un nouveau label
else
{
nolab++;
ImagLab[nocol-col_deb]=nolab;
}
}
//si on n'est pas dans le premiere colonne
else
{
//Si l'on est dans la classe 0 le label du pixel courant devient 0
if (ImagEch[1][nocol-col_deb]==0)
ImagLab[nocol-col_deb]=0.0;
else
{
//SI la classe du pixel courrant est la meme que celle du pixel précédent on est dans le même label
if ( ImagEch[1][nocol-col_deb] == ImagEch[1][nocol-col_deb-1])
ImagLab[nocol-col_deb]=ImagLab[nocol-col_deb-1];
//sinon c'est un nouveau label
else
{
nolab++;
ImagLab[nocol-col_deb]=nolab;
}
}
}
}
}
ecrit_1can_nbcol(FichTemp,ImagLab,1,taille_col);
/* traitement de toutes les autres lignes */
for (nolig=lig_deb+1;nolig<taille_lig+lig_deb;nolig++)
{
lect_1can(FichInCla,nolig,1,nlimCla,2);
for (k=0;k<nbcol;k++)
{
if ((k >= col_deb) && (k < taille_col+col_deb))
{
ImagEch[0][k-col_deb]=ImagEch[1][k-col_deb];
ImagEch[1][k-col_deb]=(int)nlimCla[0][k];
Image[k-col_deb]=ImagLab[k-col_deb];
}
}
//pour chaque colonne de ces lignes
for (nocol=0;nocol<nbcol;nocol++)
{
if ((nocol >= col_deb) && (nocol < taille_col+col_deb))
{
if (nocol==col_deb)
{
if (ImagEch[1][nocol-col_deb]==0)
ImagLab[nocol-col_deb] = 0.0;
else
{
if (ImagEch[1][nocol-col_deb]==ImagEch[0][nocol-col_deb])
ImagLab[nocol-col_deb] = Image[nocol-col_deb];
else
{
if (ImagEch[1][nocol-col_deb]==ImagEch[0][nocol-col_deb+1])
ImagLab[nocol-col_deb] = Image[nocol-col_deb+1];
else
{
nolab++;
ImagLab[nocol-col_deb] = nolab;
}
}
}
}
else
{
if (nocol == taille_col+col_deb-1)
{
if (ImagEch[1][nocol-col_deb]==0)
ImagLab[nocol-col_deb]=0.0;
else
{
if (ImagEch[1][nocol-col_deb]==ImagEch[1][nocol-col_deb-1])
ImagLab[nocol-col_deb]=ImagLab[nocol-col_deb-1];
else
{
if (ImagEch[1][nocol-col_deb]==ImagEch[0][nocol-col_deb-1])
ImagLab[nocol-col_deb]=Image[nocol-col_deb-1];
else
{
if (ImagEch[1][nocol-col_deb]==ImagEch[0][nocol-col_deb])
ImagLab[nocol-col_deb]=Image[nocol-col_deb];
else
{
nolab++;
ImagLab[nocol-col_deb] = nolab;
}
}
}
}
}
else
{
if (ImagEch[1][nocol-col_deb]==0)
ImagLab[nocol-col_deb]=0.0;
else
{
if (ImagEch[1][nocol-col_deb]==ImagEch[1][nocol-col_deb-1])
ImagLab[nocol-col_deb]=ImagLab[nocol-1-col_deb];
else
{
if (ImagEch[1][nocol-col_deb]==ImagEch[0][nocol-col_deb-1])
ImagLab[nocol-col_deb]=Image[nocol-1-col_deb];
else
{
if (ImagEch[1][nocol-col_deb]==ImagEch[0][nocol-col_deb])
ImagLab[nocol-col_deb]=Image[nocol-col_deb];
else
{
if (ImagEch[1][nocol-col_deb]==ImagEch[0][nocol+1-col_deb])
ImagLab[nocol-col_deb]=Image[nocol+1-col_deb];
else
{
nolab++;
ImagLab[nocol-col_deb] = nolab;
}
}
}
}
}
}
}
}
}
ecrit_1can_nbcol(FichTemp,ImagLab,1,taille_col);
}
*nb_labels=nolab;
fclose(FichTemp);
fclose(FichInCla);
free_imatrix( ImagEch,0,1,0,taille_col-1);
free_vector(ImagLab,0,taille_col-1);
free_vector(Image,0,taille_col-1);
free_matrix(nlimCla,0,1,0,taille_col-1);
}
/***********************************************************/
/* Procedure qui permet de lire l'image reduite */
/***********************************************************/
void lect_1can_nbcol(FILE *fichima, int nolig, int tfen, float **nli,int type_canal,int nbcol)
{
/* PROCEDURE DE LECTURE D'IMAGE DE TOUT TYPE */
/* */
/* type_canal =1 ----> flottant */
/* type_canal =2 ----> octet 8_bit */
/* type_canal =3 ----> 16_bit poids fort-poids faible */
/* type_canal =4 ----> 16_bit poids faible-poids fort */
long dep;
int i,k;
unsigned char *loct;
loct = cvector(0,2*nbcol);
switch (type_canal){
case 1 : {
dep=(long)(nolig*nbcol*4);
fseek(fichima,dep,SEEK_SET);
for (i=0;i<tfen;i++)
fread(nli[i],4,nbcol,fichima);
break;
}
case 2 : {
dep=(long)(nolig*nbcol);
fseek(fichima,dep,SEEK_SET);
for (i=0;i<tfen;i++)
{
fread(loct,1,nbcol,fichima);
for (k=0;k<nbcol;k++)
nli[i][k] = (float)loct[k];
}
break;
}
case 3 : {
dep=(long)(nolig*nbcol*2);
fseek(fichima,dep,SEEK_SET);
for (i=0;i<tfen;i++)
{
fread(loct,1,2*nbcol,fichima);
for (k=0;k<nbcol;k++)
nli[i][k] = (float)loct[2*k]*256+(float)loct[2*k+1];
}
break;
}
case 4 : {
dep=(long)(nolig*nbcol*2);
fseek(fichima,dep,SEEK_SET);
for (i=0;i<tfen;i++)
{
fread(loct,1,2*nbcol,fichima);
for (k=0;k<nbcol;k++)
nli[i][k] = (float)loct[2*k+1]*256+(float)loct[2*k];
}
break;
}
default : {
printf("\nProcedure de lecture d'image 1 canal\nType du canal : %d non repertorie!!!\nexit...\n",type_canal);
exit(1);
}
}
free_cvector(loct,0,2*nbcol);
}
/**************************************************************************/
/* Procedure qui detecte les labels a regrouper */
/**************************************************************************/
void Recherche_Regroup_Label(NomFich nom_cla,int lig_deb,int col_deb,int taille_lig,int taille_col,int *fin)
{
int nolig,nocol; /* Numero de ligne et de colonne */
float **nlimCla,**nlimLab; /* Matrice contenant temporairement */
/* une ligne de l'image a labeliser */
int **ImagEch; /* Matrice contenant temporairement */
/* 2 lignes de l'image a labeliser */
float **ImagLab; /* Vecteur contenant temporairement */
/* l'image ou ont ete cree les labels*/
NomFich Temp,Sortie; /* Nom du fichier temporaire ou */
/* va etre ecrite l'image labelisee */
/* Allocations dynamiques */
ImagEch=imatrix(0,1,0,taille_col-1);
ImagLab=matrix(0,1,0,taille_col-1);
nlimCla=matrix(0,1,0,nbcol-1);
nlimLab=matrix(0,1,0,taille_col-1);
/* ouverture en lecture du fichier image */
ofl(&FichInCla,nom_cla);
strcpy(Sortie,nom_cla);
strcat(Sortie,".lab");
strcpy(Temp,nom_cla);
strcat(Temp,".temp");
ofl(&FichTemp,Temp);
fseek(FichInCla,lig_deb*nbcol*sizeof(unsigned char),SEEK_SET);
nolig=lig_deb;
for (nolig=lig_deb;nolig<(lig_deb+taille_lig);nolig++)
{
lect_1can(FichInCla,nolig,1,nlimCla,2);
lect_1can_nbcol(FichTemp,(nolig-lig_deb),1,nlimLab,1,taille_col);
for (nocol=col_deb;nocol<(taille_col+col_deb);nocol++)
{
if (nolig == lig_deb)
{
ImagEch[1][nocol-col_deb]=(int)nlimCla[0][nocol];
ImagLab[1][nocol-col_deb]=nlimLab[0][nocol-col_deb];
}
else
{
ImagEch[0][nocol-col_deb]=ImagEch[1][nocol-col_deb];
ImagLab[0][nocol-col_deb]=ImagLab[1][nocol-col_deb];
ImagEch[1][nocol-col_deb]=(int)nlimCla[0][nocol];
ImagLab[1][nocol-col_deb]=nlimLab[0][nocol-col_deb];
}
}
for (nocol=col_deb;nocol<(taille_col+col_deb);nocol++)
{
/* debut traitement de la premiere ligne */
if (nolig==lig_deb)
{
if(nocol != col_deb)
{
if ((ImagEch[1][nocol-col_deb]==ImagEch[1][nocol-col_deb-1])&&(ImagLab[1][nocol-col_deb]!=ImagLab[1][nocol-col_deb-1]))
{
if (ImagLab[1][nocol-col_deb] < ImagLab[1][nocol-col_deb-1])
{
regroup_label[(long)ImagLab[1][nocol-col_deb-1]]=ImagLab[1][nocol-col_deb];
*fin = 0;
}
else
{
regroup_label[(long)ImagLab[1][nocol-col_deb]]=ImagLab[1][nocol-col_deb-1];
*fin=0;
}
}
}
}
/*fin du traitement de la premiere ligne */
else
{
/* traitement des autres lignes : cas 1 colonne */
if (nocol==col_deb)
{
if ((ImagEch[1][nocol-col_deb]==ImagEch[0][nocol-col_deb])&&(ImagLab[1][nocol-col_deb]!=ImagLab[0][nocol-col_deb]))
{
if (ImagLab[1][nocol-col_deb] < ImagLab[0][nocol-col_deb])
{
regroup_label[(long)ImagLab[0][nocol-col_deb]]=ImagLab[1][nocol-col_deb];
*fin = 0;
}
else
{
regroup_label[(long)ImagLab[1][nocol-col_deb]]=ImagLab[0][nocol-col_deb];
*fin = 0;
}
}
if ((ImagEch[1][nocol-col_deb]==ImagEch[0][nocol-col_deb+1])&&(ImagLab[1][nocol-col_deb]!=ImagLab[0][nocol-col_deb+1]))
{
if (ImagLab[1][nocol-col_deb] < ImagLab[0][nocol-col_deb+1])
{
regroup_label[(long)ImagLab[0][nocol-col_deb+1]]=ImagLab[1][nocol-col_deb];
*fin = 0;
}
else
{
regroup_label[(long)ImagLab[1][nocol-col_deb]]=ImagLab[0][nocol-col_deb+1];
*fin = 0;
}
}
}
/*fin traitement de la 1 colonne*/
else
{
/* debut traitement derniere colonne */
if (nocol==(col_deb+taille_col-1))
{
if ((ImagEch[1][nocol-col_deb]==ImagEch[1][nocol-col_deb-1])&&(ImagLab[1][nocol-col_deb]!=ImagLab[1][nocol-col_deb-1]))
{
if (ImagLab[1][nocol-col_deb] < ImagLab[1][nocol-col_deb-1])
{
regroup_label[(long)ImagLab[1][nocol-col_deb-1]]=ImagLab[1][nocol-col_deb];
*fin = 0;
}
else
{
regroup_label[(long)ImagLab[1][nocol-col_deb]]=ImagLab[1][nocol-col_deb-1];
*fin = 0;
}
}
if ((ImagEch[1][nocol-col_deb]==ImagEch[0][nocol-col_deb-1])&&(ImagLab[1][nocol-col_deb]!=ImagLab[0][nocol-col_deb-1]))
{
if (ImagLab[1][nocol-col_deb] < ImagLab[0][nocol-col_deb-1])
{
regroup_label[(long)ImagLab[0][nocol-col_deb-1]]=ImagLab[1][nocol-col_deb];
*fin = 0;
}
else
{
regroup_label[(long)ImagLab[1][nocol-col_deb]]=ImagLab[0][nocol-col_deb-1];
*fin = 0;
}
}
if ((ImagEch[1][nocol-col_deb]==ImagEch[0][nocol-col_deb])&&(ImagLab[1][nocol-col_deb]!=ImagLab[0][nocol-col_deb]))
{
if (ImagLab[1][nocol-col_deb] < ImagLab[0][nocol-col_deb])
{
regroup_label[(long)ImagLab[0][nocol-col_deb]]=ImagLab[1][nocol-col_deb];
*fin = 0;
}
else
{
regroup_label[(long)ImagLab[1][nocol-col_deb]]=ImagLab[0][nocol-col_deb];
*fin = 0;
}
}
}
/* fin traitement de la derniere colonne */
else
{
/* debut traitement cas general */
if ((ImagEch[1][nocol-col_deb]==ImagEch[1][nocol-col_deb-1])&&(ImagLab[1][nocol-col_deb]!=ImagLab[1][nocol-col_deb-1]))
{
if (ImagLab[1][nocol-col_deb] < ImagLab[1][nocol-col_deb-1])
{
regroup_label[(long)ImagLab[1][nocol-col_deb-1]]=ImagLab[1][nocol-col_deb];
*fin = 0;
}
else
{
regroup_label[(long)ImagLab[1][nocol-col_deb]]=ImagLab[1][nocol-col_deb-1];
*fin = 0;
}
}
if ((ImagEch[1][nocol-col_deb]==ImagEch[0][nocol-col_deb-1])&&(ImagLab[1][nocol-col_deb]!=ImagLab[0][nocol-col_deb-1]))
{
if (ImagLab[1][nocol-col_deb] < ImagLab[0][nocol-col_deb-1])
{
regroup_label[(long)ImagLab[0][nocol-col_deb-1]]=ImagLab[1][nocol-col_deb];
*fin = 0;
}
else
{
regroup_label[(long)ImagLab[1][nocol-col_deb]]=ImagLab[0][nocol-col_deb-1];
*fin = 0;
}
}
if ((ImagEch[1][nocol-col_deb]==ImagEch[0][nocol-col_deb])&&(ImagLab[1][nocol-col_deb]!=ImagLab[0][nocol-col_deb]))
{
if (ImagLab[1][nocol-col_deb] < ImagLab[0][nocol-col_deb])
{
regroup_label[(long)ImagLab[0][nocol-col_deb]]=ImagLab[1][nocol-col_deb];
*fin = 0;
}
else
{
regroup_label[(long)ImagLab[1][nocol-col_deb]]=ImagLab[0][nocol-col_deb];
*fin = 0;
}
}
if ((ImagEch[1][nocol-col_deb]==ImagEch[0][nocol-col_deb+1])&&(ImagLab[1][nocol-col_deb]!=ImagLab[0][nocol-col_deb+1]))
{
if (ImagLab[1][nocol-col_deb] < ImagLab[0][nocol-col_deb+1])
{
regroup_label[(long)ImagLab[0][nocol-col_deb+1]]=ImagLab[1][nocol-col_deb];
*fin = 0;
}
else
{
regroup_label[(long)ImagLab[1][nocol-col_deb]]=ImagLab[0][nocol-col_deb+1];
*fin = 0;
}
}
}
}
}
}
}
fclose(FichInCla);
fclose(FichTemp);
free_imatrix(ImagEch,0,1,0,taille_col-1);
free_matrix(ImagLab,0,1,0,taille_col-1);
free_matrix(nlimCla,0,1,0,nbcol-1);
free_matrix(nlimLab,0,1,0,taille_col-1);
}
/***************************************************************************/
/* Procedure qui met a jour le tableau des labels englobes */
/***************************************************************************/
void Actualiser_Tableau(float nb_labels,int *modif)
{
long i;
for (i=0;i<(long)nb_labels+1;i++)
{
if (regroup_label[i]!= (float)i)
{
if (regroup_label[(long)regroup_label[i]] != regroup_label[i])
{
regroup_label[i]=regroup_label[(long)regroup_label[i]];
*modif=1;
}
}
}
}
/***************************************************************************/
/* Procedure qui permet de reecrire l'image */
/***************************************************************************/
void Ecrire_image(NomFich nom_cla,int taille_lig,int taille_col)
{
int nolig,nocol; /* Numero de ligne et de colonne */
float **nlimLab; /* Matrice contenant temporairement */
/* une ligne de l'image a labeliser */
float *ImagLab;
NomFich Temp,Sortie; /* Nom du fichier temporaire ou */
/* va etre ecrite l'image labelisee */
strcpy(Temp,nom_cla);
strcat(Temp,".temp");
strcpy(Sortie,nom_cla);
strcat(Sortie,".lab");
/* Allocations dynamiques */
ImagLab=vector(0,taille_col-1);
nlimLab=matrix(0,1,0,taille_col-1);
/* ouverture en lecture du fichier image */
ofl(&FichTemp,Temp);
ofe(&FichRes,Sortie);
//pour chaque ligne
for(nolig=0;nolig<taille_lig;nolig++)
{
lect_1can_nbcol(FichTemp,nolig,1,nlimLab,1,taille_col);
//pour chaque colonne
for (nocol=0;nocol<taille_col;nocol++){
ImagLab[nocol] = regroup_label[(long)nlimLab[0][nocol]];
}
ecrit_1can_nbcol(FichRes,ImagLab,1,taille_col);
}
fclose(FichTemp);
fclose(FichRes);
remove(Temp);
free_vector(ImagLab,0,taille_col-1);
free_matrix(nlimLab,0,1,0,taille_col-1);
}
/****************************************************************************/
/* Procedure qui permet de renumeroter les labels lorsqu'il y'a des vides */
/****************************************************************************/
void Renumerotation(float *nb_max)
{
float numero;
long i;
numero=0.0;
for (i=1;i<=*nb_max;i++)
{
if (regroup_label[i]==(float)i)
{
numero++;
regroup_label[i]=numero;
}
}
*nb_max = numero;
}
/****************************************************************************/
/**************************** PROGRAMME PRINCIPAL ***************************/
/****************************************************************************/
int main(int argc, char **argv)
{
int ech_def,inf_def,dim_fen,noarg; /* Variables de lecture des parametres */
int lig_deb = 0,col_deb = 0,taille_lig = 0,taille_col = 0,modif,fin;
long i;
char *c;
float nb_labels=0.0;
NomFich EntreeTxt; /* Fichier contenant la taille des images */
NomFich EntreeCla; /* Fichier echantillon */
NomFich nom1,nom2;
c=" ";
inf_def=ech_def=dim_fen=0;
/*************************************************/
/* Passage des parametres a l'appel du programme */
/*************************************************/
if (argc>1)
{
noarg=1;
do
{
/* Si Demande d'aide */
if (strcmp(argv[noarg],"help")==0)
{
printf("\nOPTIONS DU PROGRAMME :\n");
printf("\t< -inf > : Nom du fichier texte (extension .inf) sans extension\n");
printf("\t\t contenant la taille de l'image\n");
printf("\t< -img> : Nom du fichier image echantillon\n");
printf("\t< -fen > : taille de la fenetre\n");
exit(1);
}
/* Passage du fichier texte en parametre */
else if (strcmp(argv[noarg],"-inf")==0)
{
inf_def=1;
noarg++;
/* Lecture du fichier texte */
sscanf(argv[noarg],"%s",EntreeTxt);
strcat(EntreeTxt,".inf");
ofl(&FichInTxt,EntreeTxt);
/* Recuperation de la taille de l'image */
fscanf(FichInTxt,"%ld",&nbcol);
fscanf(FichInTxt,"%ld",&nblig);
fclose(FichInTxt);
noarg++;
}
/* Passage du nom du fichier image en parametre */
else if (strcmp(argv[noarg],"-img")==0)
{
ech_def=1;
noarg++;
/* Lecture du nom du fichier image */
sscanf(argv[noarg],"%s",EntreeCla);
noarg++;
}
/* Coordonnees de la fenetre */
else if (strcmp(argv[noarg],"-fen")==0)
{
dim_fen=1;
noarg++;
sscanf(argv[noarg],"%s",c);
lig_deb=atoi(c);
noarg++;
sscanf(argv[noarg],"%s",c);
col_deb=atoi(c);
noarg++;
sscanf(argv[noarg],"%s",c);
taille_lig=atoi(c);
noarg++;
sscanf(argv[noarg],"%s",c);
taille_col=atoi(c);
noarg++;
}
/* Si option inconnue */
else {
printf("\n\toption <%s> inconnue. Sortie du programme...\n\n",argv[noarg]);
exit(1);
}
}while (noarg<argc);
}
/************************************************************/
/* Traitement des parametres faisant defaut lors de l'appel */
/************************************************************/
if (!inf_def)
{
inf_def=1;
printf("Quel est le nom du fichier .inf (sans extension):");
scanf("%s",EntreeTxt);
strcat(EntreeTxt,".inf");
ofl(&FichInTxt,EntreeTxt);
/* Recuperation de la taille de l'image */
fscanf(FichInTxt,"%ld",&nbcol);
fscanf(FichInTxt,"%ld",&nblig);
fflush(stdin);fflush(stdout);
}
if (!ech_def)
{
ech_def=1;
printf("Quel est le nom du fichier a labeliser(avec extension):");
/* Lecture du nom du fichier a labeliser */
scanf("%s",EntreeCla);
ofl(&FichInCla,EntreeCla);
fflush(stdin);
fflush(stdout);
}
if (!dim_fen)
{
lig_deb=0;
col_deb=0;
taille_lig=nblig;
taille_col=nbcol;
}
/**************************/
/* Execution du programme */
/**************************/
printf("\n Labelisation du fichier %s\n",EntreeCla);
Creation_Labels(EntreeCla,lig_deb,col_deb,taille_lig,taille_col,&nb_labels);
regroup_label=vector(0,nb_labels);
for (i=0;i<(long)nb_labels+1;i++)
regroup_label[i]=i;
printf("\n Recherche des labels a englober ... \n");
fin=0;
strcpy(nom1,EntreeCla);
strcpy(nom2,EntreeCla);
strcat(nom1,".lab");
strcat(nom2,".temp");
while (fin!=1)
{
fin=1;
Recherche_Regroup_Label(EntreeCla,lig_deb,col_deb,taille_lig,taille_col,&fin);
modif=1;
while (modif !=0)
{
modif=0;
Actualiser_Tableau(nb_labels,&modif);
}
Ecrire_image(EntreeCla,taille_lig,taille_col);
if (fin != 1)
{
rename(nom1,nom2);
remove(nom1);
}
}
printf("\n Renumerotation des labels ...\n");
Renumerotation(&nb_labels);
printf("\n Nombre de labels = %.1f\n",nb_labels);
rename(nom1,nom2);
remove(nom1);
printf("\n Ecriture de l'image resultat %s\n",nom1);
Ecrire_image(EntreeCla,taille_lig,taille_col);
free_vector(regroup_label,0,nb_labels);
printf("\nExecution Terminee\n");
return EXIT_SUCCESS;
} |
Partager