8#include "tpcclibConfig.h"
23static char *info[] = {
24 "Calculate the volume percentage of voxels with positive (>0) value in",
25 "a static PET image file in ECAT 6.3 or 7.x, NIfTI-1, or Analyze 7.5 format.",
27 "Usage: @P [Options] imgfile [resfile]",
32 "See also: imghist, imgthrs, imgmask, imgmax, imginteg, imgslim",
34 "Keywords: image, threshold, mask",
53int main(
int argc,
char **argv)
55 int ai, help=0, version=0, verbose=1;
56 char imgfile[FILENAME_MAX], outfile[FILENAME_MAX];
64 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
65 imgfile[0]=outfile[0]=(char)0;
67 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
68 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(cptr==NULL)
continue;
70 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
75 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
80 if(ai<argc) {
strlcpy(imgfile, argv[ai], FILENAME_MAX); ai++;}
81 if(ai<argc) {
strlcpy(outfile, argv[ai], FILENAME_MAX); ai++;}
82 if(ai<argc) {fprintf(stderr,
"Error: too many arguments.\n");
return(1);}
86 fprintf(stderr,
"Error: missing command-line argument; use option --help\n");
92 printf(
"imgfile := %s\n", imgfile);
93 if(outfile[0]) printf(
"outfile := %s\n", outfile);
100 if(verbose>0) printf(
"reading static image %s\n", imgfile);
104 fprintf(stderr,
"Error: %s\n", img.
statmsg);
105 if(verbose>1) printf(
"ret := %d\n", ret);
109 fprintf(stderr,
"Error: not a static image.\n");
113 printf(
"dimx := %d\n", img.
dimx);
114 printf(
"dimy := %d\n", img.
dimy);
115 printf(
"dimz := %d\n", img.
dimz);
118 if(verbose>0) fprintf(stderr,
"Warning: missing pixel values.\n");
124 if(verbose>0) printf(
"counting positive voxels...\n");
125 long long total_n=0, posit_n=0;
127 for(zi=0; zi<img.
dimz; zi++)
128 for(yi=0; yi<img.
dimy; yi++)
129 for(xi=0; xi<img.
dimx; xi++) {
131 if(img.
m[zi][yi][xi][0]>0.0) posit_n++;
133 double volper=100.0*(double)posit_n/(
double)total_n;
137 if(!outfile[0] || verbose>0) {
138 printf(
"positive_volume_percentage := %g\n", volper);
140 if(!outfile[0])
return(0);
142 char tmp[64]; sprintf(tmp,
"%g", volper);
144 ret=
iftPut(&ift,
"positive_volume_percentage", tmp, NULL, 0);
145 if(ret==0) ret=
iftWrite(&ift, outfile, 0);
148 fprintf(stderr,
"Error: cannot save the result.\n");
151 if(verbose>0) printf(
"done.\n");
int iftPut(IFT *ift, char *key, char *value, char *cmt_type, int verbose)
int iftWrite(IFT *ift, char *filename, int verbose)
unsigned long long imgNaNs(IMG *img, int fix)
void imgEmpty(IMG *image)
int imgRead(const char *fname, IMG *img)
Header file for libtpcimgio.
Header file for libtpcmisc.
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
size_t strlcpy(char *dst, const char *src, size_t dstsize)
int tpcHtmlUsage(const char *program, char *text[], const char *path)
void tpcPrintBuild(const char *program, FILE *fp)
void tpcPrintUsage(const char *program, char *text[], FILE *fp)