Advertisement
Kojima0502

☆COLORIZATION by RGB in OPENGL☆

Jan 24th, 2014
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define  CHANNEL  3// 画像の色数(R, G, B)
  6.  
  7. int main(int argc,char *argv[])
  8. {
  9.     FILE *fpi,*fpo;
  10.     int i,j,height,width;
  11.     float dn1;
  12.     float *file1;
  13.     unsigned char *file2;
  14.     float data1,data2,data3;
  15.     if(argc!=5)
  16.     {
  17.         fprintf(stderr,"Usage: %s\n(2)Input_READ_filename\n(3)width\n(4)height\n",argv[0]);
  18.         exit(1);
  19.     }
  20.    
  21.     printf("OPEN FILE NAME:%s\n",argv[1]);
  22.    
  23.     width = atoi(argv[3]); printf("W = %d,", width);
  24.     height = atoi(argv[4]); printf("H = %d\n", height);
  25.        
  26.     file1= (float *)malloc(width*height*sizeof(float));
  27.     file2= (unsigned char *)malloc(CHANNEL*width*height*sizeof(char));
  28.    
  29.     if((fpi=fopen(argv[1],"r"))==NULL)
  30.     {
  31.         fprintf(stderr,"input file open error\n");
  32.         exit(1);
  33.     }
  34.     fread((float *)file1,sizeof(float),width*height,fpi);
  35.    
  36.     if((fpo=fopen(argv[2],"wb"))==NULL)
  37.     {
  38.         printf("The file can't be opened. The program is exit.\n");
  39.        
  40.         exit(1);
  41.     }
  42.    
  43.    
  44.     for(i=0;i<height;i++)
  45.     {
  46.         for(j=0;j<width;j++)
  47.         {
  48.             dn1=file1[i*width+j];
  49.        if(dn1>=0 && dn1<1.0)
  50.            {
  51.         file2[i*width+j]=204;
  52.         file2[i*width+j+width*height]=0;
  53.         file2[i*width+j+width*height*2]=0;
  54.            }
  55.        else if(dn1>=1.0 && dn1<2.0)
  56.        {
  57.            file2[i*width+j]=183;
  58.            file2[i*width+j+width*height]=65;
  59.            file2[i*width+j+width*height*2]=14;
  60.        }
  61.        else if(dn1>=2.0 && dn1<3.0)
  62.        {
  63.            file2[i*width+j]=235;
  64.            file2[i*width+j+width*height]=121;
  65.            file2[i*width+j+width*height*2]=136;
  66.        }
  67.        else if(dn1>=3.0 && dn1<4.0)
  68.        {
  69.            file2[i*width+j]=239;
  70.            file2[i*width+j+width*height]=161;
  71.            file2[i*width+j+width*height*2]=143;
  72.        }
  73.        else if(dn1>=4.0 && dn1<5.0)
  74.        {
  75.            file2[i*width+j]=229;
  76.            file2[i*width+j+width*height]=152;
  77.            file2[i*width+j+width*height*2]=197;
  78.        }
  79.        else if(dn1>5.0)
  80.        {
  81.            file2[i*width+j]=229;
  82.            file2[i*width+j+width*height]=152;
  83.            file2[i*width+j+width*height*2]=197;
  84.        }
  85.  
  86.             /*
  87.        else if(dn1>=5.0 && dn1<6.0)
  88.        {
  89.            file2[i*width+j]=1;
  90.            file2[i*width+j+width*height]=1;
  91.            file2[i*width+j+width*height*2]=1;
  92.        }
  93.        else if(dn1>=6.0 && dn1<7.0)
  94.        {
  95.            file2[i*width+j]=1;
  96.            file2[i*width+j+width*height]=1;
  97.            file2[i*width+j+width*height*2]=1;
  98.        }
  99.        else if(dn1>=7.0 && dn1<8.0)
  100.        {
  101.            file2[i*width+j]=1;
  102.            file2[i*width+j+width*height]=1;
  103.            file2[i*width+j+width*height*2]=1;
  104.        }
  105.        else if(dn1>=8.0 && dn1<9.0)
  106.        {
  107.            file2[i*width+j]=1;
  108.            file2[i*width+j+width*height]=1;
  109.            file2[i*width+j+width*height*2]=1;
  110.        }
  111.        else if(dn1>=9.0 && dn1<10.0)
  112.        {
  113.            file2[i*width+j]=1;
  114.            file2[i*width+j+width*height]=1;
  115.            file2[i*width+j+width*height*2]=1;
  116.        }
  117.        else if(dn1>=10.0 && dn1<11.0)
  118.        {
  119.            file2[i*width+j]=1;
  120.            file2[i*width+j+width*height]=1;
  121.            file2[i*width+j+width*height*2]=1;
  122.        }else if(dn1>=12.0 && dn1<13.0)
  123.        {
  124.            file2[i*width+j]=1;
  125.            file2[i*width+j+width*height]=1;
  126.            file2[i*width+j+width*height*2]=1;
  127.        }
  128.        else if(dn1>=13.0 && dn1<14.0)
  129.        {
  130.            file2[i*width+j]=1;
  131.            file2[i*width+j+width*height]=1;
  132.            file2[i*width+j+width*height*2]=1;
  133.        }
  134.        else if(dn1>=14.0 && dn1<15.0)
  135.        {
  136.            file2[i*width+j]=1;
  137.            file2[i*width+j+width*height]=1;
  138.            file2[i*width+j+width*height*2]=1;
  139.        }
  140.        else if(dn1>=15.0 && dn1<16.0)
  141.        {
  142.            file2[i*width+j]=1;
  143.            file2[i*width+j+width*height]=1;
  144.            file2[i*width+j+width*height*2]=1;
  145.        }
  146.        else if(dn1>=16.0 && dn1<17.0)
  147.        {
  148.            file2[i*width+j]=1;
  149.            file2[i*width+j+width*height]=1;
  150.            file2[i*width+j+width*height*2]=1;
  151.        }
  152.        else if(dn1>=17.0 && dn1<18.0)
  153.        {
  154.            file2[i*width+j]=1;
  155.            file2[i*width+j+width*height]=1;
  156.            file2[i*width+j+width*height*2]=1;
  157.        }
  158.        else if(dn1>=18.0 && dn1<19.0)
  159.        {
  160.            file2[i*width+j]=1;
  161.            file2[i*width+j+width*height]=1;
  162.            file2[i*width+j+width*height*2]=1;
  163.        }
  164.        else if(dn1>=19.0 && dn1<20.0)
  165.        {
  166.            file2[i*width+j]=1;
  167.            file2[i*width+j+width*height]=1;
  168.            file2[i*width+j+width*height*2]=1;
  169.        }
  170.              */
  171.             fwrite(&file2,sizeof(char),1,fpo);
  172.            
  173. }
  174.     }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement