8#include "tpcclibConfig.h"
28static char *info[] = {
29 "Estimation of rate constants K1, k2, and Vb from dynamic PET image in",
30 "ECAT 6.3, ECAT 7.x, NIfTI-1, or Analyze 7.5 file format using",
31 "one-tissue compartment model, solved using the basis function approach.",
32 "The radioactivity concentration of each voxel is assumed to consist of",
33 "tissue (Ct) and blood (Cb):",
34 " Cpet(t) = Ct(t) + Vb*Cb",
35 "and differential equation for Ct is:",
36 " dCt(t)/dt = K1*Cp(t) - k2*Ct(t)",
37 ", where Cp(t) is arterial plasma concentration curve.",
38 "Arterial plasma and blood data must be corrected for decay and delay.",
39 "Dynamic PET image must be corrected for decay.",
40 "Fit time must be given in seconds.",
42 "Usage: @P [Options] ptacfile btacfile imgfile fittime K1file [k2file]",
46 " Parametric K1/k2 (Vt) image is saved.",
48 " Parametric Vb image is saved.",
49 " -k2min=<Min k2> and -k2max=<Max k2>",
50 " Enter the minimum and maximum k2 in units 1/min, applying to decay",
51 " corrected data. Defaults are k2min=0 and k2max=10, respectively.",
52 " -K1min=<Min K1> and -K1max=<Max K1>",
53 " Enter the minimum and maximum K1 value; defaults are",
54 " 0 and 10 mL/(mL*min), respectively.",
55 " -Vtmin=<Min Vt> and -Vtmax=<Max Vt>",
56 " Enter the minimum and maximum value for apparent Vt (K1/k2);",
57 " defaults are 0 and 10 mL/mL, respectively.",
58 " -Vbmin=<Min Vb> and -Vbmax=<Max Vb>",
59 " Enter the minimum and maximum value for Vb (volume fraction);",
60 " defaults are 0 and 1 mL/mL, respectively.",
62 " Set number of basis functions; default is 500, minimum 100.",
64 " Weighted sum-of-squares are written in specified image file.",
66 " Pixels with AUC less than (threshold/100 x input AUC) are set to zero;",
69 " Basis function curves are written in specified file.",
71 " Excluded voxels and voxels with any of the result parameters at either",
72 " of its limits is written in the specified image file with value 1,",
73 " otherwise with value 0.",
76 "Example 1. Calculation of K1 and k2 images using 0-20 min of",
78 " @P P223344apc.bld P223344ab.bld P223344.nii 20 P223344k1.nii P223344k2.nii",
80 "By default, the units of voxel values in the K1 image are",
81 "(mL plasma)/((mL tissue) * min), in k2 image 1/min, in Vb image",
82 "mL blood/mL tissue), and in Vt image (mL plasma)/(mL tissue),",
84 "See also: imgbfh2o, fitk2, imgunit, fitdelay, imgcbv",
86 "Keywords: image, modelling, compartmental model, basis function method",
129 printf(
"\n%s(*inp, *tis, *bf, %d, %g, %g, status, %d)\n", __func__, bfNr, k2min, k2max, verbose);
132 if(input==NULL || tissue==NULL || bf==NULL) {
133 if(status!=NULL) strcpy(status,
"program error");
137 if(status!=NULL) strcpy(status,
"no input data");
141 if(status!=NULL) strcpy(status,
"no pet data");
145 if(status!=NULL) strcpy(status,
"invalid time units");
149 if(status!=NULL) strcpy(status,
"invalid nr of basis functions");
152 if(k2min<1.0E-10) k2min=1.0E-10;
153 if(k2min>=k2max || k2min<0.0) {
154 if(status!=NULL) strcpy(status,
"invalid k2 range");
158 printf(
"input timerange: %g - %g\n", input->
x[0], input->
x[input->
frameNr-1]);
159 printf(
"tissue timerange: %g - %g\n", tissue->
x[0], tissue->
x[tissue->
frameNr-1]);
166 if(verbose>1) printf(
"allocating memory for basis functions\n");
169 if(status!=NULL) strcpy(status,
"out of memory");
177 for(bi=0; bi<bf->
voiNr; bi++) {
178 snprintf(bf->
voi[bi].
voiname, 6,
"B%5.5d", bi+1);
183 for(fi=0; fi<bf->
frameNr; fi++) {
184 bf->
x[fi]=tissue->
x[fi];
185 bf->
x1[fi]=tissue->
x1[fi];
186 bf->
x2[fi]=tissue->
x2[fi];
190 if(verbose>1) printf(
"computing k2 values\n");
191 a=log10(k2min); b=log10(k2max); c=(b-a)/(
double)(bfNr-1);
192 if(verbose>20) printf(
"a=%g b=%g, c=%g\n", a, b, c);
193 for(bi=0; bi<bf->
voiNr; bi++) {
194 bf->
voi[bi].
size=pow(10.0, (
double)bi*c+a);
201 double *sim=(
double*)malloc(input->
frameNr*
sizeof(
double));
203 if(status!=NULL) strcpy(status,
"out of memory");
208 if(verbose>1) printf(
"computing basis functions at input sample times\n");
209 for(bi=0; bi<bf->
voiNr; bi++) {
213 if(status!=NULL) strcpy(status,
"simulation problem");
218 printf(
"\nk2 := %g\n", a);
219 printf(
"simulated TAC:\n");
220 for(fi=0; fi<input->
frameNr; fi++)
221 printf(
" %12.6f %12.3f\n", input->
x[fi], sim[fi]);
231 if(status!=NULL) strcpy(status,
"simulation problem");
239 if(verbose>1) printf(
"%s() done.\n\n", __func__);
240 if(status!=NULL) strcpy(status,
"ok");
251int main(
int argc,
char **argv)
253 int ai, help=0, version=0, verbose=1;
255 char apfile[FILENAME_MAX], abfile[FILENAME_MAX], petfile[FILENAME_MAX];
256 char k1file[FILENAME_MAX], k2file[FILENAME_MAX], vbfile[FILENAME_MAX];
257 char vtfile[FILENAME_MAX], wssfile[FILENAME_MAX], errfile[FILENAME_MAX];
258 char bfsfile[FILENAME_MAX];
259 int bfNr=500, *bf_opt_nr;
260 float threshold, calcThreshold=0.0;
262 double k1min=0.0, k1max=10.0;
263 double k2min=0.0, k2max=10.0;
264 double vtmin=0.0, vtmax=100.0;
265 double vbmin=0.0, vbmax=1.0;
271 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
272 apfile[0]=abfile[0]=petfile[0]=k1file[0]=k2file[0]=vbfile[0]=vtfile[0]=(char)0;
273 wssfile[0]=errfile[0]=bfsfile[0]=(char)0;
275 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
277 char *cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(cptr==NULL)
continue;
278 if(strncasecmp(cptr,
"VB=", 3)==0 || strncasecmp(cptr,
"VA=", 3)==0) {
279 strlcpy(vbfile, cptr+3, FILENAME_MAX);
if(strlen(vbfile))
continue;
280 }
else if(strncasecmp(cptr,
"VT=", 3)==0 || strncasecmp(cptr,
"VD=", 3)==0) {
281 strlcpy(vtfile, cptr+3, FILENAME_MAX);
if(strlen(vtfile))
continue;
282 }
else if(strncasecmp(cptr,
"K1min=", 6)==0 && strlen(cptr)>6) {
284 }
else if(strncasecmp(cptr,
"K1max=", 6)==0 && strlen(cptr)>6) {
286 }
else if(strncasecmp(cptr,
"k2min=", 6)==0) {
288 }
else if(strncasecmp(cptr,
"k2max=", 6)==0) {
290 }
else if(strncasecmp(cptr,
"Vtmin=", 6)==0) {
292 }
else if(strncasecmp(cptr,
"Vtmax=", 6)==0) {
294 }
else if(strncasecmp(cptr,
"Vbmin=", 6)==0) {
296 }
else if(strncasecmp(cptr,
"Vbmax=", 6)==0) {
298 }
else if(strncasecmp(cptr,
"NR=", 3)==0) {
299 bfNr=atoi(cptr+3);
if(bfNr>5E+04) bfNr=5E+04;
300 if(bfNr>=100)
continue;
301 }
else if(strncasecmp(cptr,
"BF=", 3)==0) {
302 strlcpy(bfsfile, cptr+3, FILENAME_MAX);
if(strlen(bfsfile)>0)
continue;
303 }
else if(strncasecmp(cptr,
"WSS=", 4)==0) {
304 strlcpy(wssfile, cptr+4, FILENAME_MAX);
if(strlen(wssfile)>0)
continue;
305 }
else if(strncasecmp(cptr,
"ERR=", 4)==0) {
306 strlcpy(errfile, cptr+4, FILENAME_MAX);
if(strlen(errfile)>0)
continue;
307 }
else if(strncasecmp(cptr,
"THR=", 4)==0 && strlen(cptr)>4) {
308 cptr+=4;
if(isdigit(*cptr) || *cptr==
'+' || *cptr==
'-') {
310 if(calcThreshold>=0.0 && calcThreshold<=2.0)
continue;
313 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
318 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
323 if(ai<argc)
strlcpy(apfile, argv[ai++], FILENAME_MAX);
324 if(ai<argc)
strlcpy(abfile, argv[ai++], FILENAME_MAX);
325 if(ai<argc)
strlcpy(petfile, argv[ai++], FILENAME_MAX);
328 fprintf(stderr,
"Error: invalid fit time '%s'.\n", argv[ai]);
return(1);}
331 if(ai<argc)
strlcpy(k1file, argv[ai++], FILENAME_MAX);
332 if(ai<argc)
strlcpy(k2file, argv[ai++], FILENAME_MAX);
334 fprintf(stderr,
"Error: invalid argument '%s'.\n", argv[ai]);
339 fprintf(stderr,
"Error: missing command-line argument; use option --help\n");
342 if(fittime<1.0E-04) fittime=1.0E+020;
344 if(vbmin<1.0E-05 && vbmax<1.0E-05) {vbmin=vbmax=0.0; abfile[0]=(char)0;}
346 if(vbmin==vbmax && vbfile[0]) {
347 fprintf(stderr,
"Warning: Vb image will not be created.\n");
354 printf(
"petfile := %s\n", petfile);
355 printf(
"apfile := %s\n", apfile);
356 if(abfile[0]) printf(
"abfile := %s\n", abfile);
357 printf(
"k1file := %s\n", k1file);
358 if(k2file[0]) printf(
"k2file := %s\n", k2file);
359 if(vbfile[0]) printf(
"vbfile := %s\n", vbfile);
360 if(vtfile[0]) printf(
"vtfile := %s\n", vtfile);
361 if(wssfile[0]) printf(
"wssfile := %s\n", wssfile);
362 if(errfile[0]) printf(
"errfile := %s\n", errfile);
363 if(bfsfile[0]) printf(
"bfsfile := %s\n", bfsfile);
364 printf(
"bfNr := %d\n", bfNr);
365 printf(
"calcThreshold := %g\n", calcThreshold);
366 printf(
"requested_fittime := %g [min]\n", fittime);
367 printf(
"k1min := %g\n", k1min);
368 printf(
"k1max := %g\n", k1max);
369 printf(
"k2min := %g\n", k2min);
370 printf(
"k2max := %g\n", k2max);
371 printf(
"vbmin := %g\n", vbmin);
372 printf(
"vbmax := %g\n", vbmax);
373 printf(
"vtmin := %g\n", vtmin);
374 printf(
"vtmax := %g\n", vtmax);
380 fprintf(stderr,
"Error: invalid range for K1 (%g - %g).\n", k1min, k1max);
384 fprintf(stderr,
"Error: invalid range for k2 (%g - %g).\n", k2min, k2max);
387 if(vbmin>vbmax || vbmax>1.0) {
388 fprintf(stderr,
"Error: invalid range for Vb (%g - %g).\n", vbmin, vbmax);
392 fprintf(stderr,
"Error: invalid range for Vt (%g - %g).\n", vtmin, vtmax);
395 if(k1min/vtmax>k2min) k2min=k1min/vtmax;
396 if(vtmin>0.0 && k1max/vtmin<k2max) k2max=k1max/vtmin;
397 if(k2max<=k2min || k2min<0.) {
398 fprintf(stderr,
"Error: invalid range for K1 and Vt.\n");
406 if(verbose>1) printf(
"reading data files\n");
412 petfile, NULL, apfile, abfile, NULL, &fittime, &fitdimt, &img,
413 &input, &tac, 1, stdout, verbose-2, tmp);
415 fprintf(stderr,
"Error: %s.\n", tmp);
416 if(verbose>1) printf(
" ret := %d\n", ret);
420 if(verbose>0) fprintf(stderr,
"Warning: missing pixel values.\n");
427 printf(
"fittimeFinal := %g min\n", fittime);
428 printf(
"fitdimt := %d\n", fitdimt);
433 fprintf(stderr,
"Error: too few time frames for fitting.\n");
439 fprintf(stderr,
"Error: cannot allocate memory.\n"); fflush(stderr);
443 int iAPC=0, iAB=0, iT=1;
if(tac.
voiNr==2) {iAB++; iT++;}
446 if(iAB>0) strcpy(tac.
voi[iAB].
voiname,
"blood");
452 threshold=calcThreshold*tac.
voi[iAPC].
y2[tac.
frameNr-1]/60.0;
453 if(verbose>2) {printf(
"threshold_AUC = %g\n", threshold); fflush(stdout);}
459 if(verbose>1) printf(
"setting weights based on frame lengths\n");
461 fprintf(stderr,
"Warning: cannot calculate weights.\n"); fflush(stderr);
463 for(
int i=0; i<img.
dimt; i++) img.
weight[i]=1.0;
471 if(verbose>1) {fprintf(stdout,
"calculating basis functions\n"); fflush(stdout);}
476 int ret=bf1TCM(&input, &tac, &bf, bfNr, k2min, k2max, tmp, verbose-2);
479 fprintf(stderr,
"Error: cannot calculate basis functions.\n");
480 if(verbose>1) fprintf(stderr,
"bf1TCM(): %s.\n", tmp);
492 if(verbose>1) {printf(
"allocating memory for parametric images\n"); fflush(stdout);}
500 fprintf(stderr,
"Error: out of memory.\n");
504 k1img.
start[0]=0.0; k1img.
end[0]=fittime*60.0;
507 k1img.
unit=IMGUNIT_ML_PER_ML_PER_MIN;
512 if(ret==0) k2img.
unit=IMGUNIT_PER_MIN;
514 if(ret==0 && vtfile[0]) {
516 if(ret==0) vtimg.
unit=IMGUNIT_UNITLESS;
518 if(ret==0 && vbfile[0]) {
520 if(ret==0) vbimg.
unit=IMGUNIT_UNITLESS;
522 if(ret==0 && wssfile[0]) {
524 if(ret==0) wssimg.
unit=IMGUNIT_UNITLESS;
526 if(ret==0 && errfile[0]) {
528 if(ret==0) errimg.
unit=IMGUNIT_UNITLESS;
531 fprintf(stderr,
"Error: out of memory.\n"); fflush(stderr);
544 double **mem, **A, *B, X[MAX_N], *tau, *residual, RNORM, *chain;
545 double *qrweight, **wws, *ws, *wwschain;
547 if(verbose>1) {fprintf(stdout,
"allocating memory for QR\n"); fflush(stdout);}
548 M=tac.
frameNr; N=2;
if(vbmin==vbmax) N--;
549 chain=(
double*)malloc((M+1)*N*bf.
voiNr *
sizeof(
double));
550 mem=(
double**)malloc(bf.
voiNr *
sizeof(
double*));
551 A=(
double**)malloc(M *
sizeof(
double*));
552 B=(
double*)malloc(M*
sizeof(
double));
553 residual=(
double*)malloc(M*
sizeof(
double));
554 qrweight=(
double*)malloc(M*
sizeof(
double));
555 wwschain=(
double*)malloc((M*N+2*M)*
sizeof(
double));
556 wws=(
double**)malloc(M *
sizeof(
double*));
557 if(chain==NULL || B==NULL || A==NULL || residual==NULL || qrweight==NULL || wwschain==NULL || wws==NULL)
559 fprintf(stderr,
"Error: out of memory.\n"); fflush(stderr);
565 for(
int bi=0; bi<bf.
voiNr; bi++) mem[bi]=chain+bi*(M+1)*N;
566 for(
int m=0; m<M; m++) wws[m]=wwschain+m*N;
570 for(
int m=0; m<M; m++) {
571 if(img.
weight[m]<=1.0e-20) qrweight[m]=0.0;
572 else qrweight[m]=sqrt(img.
weight[m]);
577 if(verbose>1) {fprintf(stdout,
"calculating QR decomposition\n"); fflush(stdout);}
578 for(
int bi=0; bi<bf.
voiNr; bi++) {
581 for(
int m=0; m<M; m++) A[m]=mem[bi]+m*N;
585 for(
int m=0; m<M; m++) {
586 A[m][0]=bf.
voi[bi].
y[m];
587 if(N>1) A[m][1]=tac.
voi[iAB].
y[m];
591 for(
int m=0; m<M; m++)
for(
int n=0; n<N; n++) A[m][n]*=qrweight[m];
594 int ret=
qr_decomp(A, M, N, tau, wws, ws);
597 free(chain); free(B); free(residual);
598 free(A); free(wwschain); free(wws); free(qrweight); free(mem);
610 if(verbose>0) {fprintf(stdout,
"computing QR pixel-by-pixel\n"); fflush(stdout);}
611 int nosolution_nr=0, thresholded_nr=0;
612 double *ct=tac.
voi[iT].
y;
613 double *cti=tac.
voi[iT].
y2;
615 bf_opt_nr=(
int*)malloc(bfNr*
sizeof(
int));
616 for(
int bi=0; bi<bf.
voiNr; bi++) bf_opt_nr[bi]=0.0;
618 for(
int zi=0; zi<img.
dimz; zi++) {
619 if(img.
dimz>1 && verbose>0) {
620 if(verbose>6) printf(
"computing plane %d\n", img.
planeNumber[zi]);
else fprintf(stdout,
".");
623 for(
int yi=0; yi<img.
dimy; yi++) {
624 if(verbose>6 && yi==4*img.
dimy/10) printf(
" computing row %d\n", yi+1);
625 for(
int xi=0; xi<img.
dimx; xi++) {
627 if(verbose>6 && yi==4*img.
dimy/10 && xi==4*img.
dimx/10)
628 printf(
" computing column %d\n", xi+1);
630 k1img.
m[zi][yi][xi][0]=0.0;
631 if(k2file[0]) k2img.
m[zi][yi][xi][0]=0.0;
632 if(vbfile[0]) vbimg.
m[zi][yi][xi][0]=0.0;
633 if(vtfile[0]) vtimg.
m[zi][yi][xi][0]=0.0;
634 if(wssfile[0]) wssimg.
m[zi][yi][xi][0]=0.0;
635 if(errfile[0]) errimg.
m[zi][yi][xi][0]=0.0;
639 for(
int m=0; m<M; m++) {ct[m]=img.
m[zi][yi][xi][m];}
643 if(verbose>6 && yi==4*img.
dimy/10 && xi==4*img.
dimx/10) {
644 printf(
" Pixel (%d,%d,%d), int= %f, threshold= %g\n", zi, yi, xi, cti[M-1], threshold);
646 for(
int m=0; m<M; m++)
647 printf(
" %02d:\t%g\t%g\n", m, img.
m[zi][yi][xi][m], tac.
voi[iAPC].
y[m]);
650 if(!(cti[M-1]>=threshold)) {
651 if(errfile[0]) errimg.
m[zi][yi][xi][0]=1.0;
657 if(vbmin==vbmax && vbmin>0.0) {
658 for(
int m=0; m<M; m++) {ct[m]=img.
m[zi][yi][xi][m]-vbmin*tac.
voi[iAB].
y[m];}
662 if(!(cti[M-1]>0.0)) {
663 if(errfile[0]) errimg.
m[zi][yi][xi][0]=1.0;
670 int bi_min=-1;
double rnorm_min=1.0E80;
671 double p1=0.0, p2=0.0, p3=0.0;
672 for(
int bi=0; bi<bf.
voiNr; bi++) {
676 for(
int m=0; m<M; m++) {A[m]=mem[bi]+ m*N;}
680 for(
int m=0; m<M; m++) {
681 B[m]=img.
m[zi][yi][xi][m]*qrweight[m];
685 int ret=
qr_solve(A, M, N, tau, B, X, residual, &RNORM, wws, ws);
687 for(
int n=0; n<N; n++) X[n]=0.0;
692 if(!(RNORM<rnorm_min))
continue;
695 if(N>1 && X[1]>=1.0) {
697 }
else if(N>1 && (X[1]<vbmin || X[1]>vbmax))
continue;
698 if(X[0]<0.0 || X[0]>k1max)
continue;
699 if(!(X[0]/bf.
voi[bi].
size <= vtmax))
continue;
701 rnorm_min=RNORM; bi_min=bi;
703 if(N>1) p2=X[1];
else p2=vbmin;
705 if(p1<k1min+1.0E-05) p3=0.0;
711 if(rnorm_min>=1.0E60) {
713 if(errfile[0]) errimg.
m[zi][yi][xi][0]=2.0;
717 bf_opt_nr[bi_min]+=1;
720 if(verbose>6 && yi==4*img.
dimy/10 && xi==4*img.
dimx/10) {
721 printf(
" Pixel (%d,%d,%d), K1=%g Vb=%g k2=%g\n", zi, yi, xi, p1, p2, p3);
727 for(
int m=0; m<M; m++) {
728 double f=p1*bf.
voi[bi_min].
y[m];
729 if(N>1) f+=p2*tac.
voi[iAB].
y[m];
730 f-=img.
m[zi][yi][xi][m];
734 k1img.
m[zi][yi][xi][0]=p1;
735 if(vbfile[0]) vbimg.
m[zi][yi][xi][0]=p2;
736 if(k2file[0]) k2img.
m[zi][yi][xi][0]=p3;
737 if(vtfile[0]) {
double f=p1/p3;
if(f>=vtmin && f<=vtmax) vtimg.
m[zi][yi][xi][0]=f;}
738 if(wssfile[0]) wssimg.
m[zi][yi][xi][0]=wss;
740 if(bi_min==0 || bi_min==bf.
voiNr-1) errimg.
m[zi][yi][xi][0]=2.0;
741 else errimg.
m[zi][yi][xi][0]=0.0;
747 if(verbose>0) {fprintf(stdout,
"done.\n"); fflush(stdout);}
749 if(verbose>1 || thresholded_nr>0) {
751 f=(double)thresholded_nr/((
double)(k1img.
dimx*k1img.
dimy*k1img.
dimz));
752 f*=100.;
if(f<3.0) printf(
"%g%%", f);
else printf(
"%.0f%%", f);
753 printf(
" of pixels were not fitted due to threshold.\n");
754 if(verbose>2) printf(
"thresholded %d pixels\n", thresholded_nr);
757 if(verbose>1 || nosolution_nr>0) {
758 fprintf(stdout,
"no QR solution for %d pixels.\n", nosolution_nr); fflush(stdout);}
763 free(chain); free(B); free(residual); free(A); free(wwschain);
764 free(wws); free(qrweight); free(mem);
772 for(
int bi=0; bi<bf.
voiNr; bi++) sprintf(bf.
voi[bi].
place,
"%d", bf_opt_nr[bi]);
774 fprintf(stderr,
"Error in writing %s: %s\n", bfsfile,
dfterrmsg); fflush(stderr);
777 dftEmpty(&bf); free(bf_opt_nr);
return(11);
779 if(verbose>0) {fprintf(stdout,
"basis functions written in %s\n", bfsfile); fflush(stdout);}
789 if(verbose>1) {printf(
"Saving parametric images\n"); fflush(stdout);}
792 if(ret) {fprintf(stderr,
"Error: %s\n", k1img.
statmsg); fflush(stderr);}
793 else if(verbose>0) {fprintf(stdout,
"K1 image %s saved.\n", k1file); fflush(stdout);}
795 if(ret==0 && vbfile[0]) {
797 if(ret) {fprintf(stderr,
"Error: %s\n", vbimg.
statmsg); fflush(stderr);}
798 else if(verbose>0) {fprintf(stdout,
"Vb image %s saved.\n", vbfile); fflush(stdout);}
800 if(ret==0 && vtfile[0]) {
802 if(ret) {fprintf(stderr,
"Error: %s\n", vtimg.
statmsg); fflush(stderr);}
803 else if(verbose>0) {fprintf(stdout,
"Vt image %s saved.\n", vtfile); fflush(stdout);}
805 if(ret==0 && k2file[0]) {
807 if(ret) {fprintf(stderr,
"Error: %s\n", k2img.
statmsg); fflush(stderr);}
808 else if(verbose>0) {fprintf(stdout,
"k2 image %s saved.\n", k2file); fflush(stdout);}
810 if(ret==0 && wssfile[0]) {
812 if(ret) {fprintf(stderr,
"Error: %s\n", wssimg.
statmsg); fflush(stderr);}
813 else if(verbose>0) {fprintf(stdout,
"WSS image %s saved.\n", wssfile); fflush(stdout);}
815 if(ret==0 && errfile[0]) {
817 if(ret) {fprintf(stderr,
"Error: %s\n", errimg.
statmsg); fflush(stderr);}
818 else if(verbose>0) {fprintf(stdout,
"Error image %s saved.\n", errfile); fflush(stdout);}
int atof_with_check(char *double_as_string, double *result_value)
double atof_dpi(char *str)
int dftAddmem(DFT *dft, int voiNr)
int dftCopymainhdr2(DFT *dft1, DFT *dft2, int ow)
int dftSetmem(DFT *data, int frameNr, int voiNr)
int dftWrite(DFT *data, char *filename)
int dftTimeunitConversion(DFT *dft, int tunit)
unsigned long long imgNaNs(IMG *img, int fix)
int imgAllocateWithHeader(IMG *image, int planes, int rows, int columns, int frames, IMG *image_from)
void imgEmpty(IMG *image)
int imgWrite(const char *fname, IMG *img)
int petintegral(double *x1, double *x2, double *y, int nr, double *ie, double *iie)
Integrate PET TAC data to frame mid times.
int interpolate(double *x, double *y, int nr, double *newx, double *newy, double *newyi, double *newyii, int newnr)
Linear interpolation and integration.
int interpolate4pet(double *x, double *y, int nr, double *newx1, double *newx2, double *newy, double *newyi, double *newyii, int newnr)
Interpolate and integrate TAC to PET frames.
Header file for libtpccurveio.
#define DFT_TIME_STARTEND
Header file for libtpcimgio.
#define IMG_DC_NONCORRECTED
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.
int simC1(double *t, double *ca, int nr, double k1, double k2, double *ct)
int qr_solve(double **QR, int M, int N, double *tau, double *b, double *x, double *residual, double *resNorm, double **cchain, double *chain)
int qr_decomp(double **a, int M, int N, double *tau, double **cchain, double *chain)
Header file for libtpcmodext.
int imgSetWeights(IMG *img, int wmet, int verbose)
char voiname[MAX_REGIONSUBNAME_LEN+1]
char name[MAX_REGIONNAME_LEN+1]
char hemisphere[MAX_REGIONSUBNAME_LEN+1]
char place[MAX_REGIONSUBNAME_LEN+1]