⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rutovitz.c

📁 squelletisation using Rutovitz
💻 C
字号:
#include <stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include <time.h>	
#define dim 65536
void main()
{
	
	FILE * image_in;
	FILE * image_out;
	time_t  depart,fin;
	float duree;
    
  int Bp,Ap1,Ap2,Ap4;
  int i,j,x,y,k,nbr=0,flag=0;
  int mat[258][258];
  
  
 
   
image_in=fopen("matrice_0_1aug.txt","r"); 
  
	if (image_in == NULL) 
	{ 
		printf("erreur d'ouverture du fichier source\n");
	}
for(i = 0 ; i < 258 ; i++)
{
  for (j=0;j<258;j++)
  {
     fscanf(image_in,"%d ",&mat[i][j]);
	 
	
  }
}
fclose(image_in);

depart=clock();
k=0;	
while(k<1000)
{
		
do
{
    flag=0;
       // printf("le nbr d'itrerration=%d\n",nbr++);
		
    for( x=1;x<257;x++)
	{
        for( y=1;y<257;y++)
        {
        Bp=0;
        Ap1=0;
        Ap2=0;
        Ap4=0;
 
        if (mat[x-1][y-1]==0)Bp=Bp+1;
        if (mat[x-1][y]==0)Bp=Bp+1;
        if (mat[x-1][y+1]==0)Bp=Bp+1;
        if (mat[x][y+1]==0)Bp=Bp+1;
        if (mat[x+1][y+1]==0)Bp=Bp+1;
        if (mat[x+1][y]==0)Bp=Bp+1;
        if (mat[x+1][y-1]==0)Bp=Bp+1;
        if (mat[x][y-1]==0)Bp=Bp+1;
 
        /****************************************************/
		if (mat[x-1][y]==1 && mat[x-1][y+1]==0)Ap1=Ap1+1;
        if (mat[x-1][y]==0 && mat[x-1][y+1]==1)Ap1=Ap1+1;
        if (mat[x-1][y+1]==1 && mat[x][y+1]==0)Ap1=Ap1+1;
        if (mat[x-1][y+1]==0 && mat[x][y+1]==1)Ap1=Ap1+1;
        if (mat[x][y+1]==1 && mat[x+1][y+1]==0)Ap1=Ap1+1;
        if (mat[x][y+1]==0 && mat[x+1][y+1]==1)Ap1=Ap1+1;
        if (mat[x+1][y+1]==1 && mat[x+1][y]==0)Ap1=Ap1+1;
        if (mat[x+1][y+1]==0 && mat[x+1][y]==1)Ap1=Ap1+1;
        if (mat[x+1][y]==1 && mat[x+1][y-1]==0)Ap1=Ap1+1;
        if (mat[x+1][y]==0 && mat[x+1][y-1]==1)Ap1=Ap1+1;
        if (mat[x+1][y-1]==1 && mat[x][y-1]==0)Ap1=Ap1+1;
        if (mat[x+1][y-1]==0 && mat[x][y-1]==1)Ap1=Ap1+1;
        if (mat[x][y-1]==1 && mat[x-1][y-1]==0)Ap1=Ap1+1;
        if (mat[x][y-1]==0 && mat[x-1][y-1]==1)Ap1=Ap1+1;
        if (mat[x-1][y-1]==1 && mat[x-1][y]==0)Ap1=Ap1+1;
        if (mat[x-1][y-1]==0 && mat[x-1][y]==1)Ap1=Ap1+1;

     
 
        /************************************************/
        if (mat[x-2][y]==0 && mat[x-2][y+1]==1)Ap2=Ap2+1;
      if (mat[x-2][y]==1 && mat[x-2][y+1]==0)Ap2=Ap2+1;
        if (mat[x-2][y+1]==0 && mat[x-1][y+1]==1)Ap2=Ap2+1;
     if (mat[x-2][y+1]==1 && mat[x-1][y+1]==0)Ap2=Ap2+1;
        if (mat[x-1][y+1]==0 && mat[x][y+1]==1)Ap2=Ap2+1;
     if (mat[x-1][y+1]==1 && mat[x][y+1]==0)Ap2=Ap2+1;
        if (mat[x][y+1]==0 && mat[x][y]==1)Ap2=Ap2+1;
      if (mat[x][y+1]==1 && mat[x][y]==0)Ap2=Ap2+1;
        if (mat[x][y]==0 && mat[x][y-1]==1)Ap2=Ap2+1;
      if (mat[x][y]==1 && mat[x][y-1]==0)Ap2=Ap2+1;
        if (mat[x][y-1]==0 && mat[x-1][y-1]==1)Ap2=Ap2+1;
      if (mat[x][y-1]==1 && mat[x-1][y-1]==0)Ap2=Ap2+1;
        if (mat[x-1][y-1]==0 && mat[x-2][y-1]==1)Ap2=Ap2+1;
      if (mat[x-1][y-1]==1 && mat[x-2][y-1]==0)Ap2=Ap2+1;
        if (mat[x-2][y-1]==0 && mat[x-2][y]==1)Ap2=Ap2+1;
      if (mat[x-2][y-1]==1 && mat[x-2][y]==0)Ap2=Ap2+1;



		/********************************************************/
 
        
        if (mat[x-1][y+1]==0 && mat[x-1][y+2]==1)Ap4=Ap4+1;
      if (mat[x-1][y+1]==1 && mat[x-1][y+2]==0)Ap4=Ap4+1;
        if (mat[x-1][y+2]==0 && mat[x][y+2]==1)Ap4=Ap4+1;
      if (mat[x-1][y+2]==1 && mat[x][y+2]==0)Ap4=Ap4+1;
        if (mat[x][y+2]==0 && mat[x+1][y+2]==1)Ap4=Ap4+1;
      if (mat[x][y+2]==1 && mat[x+1][y+2]==0)Ap4=Ap4+1;
        if (mat[x+1][y+2]==0 && mat[x+1][y+1]==1)Ap4=Ap4+1;
      if (mat[x+1][y+2]==1 && mat[x+1][y+1]==0)Ap4=Ap4+1;
        if (mat[x+1][y+1]==0 && mat[x][y+1]==1)Ap4=Ap4+1;
      if (mat[x+1][y+1]==1 && mat[x][y+1]==0)Ap4=Ap4+1;
        if (mat[x][y+1]==0 && mat[x][y]==1)Ap4=Ap4+1;
      if (mat[x][y+1]==1 && mat[x][y]==0)Ap4=Ap4+1;
        if (mat[x][y]==0 && mat[x-1][y]==1)Ap4=Ap4+1;
      if (mat[x][y]==1 && mat[x-1][y]==0)Ap4=Ap4+1;
        if (mat[x-1][y]==0 && mat[x-1][y+1]==1)Ap4=Ap4+1;
      if (mat[x-1][y]==1 && mat[x-1][y+1]==0)Ap4=Ap4+1;

 
 /********************les conditions*****************************/
  
        if ((Bp>=2 && Bp<=6) && (Ap1==2)&&(mat[x][y]==1))
        {
            if ((mat[x-1][y]*mat[x][y+1]*mat[x][y-1]==0)||(Ap2!=2) )
			{
               if ((mat[x][y+1]*mat[x-1][y]*mat[x+1][y]==0)||(Ap4!=2) )
                {
                     mat[x][y]=0;
				     flag=1;
					// printf("les position  %d   %d de l'iteration%d\n",x,y,nbr);
                }
			}
        }
		
		
}
	}
//	printf("flag=%d\n",flag);
}		while((flag==1));
	k++;
}
fin=clock();
		duree=(float)(fin-depart)/CLOCKS_PER_SEC;
		printf("la duree en milisecondes=%f\n",duree);


image_out=fopen("rutovitz sq.txt", "w+");
 
	if (image_out == NULL) 
	{
		printf("erreur d'ouverture du fichier destination\n");
	}
	for(i =0; i < 256; i++)
    {
		for(j= 0; j < 256; j++)
		{
					fprintf(image_out,"%d ",mat[i][j]);
			
			
		}
		fprintf(image_out,"\n");
	}


fclose(image_out);

}
 
 
        
        
       
 
      
 
 
    
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -