画像情報処理_pa1

/* ========================================
Image Processing pa1.c
PGM Format Gray Image Data Generation
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 int pixel,line;
FILE *fp1;

/* Command parameter check  */
if (argc!=4){
printf("Usage : command pixel line output_file\n");
return 1;
}

/* Image size parameter load */
sscanf(argv[1],"%d",&pixel);
sscanf(argv[2],"%d",&line);

if ( pixel*line>1000*1000){
printf("Over image size\n");
return 1;
}

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

/* pnm(pgm) header code output */
fprintf(fp1,"P5\n");   /* Gray binary image data */
fprintf(fp1,"# INCT\n"); /* Comment */
fprintf(fp1,"%s %s\n",argv[1],argv[2]); /* Pixel Line Image size */
fprintf(fp1,"255\n"); /* Imade data maximum value */

/* Gray binary image data output */
for (i=0; i<line; i++)
{
for (j=0; j<pixel; j++)
{
m=128;
putc(m,fp1);
}
}
fclose(fp1);
return 0;
}
最終更新:2009年05月08日 11:17
ツールボックス

下から選んでください:

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