10#include "tpcclibConfig.h"
24static char *info[] = {
25 "Report and change the correction for physical decay in PET image data.",
27 "Usage: @P [Options] imagefile",
31 " Correct PET data for physical decay.",
33 " Remove decay correction.",
34 " Make sure that PET is decay corrected before this operation.",
36 " Changes or specifies the isotope.",
37 " Any previous decay correction must be removed before this operation.",
38 " Note that image may need to be recalibrated if isotope is changed;",
39 " at least branching fraction needs to be corrected.",
46 " Add decay correction factors to the image data.",
47 " This option does not add decay correction to the pixel values.",
48 " This may not be effective in some image formats.",
50 " Remove decay correction factors from the image data.",
51 " This option does not remove decay correction from the pixel values.",
52 " This may not be effective in some image formats.",
55 "If no option is specified, program reports the current state of decay",
56 "correction, but makes no changes to the data file.",
58 "See also: eframe, ecattime, egetstrt, esetstrt, imgunit, lmhdr, lshdr",
60 "Keywords: ECAT, image, physical decay, modelling, simulation",
79int main(
int argc,
char **argv)
81 int ai, help=0, version=0, verbose=1;
83 char petfile[FILENAME_MAX], *cptr;
97 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
101 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
102 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(cptr==NULL)
continue;
105 if(strncasecmp(cptr,
"I=", 2)==0) {
110 if(halflife>0.0)
continue;
112 fprintf(stderr,
"Error: invalid isotope with option -i\n");
return(1);
113 }
else if(strncasecmp(cptr,
"D", 1)==0) {
116 fprintf(stderr,
"Error: invalid combination of options.\n");
return(1);}
118 if(strncasecmp(cptr,
"D", 1)==0) {decaycor=2;
continue;}
119 if(strncasecmp(cptr,
"C", 1)==0) {decaycor=1;
continue;}
120 }
else if(strncasecmp(cptr,
"R", 1)==0) {
123 fprintf(stderr,
"Error: invalid combination of options.\n");
return(1);}
125 if(strncasecmp(cptr,
"D", 1)==0) {decaycor=-2;
continue;}
126 if(strncasecmp(cptr,
"C", 1)==0) {decaycor=-1;
continue;}
128 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
133 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
138 for(; ai<argc; ai++) {
140 if(!petfile[0]) {strcpy(petfile, argv[ai]);
continue;}
142 fprintf(stderr,
"Error: invalid argument '%s'.\n", argv[ai]);
148 fprintf(stderr,
"Error: missing command-line argument; try %s --help\n",
155 printf(
"petfile := %s\n", petfile);
156 printf(
"info_on_image: = %d\n", info_on_image);
157 printf(
"decaycor := %d\n", decaycor);
158 printf(
"halflife := %g\n", halflife);
165 if(verbose>=0) {fprintf(stdout,
"reading %s\n", petfile); fflush(stdout);}
168 fprintf(stderr,
"Error in reading %s: %s\n", petfile, img.
statmsg);
179 for(fi=0; fi<img.
dimt; fi++)
189 if(verbose>=0 || info_on_image==1)
190 fprintf(stdout,
"isotope: %s\n",
imgIsotope(&img) );
192 if(info_on_image==1 || verbose>0) {
194 fprintf(stdout,
"Decay correction: unknown\n");
196 fprintf(stdout,
"Decay correction: corrected\n");
198 fprintf(stdout,
"Decay correction: not corrected\n");
201 fprintf(stdout,
"decay correction factors:\n");
202 fprintf(stdout,
"Frame start length Decay factor\n");
203 for(fi=0; fi<img.
dimt; fi++) {
204 if(verbose>1) fprintf(stdout,
"frame%d: %g %g %g\n", fi+1, img.
start[fi],
206 else fprintf(stdout,
"%4d %6.0f %6.0f %g\n", fi+1, img.
start[fi],
213 fprintf(stdout,
"Note: status of the decay correction is not known.\n");
215 fprintf(stdout,
"Note: decay correction factors not available\n");
238 if(verbose>1) printf(
"end of info.\n");
248 if(verbose>1) printf(
"Request to set the halflife to %g\n", halflife);
250 if(verbose>1) printf(
"same isotope was previously set.\n");
253 if(verbose>=0) printf(
"Note: same isotope was previously set.\n");
258 if(verbose>=0) printf(
"new sinogram isotope: %s\n",
imgIsotope(&img) );
261 if(verbose>=0) printf(
"new image isotope: %s\n",
imgIsotope(&img) );
265 "Error: remove previous decay correction before changing isotope.\n");
270 fprintf(stderr,
"Warning: possible decay correction should have been");
271 fprintf(stderr,
" removed before isotope was changed to %s\n",
280 ret=0;
for(fi=0; fi<img.
dimt; fi++)
if(img.
end[fi]<=0.0) ret=1;
281 if(ret) fprintf(stderr,
"Warning: check the frame times.\n");
288 fprintf(stderr,
"Error: set isotope with option -i\n");
301 fprintf(stdout,
"decay correction of PET data...\n"); fflush(stdout);}
304 fprintf(stderr,
"Error: %s is already corrected for decay.\n", petfile);
310 fprintf(stderr,
"Warning: assuming %s was not corrected for decay.\n", petfile);
315 if(ret) fprintf(stderr,
"Error %d in decay correction.\n", ret);
316 }
else if(decaycor==-2) {
318 fprintf(stdout,
"removing decay correction...\n"); fflush(stdout);
320 fprintf(stderr,
"Warning: removing decay correction.\n");
324 if(ret) fprintf(stderr,
"Error %d in removal of decay correction.\n", ret);
325 }
else if(decaycor==1) {
326 if(verbose>=0) printf(
"computing decay correction factors...\n");
329 fprintf(stderr,
"Error: %s is already corrected for decay.\n", petfile);
336 "Warning: decay correction factors are not saved in sinogram.\n");
339 fprintf(stderr,
"Error %d in setting decay correction factors.\n", ret);
340 }
else if(decaycor==-1) {
342 if(verbose>=0) printf(
"deleting decay correction factors...\n");
345 fprintf(stderr,
"Error %d in removing decay correction factors.\n", ret);
347 fprintf(stderr,
"Error: no need to delete decay correction factors.\n");
360 fprintf(stdout,
"writing %s ...", petfile); fflush(stdout);}
363 fprintf(stderr,
"\nError: %s\n", img.
statmsg);
367 if(verbose>=0) fprintf(stdout,
"done.\n");
373 printf(
"PET data does not contain decay correction factors.\n");
375 printf(
"Frame start length Decay factor\n");
376 for(fi=0; fi<img.
dimt; fi++)
377 printf(
"%4d %6.0f %6.0f %g\n", fi+1, img.
start[fi],
char * hlCorrectIsotopeCode(char *isocode)
double hlFromIsotope(char *isocode)
void imgEmpty(IMG *image)
char * imgIsotope(IMG *img)
int imgSetDecayCorrFactors(IMG *image, int mode)
int imgDecayCorrection(IMG *image, int mode)
int imgRead(const char *fname, IMG *img)
int imgWrite(const char *fname, IMG *img)
Header file for libtpcimgio.
#define IMG_DC_NONCORRECTED
Header file for libtpcmisc.
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
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)