EDN Admin
Well-known member
Hi Everyone,
Ive problem when I try to run the below code using Visual Studio 2010, Is there anyone can help to solve this problem ?? thanks in advace
<br/>
#include<stdio.h><br/>
#include<stdlib.h><br/>
#include<string.h><br/>
#include<conio.h><br/>
#include<math.h><br/>
#include<iostream><br/>
#include<algorithm><br/>
#include <fstream><br/>
<br/>
<br/>
using namespace std;<br/>
const int size=256,ih=256,iw=256;<br/>
void median(unsigned char **buf,unsigned char **out);<br/>
<br/>
<br/>
void input(char filename[100],unsigned char **buf,int ih,int iw)<br/>
{<br/>
<span style="white-spacere FILE *fp;<br/>
<span style="white-spacere int i,j;<br/>
<br/>
<br/>
if((fp=fopen(filename,"rb"))==NULL)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere printf("File %s open error ! n",filename);<br/>
<span style="white-spacere getch();<br/>
<span style="white-spacere exit(1);<br/>
<span style="white-spacere }<br/>
<br/>
<br/>
<span style="white-spacere for(i=0;i<ih;i++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere for(j=0;j<iw;j++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere buf[j] = (unsigned char)fgetc(fp);<br/>
<span style="white-spacere }<br/>
<span style="white-spacere }<br/>
fclose(fp);<span style="white-spacere <br/>
<br/>
<br/>
}<br/>
<br/>
<br/>
void output(char filename[100],unsigned char **buf,int ih,int iw)<br/>
{<br/>
<span style="white-spacere FILE *fp;<br/>
<span style="white-spacere int i,j;<br/>
<br/>
<br/>
<span style="white-spacere if((fp=fopen(filename,"wb"))==NULL)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere printf("nCant open file!!");<br/>
<span style="white-spacere getch();<br/>
<span style="white-spacere exit(1);<br/>
<span style="white-spacere }<br/>
<br/>
<br/>
<span style="white-spacere for(i=0;i<ih;i++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere for(j=0;j<iw;j++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere fputc(buf[j], fp);<br/>
<span style="white-spacere }<br/>
<span style="white-spacere } <br/>
<span style="white-spacere fclose(fp);<br/>
}<br/>
<br/>
<br/>
void main()<br/>
{<br/>
<br/>
<br/>
<span style="white-spacere char filename[100];<br/>
unsigned char **buf1,**buf2;<br/>
<span style="white-spacere int i;<br/>
<br/>
<br/>
<span style="white-spacere buf1=(unsigned char **) malloc(ih*sizeof(unsigned char *));<br/>
<span style="white-spacere buf2=(unsigned char **) malloc(ih*sizeof(unsigned char *));<br/>
<span style="white-spacere for(i=0;i<ih;i++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere buf1=(unsigned char *) malloc(iw*sizeof(unsigned char));<br/>
<span style="white-spacere buf2=(unsigned char *) malloc(iw*sizeof(unsigned char));<br/>
<span style="white-spacere }<br/>
<span style="white-spacere <br/>
<span style="white-spacere cout<<"Open File:"<<endl;<br/>
<span style="white-spacere scanf("%s",filename);<br/>
<span style="white-spacere input(filename, buf1, 256, 256);<br/>
<br/>
<br/>
median(buf1,buf2);<br/>
<br/>
<br/>
<span style="white-spacere cout<<"..........................."<<endl;<br/>
<span style="white-spacere cout<<"Save file as:"<<endl;<br/>
<span style="white-spacere scanf("%s",filename);<br/>
<span style="white-spacere output(filename, buf2, 256 ,256);<br/>
<span style="white-spacere <br/>
<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
<br/>
void median(unsigned char **buf,unsigned char **out)<br/>
{<br/>
<br/>
<br/>
// ofstream of;<br/>
// of.open("c:\median filter.txt",ios:ut);<br/>
<br/>
<br/>
<span style="white-spacere int i,j,k,a,b,n;<br/>
<span style="white-spacere int temp[9],buffer=0;<br/>
<br/>
<br/>
<span style="white-spacere for(k=0;k<=9;k++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere temp[k]=0;<br/>
<span style="white-spacere }<br/>
<br/>
<br/>
<span style="white-spacere for(i=0;i<ih;i++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere for(j=0;j<iw;j++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere out[j]=0;<br/>
<span style="white-spacere }<br/>
<span style="white-spacere }<br/>
<br/>
<br/>
<span style="white-spacere for(i=1;i<ih-1;i++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere for(j=1;j<iw-1;j++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere n=0;<br/>
<span style="white-spacere for(a=-1;a<=1;a++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere for(b=-1;b<=1;b++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere temp[n]=buf[i+a][j+b];<br/>
<span style="white-spacere n++;<br/>
<span style="white-spacere }<br/>
<span style="white-spacere }<br/>
<br/>
<br/>
<span style="white-spacere //±Æ§Ç<br/>
<span style="white-spacere for(n=0;n<5;n++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere for(k=n;k<9;k++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere if(temp[n]>temp[k])<br/>
<span style="white-spacere {<br/>
<span style="white-spacere buffer=temp[n];<br/>
<span style="white-spacere temp[n]=temp[k];<br/>
<span style="white-spacere temp[k]=buffer;<br/>
<span style="white-spacere }<br/>
<span style="white-spacere }<br/>
<span style="white-spacere }<br/>
//<span style="white-spacere of<<"out["<<i<<"]["<<j<<"]="<<temp[4]<<endl; <br/>
<br/>
<br/>
<span style="white-spacere out[j]=temp[4];<br/>
<br/>
<br/>
<span style="white-spacere }<br/>
<span style="white-spacere <br/>
<span style="white-spacere }<br/>
<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
View the full article
Ive problem when I try to run the below code using Visual Studio 2010, Is there anyone can help to solve this problem ?? thanks in advace
<br/>
#include<stdio.h><br/>
#include<stdlib.h><br/>
#include<string.h><br/>
#include<conio.h><br/>
#include<math.h><br/>
#include<iostream><br/>
#include<algorithm><br/>
#include <fstream><br/>
<br/>
<br/>
using namespace std;<br/>
const int size=256,ih=256,iw=256;<br/>
void median(unsigned char **buf,unsigned char **out);<br/>
<br/>
<br/>
void input(char filename[100],unsigned char **buf,int ih,int iw)<br/>
{<br/>
<span style="white-spacere FILE *fp;<br/>
<span style="white-spacere int i,j;<br/>
<br/>
<br/>
if((fp=fopen(filename,"rb"))==NULL)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere printf("File %s open error ! n",filename);<br/>
<span style="white-spacere getch();<br/>
<span style="white-spacere exit(1);<br/>
<span style="white-spacere }<br/>
<br/>
<br/>
<span style="white-spacere for(i=0;i<ih;i++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere for(j=0;j<iw;j++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere buf[j] = (unsigned char)fgetc(fp);<br/>
<span style="white-spacere }<br/>
<span style="white-spacere }<br/>
fclose(fp);<span style="white-spacere <br/>
<br/>
<br/>
}<br/>
<br/>
<br/>
void output(char filename[100],unsigned char **buf,int ih,int iw)<br/>
{<br/>
<span style="white-spacere FILE *fp;<br/>
<span style="white-spacere int i,j;<br/>
<br/>
<br/>
<span style="white-spacere if((fp=fopen(filename,"wb"))==NULL)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere printf("nCant open file!!");<br/>
<span style="white-spacere getch();<br/>
<span style="white-spacere exit(1);<br/>
<span style="white-spacere }<br/>
<br/>
<br/>
<span style="white-spacere for(i=0;i<ih;i++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere for(j=0;j<iw;j++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere fputc(buf[j], fp);<br/>
<span style="white-spacere }<br/>
<span style="white-spacere } <br/>
<span style="white-spacere fclose(fp);<br/>
}<br/>
<br/>
<br/>
void main()<br/>
{<br/>
<br/>
<br/>
<span style="white-spacere char filename[100];<br/>
unsigned char **buf1,**buf2;<br/>
<span style="white-spacere int i;<br/>
<br/>
<br/>
<span style="white-spacere buf1=(unsigned char **) malloc(ih*sizeof(unsigned char *));<br/>
<span style="white-spacere buf2=(unsigned char **) malloc(ih*sizeof(unsigned char *));<br/>
<span style="white-spacere for(i=0;i<ih;i++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere buf1=(unsigned char *) malloc(iw*sizeof(unsigned char));<br/>
<span style="white-spacere buf2=(unsigned char *) malloc(iw*sizeof(unsigned char));<br/>
<span style="white-spacere }<br/>
<span style="white-spacere <br/>
<span style="white-spacere cout<<"Open File:"<<endl;<br/>
<span style="white-spacere scanf("%s",filename);<br/>
<span style="white-spacere input(filename, buf1, 256, 256);<br/>
<br/>
<br/>
median(buf1,buf2);<br/>
<br/>
<br/>
<span style="white-spacere cout<<"..........................."<<endl;<br/>
<span style="white-spacere cout<<"Save file as:"<<endl;<br/>
<span style="white-spacere scanf("%s",filename);<br/>
<span style="white-spacere output(filename, buf2, 256 ,256);<br/>
<span style="white-spacere <br/>
<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
<br/>
void median(unsigned char **buf,unsigned char **out)<br/>
{<br/>
<br/>
<br/>
// ofstream of;<br/>
// of.open("c:\median filter.txt",ios:ut);<br/>
<br/>
<br/>
<span style="white-spacere int i,j,k,a,b,n;<br/>
<span style="white-spacere int temp[9],buffer=0;<br/>
<br/>
<br/>
<span style="white-spacere for(k=0;k<=9;k++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere temp[k]=0;<br/>
<span style="white-spacere }<br/>
<br/>
<br/>
<span style="white-spacere for(i=0;i<ih;i++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere for(j=0;j<iw;j++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere out[j]=0;<br/>
<span style="white-spacere }<br/>
<span style="white-spacere }<br/>
<br/>
<br/>
<span style="white-spacere for(i=1;i<ih-1;i++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere for(j=1;j<iw-1;j++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere n=0;<br/>
<span style="white-spacere for(a=-1;a<=1;a++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere for(b=-1;b<=1;b++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere temp[n]=buf[i+a][j+b];<br/>
<span style="white-spacere n++;<br/>
<span style="white-spacere }<br/>
<span style="white-spacere }<br/>
<br/>
<br/>
<span style="white-spacere //±Æ§Ç<br/>
<span style="white-spacere for(n=0;n<5;n++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere for(k=n;k<9;k++)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere if(temp[n]>temp[k])<br/>
<span style="white-spacere {<br/>
<span style="white-spacere buffer=temp[n];<br/>
<span style="white-spacere temp[n]=temp[k];<br/>
<span style="white-spacere temp[k]=buffer;<br/>
<span style="white-spacere }<br/>
<span style="white-spacere }<br/>
<span style="white-spacere }<br/>
//<span style="white-spacere of<<"out["<<i<<"]["<<j<<"]="<<temp[4]<<endl; <br/>
<br/>
<br/>
<span style="white-spacere out[j]=temp[4];<br/>
<br/>
<br/>
<span style="white-spacere }<br/>
<span style="white-spacere <br/>
<span style="white-spacere }<br/>
<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
View the full article