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

📄 hscp.c

📁 squelletisation using HSCP
💻 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;
    
  int Bp,Ap1,Ap2,Ap4,Bp4,Bp5,Ap5,Bp6,Ap6,flag,nbi=0;
  int i,j,x,y,nbr;
  int mat[256][256];
  int mat1[256][256];
 
   
image_in=fopen("matrice_0_1.txt","r"); 
  
	if (image_in == NULL) 
	{ 
		printf("erreur d'ouverture du fichier source\n");
	}
for(i = 0 ; i < 256 ; i++)
{
  for (j=0;j<256;j++)
{
     fscanf(image_in,"%d ",&mat[i][j]);

	 mat1[i][j]=mat[i][j];
	
}
}
fclose(image_in);
	
do
{
	flag=0;
	printf("le nb d'iterration=%d\n",nbi++);
for( x=1;x<255;x++)
{
        for( y=1;y<255;y++)
        {
        Bp=0;
        Ap1=0;
        Ap4=0;
		Bp4=0;
		Ap5=0;
		Bp5=0;
		Ap6=0;
		Bp6=0;

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

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

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



		/***********************************Bp5*******************/
		if (mat[x][y+1]==1)Bp5=Bp5+1;
		if (mat[x][y+2]==1)Bp5=Bp5+1;
		if (mat[x+1][y+2]==1)Bp5=Bp5+1;
		if (mat[x+2][y+2]==1)Bp5=Bp5+1;
		if (mat[x+2][y+1]==1)Bp5=Bp5+1;
	    if (mat[x+2][y]==1)Bp5=Bp5+1;
		if (mat[x+1][y]==1)Bp5=Bp5+1;
		if (mat[x][y]==1)Bp5=Bp5+1;
		/*********************************************************/

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


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

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




		 /******************** les conditions *********************/
 
 
        if ((mat[x][y]==1)&&(Bp>=2 && Bp<=6) && (Ap1==1))
        { 
			      if((mat[x-1][y]==mat[x+1][y]==1))
				  {
					  if(((Bp4<=2 )|| (Bp4>=6))&&(Ap4==1))
					  {
		            	mat[x][y]=0;
						flag=1;
					  }
				  
			
			
			     
				  }
	
				  
		
			     if((mat[x][y]==1)&&mat[x][y+1]==mat[x][y-1]==1)
				 {
					 if(((Bp5<=2)|| (Bp5>=6))||(Ap5!=1)) 
					 {

				 
			           mat[x][y]=0;
			        
				flag=1;
					 } 
				 }
			 if((mat[x][y]==1)&&((Bp6<=2)||( Bp6>=6))||(Ap6==1))
			 {
				 if(((Bp5<=2) ||( Bp5>=6))||(Ap5==1))
				 {
					 if(((Bp4<=2) ||(Bp4>=6))||(Ap4==1))
					 {
			          mat[x][y]=0;
			       

			  	     flag=1;

					 } 

				 }
			 }
		}
		
				
}
}



}
while (flag==1);

image_out=fopen("HSCP.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 + -