9#include "tpcclibConfig.h"
25static char *info[] = {
26 "Subtracts the contribution of vascular radioactivity from dynamic PET",
27 "image. Vascular volume fraction Vb can be given as a value that is common",
28 "to all image voxels, or as separate value for each image voxel in a",
29 "(preferably smoothed) Vb image, usually calculated from a [O-15]CO study.",
30 "Vb must be given as a volume fraction, not percentage, whether it is given",
31 "directly or inside the Vb image.",
33 "Usage: @P [Options] imgfile btacfile Vb outputfile",
37 " Negative voxel values are set to 0.",
39 " Equation Ct=Cpet-Vb*Cb is applied by default or with option -pv;",
40 " with option -tv equation Ct=(Cpet-Vb*Cb)/(1-Vb) is applied.",
42 " Simulate the contribution of vascular radioactivity instead of",
43 " correcting for it, calculating Cpet from Ct using equations above.",
46 "Example 1: Vascular volume fraction in all tissue is assumed to be 0.04:",
47 " imgcbv ua2918dy1.img ua2918ab.kbq 0.04 ua2918cbv.img",
48 "Example 2: Vascular volume fraction is given in specific image file:",
49 " imgcbv ua2918dy1.v ua2918ab.kbq ua2918vb.v ua2918cbv.v",
51 "See also: taccbv, imgcalc, p2blood, imgunit, tacunit",
53 "Keywords: image, modelling, vascular fraction, simulation",
88 if(verbose>1) printf(
"ecatCopyHeaders(%s, %s)\n", file1, file2);
89 if(file1==NULL || file2==NULL)
return(1);
96 strcpy(tmp,
"user_process_code");
98 strcpy(tmp,
"ecat_calibration_factor");
102 for(mi=0; mi<ehdr.
nr; mi++) {
103 strcpy(tmp,
"scale_factor");
105 strcpy(tmp,
"image_min");
107 strcpy(tmp,
"image_max");
109 strcpy(tmp,
"scan_min");
111 strcpy(tmp,
"scan_max");
118 if(ret!=0)
return(10+ret);
129int main(
int argc,
char **argv)
131 int ai, help=0, version=0, verbose=1;
136 char infile[FILENAME_MAX], blfile[FILENAME_MAX], outfile[FILENAME_MAX],
137 *cptr, tmp[FILENAME_MAX+128],
138 vbfile[FILENAME_MAX];
150 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
151 infile[0]=outfile[0]=blfile[0]=vbfile[0]=(char)0;
154 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
155 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(cptr==NULL)
continue;
157 if(strncasecmp(cptr,
"NONEGATIVES", 1)==0) {
158 leave_negat=0;
continue;
159 }
else if(strncasecmp(cptr,
"PV", 1)==0) {
160 pet_volume=1;
continue;
161 }
else if(strncasecmp(cptr,
"TV", 1)==0) {
162 pet_volume=0;
continue;
163 }
else if(strncasecmp(cptr,
"SIMULATE", 3)==0) {
166 fprintf(stderr,
"Error: unknown option '%s'.\n", argv[ai]);
171 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
176 for(; ai<argc; ai++) {
178 strlcpy(infile, argv[ai], FILENAME_MAX);
continue;
179 }
else if(!blfile[0]) {
180 strlcpy(blfile, argv[ai], FILENAME_MAX);
continue;
181 }
else if(isvalue==0 && !vbfile[0]) {
187 fprintf(stderr,
"Warning: Vb fraction is set to %.3f\n", vb);
190 strlcpy(vbfile, argv[ai], FILENAME_MAX);
193 }
else if(!outfile[0]) {
194 strlcpy(outfile, argv[ai], FILENAME_MAX);
continue;
196 fprintf(stderr,
"Error: too many arguments: '%s'.\n", argv[ai]);
202 fprintf(stderr,
"Error: missing command-line argument; use option --help\n");
209 printf(
"infile := %s\n", infile);
210 printf(
"blfile := %s\n", blfile);
211 printf(
"vbfile := %s\n", vbfile);
212 printf(
"pet_volume := %d\n", pet_volume);
213 printf(
"vb := %g\n", vb);
214 printf(
"leave_negat := %d\n", leave_negat);
215 printf(
"add_vb := %d\n", add_vb);
218 printf(
"\napplying formula:\n");
220 if(pet_volume==0) printf(
"Ct=(Cpet-Vb*Cb)/(1-Vb)\n");
221 else printf(
"Ct=Cpet-Vb*Cb\n");
223 if(pet_volume==0) printf(
"Cpet=(1-Vb)*Ct+Vb*Cb\n");
224 else printf(
"Cpet=Ct+Vb*Cb\n");
230 if(strcasecmp(infile, outfile)==0) {
231 fprintf(stderr,
"Error: original file must not be overwritten.\n");
239 if(verbose>1) printf(
"reading data files\n");
242 infile, NULL, blfile, NULL, NULL, &endtime, &ai, &img,
243 NULL, &blood, 0, stdout, verbose-1, tmp);
245 fprintf(stderr,
"Error in reading data: %s.\n", tmp);
246 if(verbose>1) printf(
" ret := %d\n", ret);
249 if(verbose>2) printf(
"endtime := %g min\n", endtime);
259 if(verbose>1) printf(
"reading %s\n", vbfile);
262 fprintf(stderr,
"Error: %s\n", vbimg.
statmsg);
267 fprintf(stderr,
"Error: %s is not an image.\n", vbfile);
271 fprintf(stderr,
"Error: Vb image contains > 1 frame.\n");
280 fprintf(stderr,
"Error: Vb image has different dimensions.\n");
285 if(verbose>2) printf(
"Maximum value in Vb image: %g\n", f);
288 fprintf(stderr,
"Warning: Vb values were converted to fractions.\n");
295 if(verbose>1) printf(
"subtracting\n");
298 for(zi=0; zi<img.
dimz; zi++)
299 for(yi=0; yi<img.
dimy; yi++)
300 for(xi=0; xi<img.
dimx; xi++) {
301 if(vbfile[0]) vb=vbimg.
m[zi][yi][xi][0];
302 for(fi=0; fi<img.
dimt; fi++) {
303 img.
m[zi][yi][xi][fi]-=vb*blood.
voi[0].
y[fi];
304 if(pet_volume==0) img.
m[zi][yi][xi][fi]/=(1.0-vb);
305 if(leave_negat==0 && img.
m[zi][yi][xi][fi]<0.0)
306 img.
m[zi][yi][xi][fi]=0.0;
316 if(verbose) fprintf(stdout,
"writing image %s\n", outfile);
319 fprintf(stderr,
"Error: %s\n", img.
statmsg);
322 if(verbose>1) fprintf(stdout,
"Vb corrected image %s saved.\n", outfile);
326 if(verbose>1) printf(
"copying header information\n");
328 if(verbose>0 && ret!=0)
329 printf(
"copying headers not successful (%d).\n", ret);
333 if(verbose>0) printf(
"done.\n");
int atof_with_check(char *double_as_string, double *result_value)
int dftTimeunitConversion(DFT *dft, int tunit)
void ehdrEmpty(ECAT_HEADERS *ehdr)
int ecat7WriteHeaders(const char *fname, ECAT_HEADERS *ehdr, int verbose)
void ehdrInitiate(ECAT_HEADERS *ehdr)
int ecat7ReadHeaders(const char *fname, ECAT_HEADERS *ehdr, int verbose)
int iftDeleteItem(IFT *ift, int item, int verbose)
int iftGet(IFT *ift, char *key, int verbose)
void imgEmpty(IMG *image)
int imgArithmConst(IMG *img, float operand, char operation, float ulimit, int verbose)
int ecat7CopyHeadersNoQuant(const char *file1, const char *file2, int verbose)
int imgRead(const char *fname, IMG *img)
int imgWrite(const char *fname, IMG *img)
int imgMax(IMG *img, float *maxvalue)
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 libtpcmodext.