9#include "tpcclibConfig.h"
25static char *info[] = {
26 "List the x and y profiles of PET image at the pixel of maximum intensity",
27 "inside the 4D image. X and y profiles are saved separately in TAC format",
28 "files; from dynamic image the profiles from every time frame are saved.",
30 "Usage: @P [Options] imgfile xprofile yprofile [zprofile]",
33 " -tif=<TIFF filename>",
34 " Image matrix where profiles are calculated is saved as TIFF image",
35 " showing the profile lines.",
36 " -pxl=<x,y,z> or -pxlfile=<filename>",
37 " Instead of maximum, calculate profiles at pixel (x,y,z), where",
38 " x=column (starting from left, 1..width), y=row (starting from top,",
39 " 1..height), and z=plane (1..depth).",
40 " Option -pxlfile can be used to give pixel coordinates in file.",
42 " Profiles are centred on the selected pixel.",
46 " @P us3456dy.v profilex.tac profiley.tac",
48 "See also: imgmaxp, imgpeak, pxl2tac, img2tif, imgthrs, imgdim, mask2pxl",
50 "Keywords: image, profile, max, input, aorta",
69int main(
int argc,
char **argv)
71 int ai, help=0, version=0, verbose=1;
72 char imgfile[FILENAME_MAX], tiffile[FILENAME_MAX], pxlfile[FILENAME_MAX];
73 char prxfile[FILENAME_MAX], pryfile[FILENAME_MAX], przfile[FILENAME_MAX];
83 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
84 imgfile[0]=pxlfile[0]=tiffile[0]=prxfile[0]=pryfile[0]=przfile[0]=(char)0;
85 pos.
x=pos.
y=pos.
z=pos.
f=0;
87 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
88 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(cptr==NULL)
continue;
90 if(strncasecmp(cptr,
"TIF=", 4)==0) {
91 if(
strlcpy(tiffile, cptr+4, FILENAME_MAX)>1)
continue;
92 }
else if(strncasecmp(cptr,
"PXL=", 4)==0 && strlen(cptr)>4) {
94 if(ret==0 && pos.
x>0 && pos.
y>0 && pos.
z>0)
continue;
95 }
else if(strncasecmp(cptr,
"PXLFILE=", 8)==0) {
96 if(
strlcpy(pxlfile, cptr+8, FILENAME_MAX)>1)
continue;
97 }
else if(strcasecmp(cptr,
"FOCUS")==0) {
100 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
105 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
110 if(ai<argc) {
strlcpy(imgfile, argv[ai], FILENAME_MAX); ai++;}
111 if(ai<argc) {
strlcpy(prxfile, argv[ai], FILENAME_MAX); ai++;}
112 if(ai<argc) {
strlcpy(pryfile, argv[ai], FILENAME_MAX); ai++;}
113 if(ai<argc) {
strlcpy(przfile, argv[ai], FILENAME_MAX); ai++;}
114 if(ai<argc) {fprintf(stderr,
"Error: too many arguments.\n");
return(1);}
118 fprintf(stderr,
"Error: missing command-line argument; use option --help\n");
121 if(pxlfile[0] && pos.
x>0) {
122 fprintf(stderr,
"Error: do not use -pxl and -pxlfile together.\n");
128 printf(
"imgfile := %s\n", imgfile);
129 printf(
"prxfile := %s\n", prxfile);
130 printf(
"pryfile := %s\n", pryfile);
131 if(przfile[0]) printf(
"przfile := %s\n", przfile);
132 if(tiffile[0]) printf(
"tiffile := %s\n", tiffile);
133 if(pxlfile[0]) printf(
"pxlfile := %s\n", pxlfile);
134 printf(
"focus := %d\n", focus);
141 if(verbose==1) printf(
"reading %s\n", pxlfile);
145 ret=
pxlRead(&pxl, pxlfile, buf);
147 fprintf(stderr,
"Error: %s\n", buf);
148 fprintf(stderr,
"Error: cannot read pixel definition file.\n");
149 if(verbose>2) printf(
"ret := %d\n", ret);
152 if(pxl.
pxlNr>1) fprintf(stderr,
"Warning: using only the first pixel definition.\n");
153 pos.
x=pxl.
p[0].
x; pos.
y=pxl.
p[0].
y; pos.
z=pxl.
p[0].
z;
157 if(pos.
x>0) printf(
"pixel := %d,%d,%d\n", pos.
x, pos.
y, pos.
z);
164 if(verbose>0) printf(
"reading PET data %s\n", imgfile);
168 fprintf(stderr,
"Error: %s\n", img.
statmsg);
169 if(verbose>1) printf(
"ret := %d\n", ret);
172 if(verbose>0) fprintf(stdout,
" image contains %d frames and %d planes.\n", img.
dimt, img.
dimz);
173 if(przfile[0] && img.
dimz<3) {
174 fprintf(stderr,
"Warning: option for z profile ignored for this data.\n");
178 if(verbose>0) fprintf(stderr,
"Warning: missing pixel values.\n");
187 if(verbose>1) fprintf(stdout,
" searching for image max\n");
190 fprintf(stderr,
"Error: cannot determine maximum in image.\n");
196 printf(
" max_pixel := %d,%d,%d,%d\n", pos.
x, pos.
y, pos.
z, pos.
f);
197 printf(
" max_smoothed_value := %g\n", maxv);
202 if(verbose>1) fprintf(stdout,
" searching for image max value\n");
205 fprintf(stderr,
"Error: cannot determine maximum in image.\n");
210 if(verbose>0) {printf(
" max_smoothed_value := %g\n", maxv);}
220 if(verbose>1) fprintf(stdout,
"creating x profiles\n");
223 fprintf(stderr,
"Error: cannot allocate memory.\n");
237 d=-(0.5*((double)img.
dimx-1.0));
238 for(
int fi=0; fi<img.
dimx; fi++) {
239 dft.
x[fi]=d*img.
sizex; d+=1.0;
242 double c=(((double)pos.
x-1.0) - 0.5*((double)img.
dimx-1.0)) * img.
sizex;
243 if(verbose>2) printf(
"pos.x=%d cx=%g\n", pos.
x, c);
244 for(
int fi=0; fi<img.
dimx; fi++) dft.
x[fi]-=c;
248 for(
int ri=0; ri<dft.
voiNr; ri++) {
251 snprintf(buf, 128,
"%g", img.
mid[ri]); buf[6]=(char)0;
254 sprintf(dft.
voi[ri].
name,
"%s %s %s",
260 sprintf(dft.
voi[0].
place,
"z%04d", pos.
z);
261 sprintf(dft.
voi[0].
name,
"%s %s %s",
265 for(
int xi=0; xi<img.
dimx; xi++)
266 for(
int fi=0; fi<img.
dimt; fi++)
267 dft.
voi[fi].
y[xi]=img.
m[pos.
z-1][pos.
y-1][xi][fi];
271 fprintf(stderr,
"Error in writing '%s': %s\n", prxfile,
dfterrmsg);
275 if(verbose>0) fprintf(stdout,
"x profile(s) written in %s\n", prxfile);
283 if(verbose>1) fprintf(stdout,
"creating y profiles\n");
286 fprintf(stderr,
"Error: cannot allocate memory.\n");
300 d=-(0.5*((double)img.
dimy-1.0));
301 for(
int fi=0; fi<img.
dimy; fi++) {
302 dft.
x[fi]=d*img.
sizey; d+=1.0;
305 double c=(((double)pos.
y-1.0) - 0.5*((double)img.
dimx-1.0)) * img.
sizex;
306 if(verbose>2) printf(
"pos.y=%d cy=%g\n", pos.
y, c);
307 for(
int fi=0; fi<img.
dimy; fi++) dft.
x[fi]-=c;
311 for(
int ri=0; ri<dft.
voiNr; ri++) {
313 snprintf(buf, 128,
"%g", img.
mid[ri]); buf[6]=(char)0;
316 sprintf(dft.
voi[ri].
name,
"%s %s %s",
322 sprintf(dft.
voi[0].
place,
"z%04d", pos.
z);
323 sprintf(dft.
voi[0].
name,
"%s %s %s",
327 for(
int yi=0; yi<img.
dimy; yi++)
328 for(
int fi=0; fi<img.
dimt; fi++)
329 dft.
voi[fi].
y[yi]=img.
m[pos.
z-1][yi][pos.
x-1][fi];
333 fprintf(stderr,
"Error in writing '%s': %s\n", pryfile,
dfterrmsg);
338 fprintf(stdout,
"y profile(s) written in %s\n", pryfile);
345 if(przfile[0] && img.
dimz>2) {
347 if(verbose>1) fprintf(stdout,
"creating z profiles\n");
350 fprintf(stderr,
"Error: cannot allocate memory.\n");
364 d=-(0.5*((double)img.
dimz-1.0));
365 for(
int fi=0; fi<img.
dimz; fi++) {
366 dft.
x[fi]=d*img.
sizez; d+=1.0;
369 double c=(((double)pos.
z-1.0) - 0.5*((double)img.
dimz-1.0)) * img.
sizez;
370 if(verbose>2) printf(
"pos.z=%d cy=%g\n", pos.
z, c);
371 for(
int fi=0; fi<img.
dimz; fi++) dft.
x[fi]-=c;
375 for(
int ri=0; ri<dft.
voiNr; ri++) {
377 snprintf(buf, 128,
"%g", img.
mid[ri]); buf[6]=(char)0;
380 sprintf(dft.
voi[ri].
name,
"%s %s %s",
386 sprintf(dft.
voi[0].
place,
"z%04d", pos.
z);
387 sprintf(dft.
voi[0].
name,
"%s %s %s",
391 for(
int zi=0; zi<img.
dimz; zi++)
392 for(
int fi=0; fi<img.
dimt; fi++)
393 dft.
voi[fi].
y[zi]=img.
m[zi][pos.
y-1][pos.
x-1][fi];
397 fprintf(stderr,
"Error in writing '%s': %s\n", przfile,
dfterrmsg);
402 fprintf(stdout,
"z profile(s) written in %s\n", przfile);
411 if(verbose>1) fprintf(stdout,
"creating TIFF image(s)\n");
412 char tmp[FILENAME_MAX+16], extension[FILENAME_MAX];
415 for(fi=0; fi<img.
dimt; fi++) {
419 strcpy(tmp, tiffile); cptr=strrchr(tmp,
'.');
420 if(cptr!=NULL) {strcpy(extension, cptr); *cptr=(char)0;}
421 else {strcpy(extension,
".tif");}
423 snprintf(tiffile, FILENAME_MAX,
"%s_f%d%s", tmp, fi+1, extension);
426 for(xj=0; xj<img.
dimx; xj++) {
427 if(img.
m[pos.
z-1][pos.
y-1][xj][fi]>0.5*maxv)
428 img.
m[pos.
z-1][pos.
y-1][xj][fi]=0.0;
430 img.
m[pos.
z-1][pos.
y-1][xj][fi]=maxv;
432 for(yj=0; yj<img.
dimy; yj++) {
433 if(img.
m[pos.
z-1][yj][pos.
x-1][fi]>0.5*maxv)
434 img.
m[pos.
z-1][yj][pos.
x-1][fi]=0.0;
436 img.
m[pos.
z-1][yj][pos.
x-1][fi]=maxv;
440 0, 0, verbose-5, NULL);
441 if(ret) fprintf(stderr,
"Warning: cannot write %s (%d)\n", tiffile, ret);
442 else if(verbose>0) fprintf(stdout,
" %s written.\n", tiffile);
int dftSetmem(DFT *data, int frameNr, int voiNr)
int dftWrite(DFT *data, char *filename)
unsigned long long imgNaNs(IMG *img, int fix)
void imgEmpty(IMG *image)
int imgRead(const char *fname, IMG *img)
int imgSmoothMax(IMG *img, float *maxvalue, IMG_PIXEL *p)
int tiffWriteImg(IMG *img, int plane, int frame, float *maxvalue, int colorscale, char *fname, int matXdim, int matYdim, int verbose, char *status)
char * imgUnit(int dunit)
Header file for libtpccurveio.
#define DFT_FORMAT_STANDARD
Header file for libtpcimgio.
int string_to_xyz(char *str, int *x, int *y, int *z)
void pxlFree(IMG_PIXELS *pxl)
int pxlRead(IMG_PIXELS *pxl, const char *fname, char *status)
void pxlInit(IMG_PIXELS *pxl)
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)
int studynr_from_fname(char *fname, char *studynr)
void tpcPrintBuild(const char *program, FILE *fp)
#define MAX_REGIONSUBNAME_LEN
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
char studynr[MAX_STUDYNR_LEN+1]
char unit[MAX_UNITS_LEN+1]
char studyNr[MAX_STUDYNR_LEN+1]
char voiname[MAX_REGIONSUBNAME_LEN+1]
char name[MAX_REGIONNAME_LEN+1]
char hemisphere[MAX_REGIONSUBNAME_LEN+1]
char place[MAX_REGIONSUBNAME_LEN+1]