home *** CD-ROM | disk | FTP | other *** search
- #include <stdlib.h>
- #include <stdio.h>
- #include <io.h>
-
-
- #define INSIZE 512
- #define OUTSIZE 256
- #define BPV 2 /* Bytes per voxel */
-
-
- void main(int argc, char **argv)
- {
- int i,j,k,l,m;
- int Rfactor = INSIZE / OUTSIZE;
- FILE *in, *out;
- short inframe[INSIZE][INSIZE];
- short outframe[OUTSIZE][OUTSIZE];
- int filesize, numslices;
- int temp;
-
-
- /* Ensure proper syntax */
-
- if(argc != 3)
- {
- printf("\nUsage:: shrinkCT infile outfile\n\n");
- exit(1);
- }
-
-
- /* Open the files */
-
- in = fopen(argv[1], "rb");
- if(in == NULL)
- {
- printf("\nCould not open file %s.\n\n", argv[1]);
- exit(2);
- }
-
- out = fopen(argv[2], "wb");
- if(out == NULL)
- {
- printf("\nCould not create file %s.\n\n", argv[2]);
- exit(3);
- }
-
-
- /* Determine number of slices in the volume */
-
- filesize = filelength( fileno(in) );
- numslices = filesize / INSIZE / INSIZE / BPV;
- if(numslices * INSIZE * INSIZE * BPV != filesize)
- {
- printf("\nThe size of the input file is incorrect.\n\n");
- exit(4);
- }
-
-
- /* Processing Loop */
-
- for(i=0; i<numslices; i++)
- {
- fread(inframe, INSIZE * INSIZE, BPV, in);
- printf("Processing slice %d/%d.\n", i+1, numslices);
-
- /* Correct for negative Hounsfield values */
- /* and mask out upper nibble */
-
- for(j=0; j<INSIZE; j++)
- for(k=0; k<INSIZE; k++)
- {
- inframe[j][k] += 1024;
- inframe[j][k] &= 0x0FFF;
- }
-
- /* Size reduction by averaging */
-
- for(j=0; j<OUTSIZE; j++)
- for(k=0; k<OUTSIZE; k++)
- {
- temp = 0;
- for(l=0; l<Rfactor; l++)
- for(m=0; m<Rfactor; m++)
- temp += inframe[j*Rfactor+l][k*Rfactor+m];
- outframe[j][k] = temp / Rfactor / Rfactor;
- }
-
- fwrite(outframe, OUTSIZE * OUTSIZE, BPV, out);
- }
-
- fclose(in);
- fclose(out);
-
- }
-