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

📄 middle.htm

📁 how to process the file
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0197)http://g1a89.mail.163.com/coremail/fcg/ldmsapp/middle.cpp?lettsid=TBsKwivlWtlheYWoMIllpliznvNTfhcC&mid=1tbiYwpKo0Jwy%252DQZMwAAsn%250A99%250A8388762%250A1&funcid=readpart&part=3&filename=middle.cpp -->
<HTML><HEAD><TITLE></TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<STYLE type=text/css>BODY {
	FONT-SIZE: 14px
}
TD {
	FONT-SIZE: 14px
}
P {
	FONT-SIZE: 14px
}
TH {
	FONT-SIZE: 14px
}
INPUT {
	FONT-SIZE: 12px
}
</STYLE>

<SCRIPT language=javascript src="middle.files/readletter.js"></SCRIPT>

<META content="MSHTML 6.00.2900.2180" name=GENERATOR></HEAD>
<BODY leftMargin=5 topMargin=5 border="0" marginheight="0" marginwidth="0"><PRE style="WIDTH: 100%; WORD-WRAP: break-word">/////////// ///////Digital image processing algorithm /////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////

//Macro definition for use later
#include "math.h"
#include "stdio.h"
#include "process.h"
#include "stdlib.h"

//Function declaration
void copyfile(FILE  *fp);
void histogram(FILE *fp);
void negative(FILE *fp);
void imsharpe(FILE *fp);
void imsmooth(FILE *fp);
void middle(FILE *fp);
unsigned char  sort(unsigned char a[],int n );




//////////////////////////////////////////////////////////////////////////
//Main function calls the subfunctions
void main()
{
	FILE *fp;
	char choose;
	unsigned char c;
    int totpix=0; 
	char filename[10];

//Display some information about the autors's point of view	
    printf("////////////////////////////////////////////////////////////////////////////\n");
	printf("欢迎使用图像处理程序---图像增强篇!!\n");
   	printf("版权所有:徐明才 贾殷嘉 指导教师:高腾\n");

//Ask user to input the file which he or she want to open	
	printf("////////////////////////////////////////////////////////////////////////////\n");
	printf("Please input the filename which you want to open\n");
    scanf("%s",filename);
    
//Get the return key
    getchar();

//Open the corresponding file
	if((fp=fopen(filename,"rb"))==NULL)
	{
		printf("Cannot open the file");
			exit(0);
	}


//Get the basic information about the original image  
//	printf("\n\nInformation about the image\n");
		while(!feof(fp))
	{
		c=fgetc(fp);
	    totpix++;
  	}
//  Let the fp point to the  start of the file again	
	rewind(fp);

//Ask the user to choose the operation needed
    printf("////////////////////////////////////////////////////////////////////////////\n");	
	printf("%Please choose the operation\n\n");
    printf("Press 1  Copy the image!               you will get new file----copy.dat\n\n");	
	printf("Press 2  Negative the image!           you will get new file----negative.dat\n\n");
    printf("Press 3  Histogram equalization!       you will get new file----hist.dat\n\n");
    printf("Press 4  image sharping!               you will get new file----sharpe.dat\n\n");
	printf("Press 5  image smoothing!              you will get new file----smooth.dat\n\n"); 
	printf("Press 6  image middle filtering!       you will get new file----middle.dat\n\n");
    printf("!!!!!If you press any other key .    The program will return the error message!\n");
    printf("////////////////////////////////////////////////////////////////////////////\n");
	printf("You choice is 1 or 2 or 3 or 4 or 5 or 6?  "); 
  

//Judge the input key
again:	
    choose=getchar(); 
	switch(choose)
	{case '1': copyfile(fp);   break;
	 case '2': negative(fp);   break;
	 case '3': histogram(fp);  break;
     case '4': imsharpe(fp);   break;
     case '5': imsmooth(fp);   break;
     case '6': middle(fp);     break;
     default:  printf("\nI am very sorry!\nThere are no operation you need\n");goto again;
	}
    fclose(fp);

//Call the exeutive program  
	system("see.exe");
   
}
/////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////
void copyfile(FILE *fp)
{   FILE *fp1;	
	unsigned char c;
   
	//Create the new1 file
	if((fp1=fopen("copy.dat","wb"))==NULL)
	{
		printf("Cannot create the first file");
			exit(0);
	}
    
	//Read the file byte by byte
	while(!feof(fp))
	{
		c=fgetc(fp);
		fputc(c,fp1);
  	}
   	fclose(fp1);
}
/////////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////////
//The subfunction--negative
//The function is to be used to get the negative image of the origianl image
void negative(FILE *fp)
{   FILE *fp1;	
	unsigned char c;
   
	//Create the new1 file
	if((fp1=fopen("negative.dat","wb"))==NULL)
	{
		printf("Cannot create the first file");
			exit(0);
	}
    
	//Read the file byte by byte
	while(!feof(fp))
	{
		c=fgetc(fp);
		c=255-c;
		fputc(c,fp1);
  	}
   	fclose(fp1);
}
/////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////
//The subfunction--histogram
//The function is  equalizing the original image
void histogram(FILE *fp)
{   FILE *fp1;	
	int i=0;
	int j;
    unsigned char c;
	float sum=0;
	float graylevel[256];
//Initiate the array of graylevel	
	for(j=0;j&lt;256;j++)
	graylevel[j]=0;
	
	if((fp1=fopen("hist.dat","wb"))==NULL)
	{
		printf("Cannot create the first file");
			exit(0);
	}
//Statistatics of the original image
	while(!feof(fp))
	{
		c=fgetc(fp);
        graylevel[c]++;
		i++;
	}
	 
	i=i-1;
	graylevel[255]=graylevel[255]-1;

//Get the probality of the different graylevels
	for(j=0;j&lt;256;j++)
	{graylevel[j]=graylevel[j]/i;
    sum=sum+graylevel[j];
	}
//  Convert the probability
	for(j=1;j&lt;256;j++)
    {graylevel[j]=graylevel[j]+graylevel[j-1];

	}
	
	printf("\n");	
	printf("\n");

//Convrt the old graylevel to the new graylevel   
	for(j=0;j&lt;256;j++)
	{graylevel[j]=(int)(graylevel[j]*255+0.5);
	}
   
	
	printf("\n");	
	printf("\n");

//Change the original image to the new after converting the graylevels
	rewind(fp);
	rewind(fp1);
	while(!feof(fp))
	{
		c=fgetc(fp);
		c=(unsigned char)graylevel[c];
		fputc(c,fp1);
     }


    	fclose(fp1);
}
////////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////////
//The subfunction--imsharpe
//The function is sharping the original image
void imsharpe(FILE *fp1)
	{	FILE *fp2;
	    int  mask[3][3]; 
	    unsigned char img[3][256],transimg[256];
	    unsigned char  firstrow[256]={0},lastrow[256]={0};    /*firstcolumn[256],lastcolumn[256];*/
		int i,k,l,m=0,n=0;
	    int h,g;
	    unsigned int result;
        //Ask user to input the mask      
        printf("Please input the mask which is 3 order\n");
        for(m=0;m&lt;3;m++)
			for(n=0;n&lt;3;n++)
			 scanf("%d",&amp;mask[m][n]);
        getchar();
		printf("\n");
	
		
		
        if((fp2=fopen("sharpe.dat","wb"))==NULL)
		{  	printf("Cannot open the file");
			exit(0);
			   } 
              //Save and write the first row
		      for(i=0;i&lt;256;i++)              
			  {	firstrow[i]=fgetc(fp1);             		               
				 fputc(firstrow[i],fp2);
			  } 
             
			  //Save and write the last row
			  fseek(fp1,255*256,0);               
			  for(i=0;i&lt;256;i++)                  

⌨️ 快捷键说明

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