Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define CHANNEL 3// 画像の色数(R, G, B)
- int main(int argc,char *argv[])
- {
- FILE *fpi,*fpo;
- int i,j,height,width;
- float dn1;
- float *file1;
- unsigned char *file2;
- float data1,data2,data3;
- if(argc!=5)
- {
- fprintf(stderr,"Usage: %s\n(2)Input_READ_filename\n(3)width\n(4)height\n",argv[0]);
- exit(1);
- }
- printf("OPEN FILE NAME:%s\n",argv[1]);
- width = atoi(argv[3]); printf("W = %d,", width);
- height = atoi(argv[4]); printf("H = %d\n", height);
- file1= (float *)malloc(width*height*sizeof(float));
- file2= (unsigned char *)malloc(CHANNEL*width*height*sizeof(char));
- if((fpi=fopen(argv[1],"r"))==NULL)
- {
- fprintf(stderr,"input file open error\n");
- exit(1);
- }
- fread((float *)file1,sizeof(float),width*height,fpi);
- if((fpo=fopen(argv[2],"wb"))==NULL)
- {
- printf("The file can't be opened. The program is exit.\n");
- exit(1);
- }
- for(i=0;i<height;i++)
- {
- for(j=0;j<width;j++)
- {
- dn1=file1[i*width+j];
- if(dn1>=0 && dn1<1.0)
- {
- file2[i*width+j]=204;
- file2[i*width+j+width*height]=0;
- file2[i*width+j+width*height*2]=0;
- }
- else if(dn1>=1.0 && dn1<2.0)
- {
- file2[i*width+j]=183;
- file2[i*width+j+width*height]=65;
- file2[i*width+j+width*height*2]=14;
- }
- else if(dn1>=2.0 && dn1<3.0)
- {
- file2[i*width+j]=235;
- file2[i*width+j+width*height]=121;
- file2[i*width+j+width*height*2]=136;
- }
- else if(dn1>=3.0 && dn1<4.0)
- {
- file2[i*width+j]=239;
- file2[i*width+j+width*height]=161;
- file2[i*width+j+width*height*2]=143;
- }
- else if(dn1>=4.0 && dn1<5.0)
- {
- file2[i*width+j]=229;
- file2[i*width+j+width*height]=152;
- file2[i*width+j+width*height*2]=197;
- }
- else if(dn1>5.0)
- {
- file2[i*width+j]=229;
- file2[i*width+j+width*height]=152;
- file2[i*width+j+width*height*2]=197;
- }
- /*
- else if(dn1>=5.0 && dn1<6.0)
- {
- file2[i*width+j]=1;
- file2[i*width+j+width*height]=1;
- file2[i*width+j+width*height*2]=1;
- }
- else if(dn1>=6.0 && dn1<7.0)
- {
- file2[i*width+j]=1;
- file2[i*width+j+width*height]=1;
- file2[i*width+j+width*height*2]=1;
- }
- else if(dn1>=7.0 && dn1<8.0)
- {
- file2[i*width+j]=1;
- file2[i*width+j+width*height]=1;
- file2[i*width+j+width*height*2]=1;
- }
- else if(dn1>=8.0 && dn1<9.0)
- {
- file2[i*width+j]=1;
- file2[i*width+j+width*height]=1;
- file2[i*width+j+width*height*2]=1;
- }
- else if(dn1>=9.0 && dn1<10.0)
- {
- file2[i*width+j]=1;
- file2[i*width+j+width*height]=1;
- file2[i*width+j+width*height*2]=1;
- }
- else if(dn1>=10.0 && dn1<11.0)
- {
- file2[i*width+j]=1;
- file2[i*width+j+width*height]=1;
- file2[i*width+j+width*height*2]=1;
- }else if(dn1>=12.0 && dn1<13.0)
- {
- file2[i*width+j]=1;
- file2[i*width+j+width*height]=1;
- file2[i*width+j+width*height*2]=1;
- }
- else if(dn1>=13.0 && dn1<14.0)
- {
- file2[i*width+j]=1;
- file2[i*width+j+width*height]=1;
- file2[i*width+j+width*height*2]=1;
- }
- else if(dn1>=14.0 && dn1<15.0)
- {
- file2[i*width+j]=1;
- file2[i*width+j+width*height]=1;
- file2[i*width+j+width*height*2]=1;
- }
- else if(dn1>=15.0 && dn1<16.0)
- {
- file2[i*width+j]=1;
- file2[i*width+j+width*height]=1;
- file2[i*width+j+width*height*2]=1;
- }
- else if(dn1>=16.0 && dn1<17.0)
- {
- file2[i*width+j]=1;
- file2[i*width+j+width*height]=1;
- file2[i*width+j+width*height*2]=1;
- }
- else if(dn1>=17.0 && dn1<18.0)
- {
- file2[i*width+j]=1;
- file2[i*width+j+width*height]=1;
- file2[i*width+j+width*height*2]=1;
- }
- else if(dn1>=18.0 && dn1<19.0)
- {
- file2[i*width+j]=1;
- file2[i*width+j+width*height]=1;
- file2[i*width+j+width*height*2]=1;
- }
- else if(dn1>=19.0 && dn1<20.0)
- {
- file2[i*width+j]=1;
- file2[i*width+j+width*height]=1;
- file2[i*width+j+width*height*2]=1;
- }
- */
- fwrite(&file2,sizeof(char),1,fpo);
- }
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement