8#include "tpcclibConfig.h"
26static char *info[] = {
27 "Calculates AUC (integral over time) image from PET image in",
28 "in ECAT 6.3, 7.x, NIfTI-1, or Analyze 7.5 format.",
29 "Analyze and NIfTI image must have SIF in the same folder.",
30 "In case of a static image, the matrix values are simply multiplied by the",
32 "The pixel values of resulting integral image will be in units of",
33 "radioactivity concentration times sec.",
35 "Usage: @P [Options] image starttime duration aucimage",
37 "AUC start time and duration (not stop time) must be entered in seconds;",
38 "program will automatically set the integration start time or duration",
39 "based on the time range in the image, if either is set to zero.",
43 " Average during specified range is calculated instead of AUC.",
45 " AUC times are given in minutes instead of seconds.",
48 "Example 1: calculate integral image between 32 and 302 seconds after",
49 "scan start with command",
50 " @P s5998dy1.v 32 270 s5998int.v",
52 "Example 2: integrate a static or dynamic image from the start time of",
53 "the first frame to the end of the last frame:",
54 " @P a773dy1.v 0 0 a773int.v",
56 "Example 3: integrate a dynamic image from 600 seconds to the end of",
58 " @P a773dy1.v 600 0 a773int.v",
60 "See also: imgunit, ecattime, ecatsum, imgsuv, imgledif, imgfur, imglkup",
62 "Keywords: image, AUC, modelling, autoradiography, perfusion, SUV",
81int main(
int argc,
char **argv)
83 int ai, help=0, version=0, verbose=1;
87 char petfile[FILENAME_MAX], intfile[FILENAME_MAX];
90 float tstart, tstop, tdur;
97 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
98 petfile[0]=intfile[0]=(char)0;
99 tstart=tdur=tstop=-1.0;
102 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
104 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(cptr==NULL)
continue;
105 if(strcasecmp(cptr,
"AVG")==0 || strcasecmp(cptr,
"MEAN")==0) {
106 calc_avg=1;
continue;
107 }
else if(strncasecmp(cptr,
"MINUTES", 3)==0) {
108 times_in_min=1;
continue;
109 }
else if(strncasecmp(cptr,
"SECONDS", 3)==0) {
110 times_in_min=0;
continue;
112 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
117 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
122 if(ai<argc) {
strlcpy(petfile, argv[ai], FILENAME_MAX); ai++;}
123 if(ai<argc) {tstart=
atof_dpi(argv[ai]); ai++;}
124 if(ai<argc) {tdur=
atof_dpi(argv[ai]); tstop=tstart+tdur; ai++;}
125 if(ai<argc) {
strlcpy(intfile, argv[ai], FILENAME_MAX); ai++;}
126 if(ai<argc) {fprintf(stderr,
"Error: invalid argument '%s'.\n", argv[ai]);
return(1);}
130 fprintf(stderr,
"Error: missing command-line argument; use option --help\n");
133 if(strcasecmp(intfile, petfile)==0) {
134 fprintf(stderr,
"Error: check the output file name.\n");
137 if(tstop<tstart || tstart<0.0) {
138 fprintf(stderr,
"Error: invalid time range arguments.\n");
142 if(times_in_min==1) {tstart*=60.0; tstop*=60.0; tdur*=60.0;}
147 printf(
"petfile := %s\n", petfile);
148 printf(
"intfile := %s\n", intfile);
149 printf(
"calc_avg := %d\n", calc_avg);
150 printf(
"times_in_min := %d\n", times_in_min);
158 if(verbose>0) fprintf(stdout,
"reading image %s\n", petfile);
161 fprintf(stderr,
"Error: %s\n", pet.
statmsg);
if(verbose>1)
imgInfo(&pet);
166 fprintf(stderr,
"Error: %s is not an image.\n", petfile);
171 fprintf(stderr,
"Warning: %s is assumed to be a static image.\n", petfile);
173 if(verbose>1) printf(
"isStat := %d\n", isStat);
177 fprintf(stderr,
"Error: image does not contain frame times.\n");
183 if(verbose>1) fprintf(stdout,
"checking frame overlap in %s\n", petfile);
186 fprintf(stderr,
"Error: image %s has overlapping frame times.\n", petfile);
192 if(tstart<1.0E-03 && tdur<1.0E-02) {
193 tstart=pet.
start[0]; tstop=pet.
end[pet.
dimt-1]; tdur=tstop-tstart;
194 }
else if(tdur<1.0E-02) {
196 tstop=pet.
end[pet.
dimt-1]; tdur=tstop-tstart;
199 printf(
"tstart := %g\n", tstart);
200 printf(
"tstop := %g\n", tstop);
201 printf(
"tdur := %g\n", tdur);
208 if(verbose>1) fprintf(stdout,
"calculating integral image\n");
209 ret=
imgTimeIntegral(&pet, tstart, tstop, &rout, calc_avg, tmp, verbose-2);
211 fprintf(stderr,
"Error: %s.\n", tmp);
214 if(verbose>0) fprintf(stdout,
"%s.\n", tmp);
221 if(verbose>1) fprintf(stdout,
"writing integral image\n");
224 fprintf(stderr,
"Error: %s\n", rout.
statmsg);
228 if(calc_avg) fprintf(stdout,
"mean image written in %s\n", intfile);
229 else fprintf(stdout,
"integral image written in %s\n", intfile);
double atof_dpi(char *str)
int imgExistentTimes(IMG *img)
void imgEmpty(IMG *image)
int imgRead(const char *fname, IMG *img)
int imgWrite(const char *fname, IMG *img)
int imgDeleteFrameOverlap(IMG *img)
Header file for libtpccurveio.
Header file for libtpcimgio.
Header file for libtpcimgp.
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)
Header file for libtpcmodel.
Header file for libtpcmodext.
int imgTimeIntegral(IMG *img, float t1, float t2, IMG *iimg, int calc_mode, char *status, int verbose)