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
|
while(1){
fifo_remove(&file,p);
/* on regarde si on est arrivee a la fin de la liste */
if(p[0]==-1 && p[1]==-1) /* si p est egale au fictitious pixel*/
{
if(fifo_isempty(file)){ break; }
else
{ fifo_add(&file,&fin_file,FICTITIOUS);
++curdist; fifo_remove(&file,p);}
}
/* determination des voisins de p (on cherche les indices des voisins du pixel p)*/
n_neighboor=neighborhood8(nrow,ncol,p,&q);
/* labelisation de p si ce n'est pas un minimun local */
for(j=0;j<n_neighboor;++j)
{
/* ie q appartient deja a un bassin versant ou a une watershed */
if((dist[q[j][0]][q[j][1]]<curdist) && ((lab[q[j][0]][q[j][1]]>0) || (lab[q[j][0]][q[j][1]]==WSHED)))
{
if(lab[q[j][0]][q[j][1]]>0) /* q appartient seulement a un bassin */
{
if((lab[p[0]][p[1]]==MASK) || (lab[p[0]][p[1]]==WSHED))
{lab[p[0]][p[1]]=lab[q[j][0]][q[j][1]];} /* p appartient a une watershed*/
else if(lab[p[0]][p[1]] != lab[q[j][0]][q[j][1]])
{ lab[p[0]][p[1]]=WSHED;}
}
else if (lab[p[0]][p[1]]==MASK) /* si p est deja sur la watershed */
{ lab[p[0]][p[1]]=WSHED;}
}
else if ((lab[q[j][0]][q[j][1]]==MASK) && (dist[q[j][0]][q[j][1]]==0))
{dist[q[j][0]][q[j][1]]=++curdist;
p_temp=Malloc(2,int);
p_temp[0]=q[j][0];
p_temp[1]=q[j][1]; fifo_add(&file,&fin_file,p_temp) ; }
} Free(q);
}
/* verifie si des nouveaux minima locaux sont detectees*/
for(;tri[k].val==grey_value;++k){
p[0]=tri[k].row;p[1]=tri[k].col;
dist[p[0]][p[1]]=0; //la distance associee a p est initialisee
if(lab[p[0]][p[1]]==MASK)
{ ++curlab;
fifo_add(&file,&fin_file,p);lab[p[0]][p[1]]=curlab;
while(!fifo_isempty(file)){
fifo_remove(&file,p1);
/* determination du voisinage de p1 (on cherche les indices des voisins de p1 ->r)*/
n_neighboor=neighborhood8(nrow,ncol,p1,&r);
for(j=0;j<n_neighboor;++j){
if(lab[r[j][0]][r[j][1]]==MASK){
p_temp=Malloc(2,int);
p_temp[0]=r[j][0];
p_temp[1]=r[j][1];
fifo_add(&file,&fin_file,p_temp);lab[r[j][0]][r[j][1]]=curlab; }
}
Free(r); }
}
}
} |
Partager