/************************************************************************/ /* */ /* Program: makehist.c */ /* Purpose: to produce a greylevel historgram file for a 3-D */ /* volume data set */ /* Input file: 3-D image one character per voxel */ /* Output file: histrgram always stored in makehist.out */ /* Programmer: Dale P. Bentz */ /* National Institute of Standards and Technology */ /* 100 Bureau Drive Stop 8621 */ /* Gaithersburg, MD 20899-8621 */ /* Phone: (301) 975-5865 */ /* Fax: (301) 990-6891 */ /* E-mail: dale.bentz@nist.gov */ /* */ /* Date: 2001 */ /* */ /***********************************************************************/ #include #include #include /* XSIZE YSIZE and ZSIZE specify the size of the 3-D image in the */ /* x, y, and z directions, respectively (should be set by the user */ /* before compiling the program) */ #define XSIZE 300 #define YSIZE 300 #define ZSIZE 300 main(){ FILE *infile,*outfile; char filein[80],fileout[80]; int ix,iy,iz,valout; long int hcount[256]; unsigned char valin; /* Initialize the greylevel histogram matrix */ for(ix=0;ix<256;ix++){ hcount[ix]=0; } printf("Enter name of file for input \n"); scanf("%s",filein); printf("%s \n",filein); infile=fopen(filein,"rb"); /* Histogram is always output to makehist.out */ /* User should rename to file of their choosing after execution */ outfile=fopen("makehist.out","w"); /* Scan the 3-D image voxel by voxel and compile the greylevel historgram */ for(iz=0;iz255)){ printf("problem- valout is %d \n",valout); } hcount[valout]+=1; } } } /* Output the compiled greylevel historgram to file */ for(ix=0;ix<256;ix++){ fprintf(outfile,"%d %ld\n",ix,hcount[ix]); } fclose(infile); fclose(outfile); }