pg1

/* ----------------------------------------
Image Processing pg1.c
Image Ratio Processing / NDVI Gray Image Output
(c)Ichinoseki National College Advanced Course
------------------------------------------ */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>  

main(argc,argv)
int argc;
char *argv[];
{
static int  i,j,m;
static double a1,a2,a3;
static int pixel,line;
FILE *fp1,*fp2,*fp3;

/* Command parameter check  */
if (argc!=6){
printf("Usage : command input_file1 input_file2 pixel line output_file\n");
return 1;
}
/* Image size parameter load */
sscanf(argv[3],"%d",&pixel);
sscanf(argv[4],"%d",&line);

/* Input image file1 check */
if (( fp1=fopen(argv[1],"r") )==NULL){
printf("Can't open input_file\n");
return 1;
}
/* Input image file1 check */
if (( fp2=fopen(argv[2],"r") )==NULL){
printf("Can't open input_file\n");
return 1;
}

/* Output image file check */
if (( fp3=fopen(argv[5],"w") )==NULL){
printf("Can't open output_file\n");
return 1;
}

/* Skip header data of Input Image */
fseek(fp1,24,0);
fseek(fp2,24,0);

/* ppm header output */
fprintf(fp3,"P5\n");
fprintf(fp3,"# INCT\n");
fprintf(fp3,"%s %s\n",argv[3],argv[4]);
fprintf(fp3,"255\n");

/* NDVI processing */
for (j=0; j<line; j++)
{
for (i=0; i<pixel; i++)
{
a1=(double)getc(fp1);
a2=(double)getc(fp2);
a3=(a1-a2)/(a1+a2);
m=(1+a3)*128;
putc(m,fp3);
}
}

fclose(fp1);
fclose(fp2);
fclose(fp3);
return 0;
}
最終更新:2009年05月28日 11:59
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。