9#include "tpcclibConfig.h"
27static char *info[] = {
28 "Find those voxels in dynamic PET image which correlate best with",
29 "user-specified TAC. Program saves a static image containing the Pearson's",
30 "correlation coefficients.",
32 "Usage: @P [Options] image tac ccimage",
36 " Save the slopes of lines fitted to the concentration values as",
39 " Save the y axis intercepts of lines fitted to the concentrations as",
42 " Integrals from 0 to each sample time are used in the correlation.",
45 "See also: imgthrs, imgqntls, imgslim, imgcalc, pxl2tac, imgdysmo",
47 "Keywords: image, TAC, correlation, mask, threshold",
66int main(
int argc,
char **argv)
68 int ai, help=0, version=0, verbose=1;
69 char imgfile[FILENAME_MAX], tacfile[FILENAME_MAX], outfile[FILENAME_MAX];
70 char slopefile[FILENAME_MAX], icfile[FILENAME_MAX];
71 int useIntegralCurve=0;
80 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
81 imgfile[0]=tacfile[0]=outfile[0]=slopefile[0]=icfile[0]=(char)0;
83 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
85 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(cptr==NULL)
continue;
86 if(strncasecmp(cptr,
"SLOPE=", 6)==0) {
87 strlcpy(slopefile, cptr+6, FILENAME_MAX);
continue;
88 }
else if(strncasecmp(cptr,
"IC=", 3)==0) {
89 strlcpy(icfile, cptr+3, FILENAME_MAX);
continue;
90 }
else if(strncasecmp(cptr,
"INTEGRAL", 1)==0) {
91 useIntegralCurve=1;
continue;
93 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
98 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
103 if(ai<argc) {
strlcpy(imgfile, argv[ai++], FILENAME_MAX);}
104 if(ai<argc) {
strlcpy(tacfile, argv[ai++], FILENAME_MAX);}
105 if(ai<argc) {
strlcpy(outfile, argv[ai++], FILENAME_MAX);}
107 fprintf(stderr,
"Error: invalid argument '%s'.\n", argv[ai]);
113 fprintf(stderr,
"Error: missing command-line argument; use option --help\n");
119 printf(
"imgfile := %s\n", imgfile);
120 printf(
"tacfile := %s\n", tacfile);
121 printf(
"outfile := %s\n", outfile);
122 if(slopefile[0]) printf(
"slopefile := %s\n", slopefile);
123 if(icfile[0]) printf(
"icfile := %s\n", icfile);
124 printf(
"useIntegralCurve := %d\n", useIntegralCurve);
133 if(verbose>0) printf(
"reading data files\n");
135 double scanlen=1.0E+020;
138 imgfile, NULL, tacfile, NULL, NULL, &scanlen, &frameNr, &img,
139 NULL, &tac, 0, stdout, verbose-2, tmp);
141 fprintf(stderr,
"Error: cannot read the data.\n");
142 fprintf(stderr,
"%s.\n", tmp);
143 if(verbose>1) printf(
" ret := %d\n", ret);
147 printf(
"scanlen := %g\n", scanlen);
148 printf(
"frameNr := %d\n", frameNr);
152 fprintf(stderr,
"Error: too few time frames.\n");
157 fprintf(stderr,
"Warning: only the first TAC is used.\n");
164 if(verbose>1) fprintf(stdout,
"allocating memory\n");
170 fprintf(stderr,
"Error: cannot allocate memory for new image.\n");
175 if(verbose>2) fprintf(stdout,
"copying data\n");
183 fprintf(stderr,
"Error: cannot allocate memory for new image.\n");
188 if(verbose>2) fprintf(stdout,
"copying data\n");
197 fprintf(stderr,
"Error: cannot allocate memory for new image.\n");
202 if(verbose>2) fprintf(stdout,
"copying data\n");
214 double *x, y[img.
dimt], k, kSD, b, bSD, r, ySD;
215 for(zi=0; zi<img.
dimz; zi++) {
216 for(yi=0; yi<img.
dimy; yi++)
for(xi=0; xi<img.
dimx; xi++) {
218 if(useIntegralCurve==0) {
220 for(ti=0; ti<img.
dimt; ti++) y[ti]=img.
m[zi][yi][xi][ti];
223 float ytemp[img.
dimt];
225 if(ret==0)
for(ti=0; ti<img.
dimt; ti++) y[ti]=ytemp[ti];
226 else for(ti=0; ti<img.
dimt; ti++) y[ti]=0.0;
228 ret=
pearson3(x, y, img.
dimt, &k, &kSD, &b, &bSD, &r, &ySD);
232 k=kSD=b=bSD=r=ySD=0.0;
234 ccimg.
m[zi][yi][xi][0]=(float)r;
236 if(k>1.0E+03) kimg.
m[zi][yi][xi][0]=1.0E+03;
237 else if(k<-1.0E+03) kimg.
m[zi][yi][xi][0]=-1.0E+03;
238 else kimg.
m[zi][yi][xi][0]=(float)k;
240 if(icfile[0]) bimg.
m[zi][yi][xi][0]=(float)b;
248 if(verbose>1) fprintf(stdout,
"writing correlation image...\n");
251 fprintf(stderr,
"Error: %s\n", ccimg.
statmsg);
254 if(verbose>0) fprintf(stdout,
"%s written.\n", outfile);
258 if(verbose>1) fprintf(stdout,
"writing slope image...\n");
261 fprintf(stderr,
"Error: %s\n", kimg.
statmsg);
264 if(verbose>0) fprintf(stdout,
"%s written.\n", slopefile);
269 if(verbose>1) fprintf(stdout,
"writing intercept image...\n");
272 fprintf(stderr,
"Error: %s\n", bimg.
statmsg);
275 if(verbose>0) fprintf(stdout,
"%s written.\n", icfile);
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 fpetintegral(float *x1, float *x2, float *y, int nr, float *ie, float *iie)
Integrate PET TAC data to frame mid times. Float version of petintegral().
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.
int pearson3(double *x, double *y, int nr, double *k, double *kSD, double *b, double *bSD, double *r, double *ySD)
Header file for libtpcmodext.