8#include "tpcclibConfig.h"
25static char *info[] = {
26 "Smoothing of dynamic PET image in ECAT 6.3 and 7, Analyze 7.5, and NIfTI",
28 "Replaces pixel TACs with an average TAC of up to 5x5x5 neighbouring pixels",
29 "which are selected based on the MRL (maximum run length) and AUC difference.",
30 "Note that before application in data analysis, the quantitativity of",
31 "the regional results must be validated.",
33 "Usage: @P [Options] dynamic_image smoothed_image",
37 " Set filter mask to 3x3x3 or 5x5x5 pixels (default).",
39 " Set smoothing strength: 1=min, 2=default, 5=max.",
41 " Set the nr of pixels to average inside smoothing mask;",
42 " by default this is set automatically based on the mask size.",
46 " @P b123dy1.v b123dy1smoothed.v",
48 "See also: imgthrs, imgbkgrm, imgfsegm, imgfiltg, fvar4img",
50 "Keywords: image, smoothing, modelling",
69int main(
int argc,
char **argv)
71 int ai, help=0, version=0, verbose=1;
72 int ret=0, maskSize=5, smoothing=2, avgNr=0;
73 char imgfile[FILENAME_MAX], smofile[FILENAME_MAX], tmp[FILENAME_MAX];
81 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
82 imgfile[0]=smofile[0]=(char)0;
85 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
86 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(cptr==NULL)
continue;
89 if(strncasecmp(cptr,
"M=", 2)==0) {
90 cptr+=2; maskSize=atoi(cptr);
if(maskSize==3 || maskSize==5)
continue;
91 }
else if(strncasecmp(cptr,
"S=", 2)==0) {
92 cptr+=2; smoothing=atoi(cptr);
if(smoothing>0 && smoothing<6)
continue;
93 }
else if(strncasecmp(cptr,
"A=", 2)==0) {
94 cptr+=2; avgNr=atoi(cptr);
if(avgNr>1)
continue;
96 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
101 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
106 for(; ai<argc; ai++) {
108 strcpy(imgfile, argv[ai]);
continue;
109 }
else if(!smofile[0]) {
110 strcpy(smofile, argv[ai]);
continue;
112 fprintf(stderr,
"Error: invalid argument '%s'.\n", argv[ai]);
118 fprintf(stderr,
"Error: missing command-line argument; try %s --help\n",
125 printf(
"imgfile := %s\n", imgfile);
126 printf(
"smofile := %s\n", smofile);
127 printf(
"maskSize := %d\n", maskSize);
128 printf(
"smoothing=%d\n", smoothing);
129 printf(
"avgNr := %d\n", avgNr);
136 if(verbose>=0) fprintf(stdout,
"reading dynamic image %s\n", imgfile);
138 fprintf(stderr,
"Error: %s\n", img.
statmsg);
146 fprintf(stderr,
"Error: raw PET data cannot be smoothed with this program.\n");
150 if(verbose>0) fprintf(stderr,
"Warning: missing pixel values.\n");
153 fprintf(stderr,
"Error: image has only one time frame.\n");
158 fprintf(stderr,
"Warning: smoothing would work better for images with more planes.\n");
166 if(avgNr<2)
switch(maskSize) {
169 case 1: avgNr=3;
break;
170 case 2: avgNr=5;
break;
171 case 3: avgNr=7;
break;
172 case 4: avgNr=9;
break;
173 case 5: avgNr=11;
break;
174 default: avgNr=5;
break;
180 case 1: avgNr=5;
break;
181 case 2: avgNr=9;
break;
182 case 3: avgNr=15;
break;
183 case 4: avgNr=25;
break;
184 case 5: avgNr=35;
break;
185 default: avgNr=9;
break;
189 ret=maskSize*maskSize*maskSize/2;
if(avgNr>ret) avgNr=ret;
192 printf(
"Average of %d best pixels inside %dx%dx%d matrix.\n",
193 avgNr, maskSize, maskSize, maskSize);
195 if(verbose>=0) printf(
"Calculating smoothed image\n");
198 fprintf(stderr,
"Error (%d): cannot smooth.\n", ret);
203 if(verbose>=0) printf(
"writing smoothed image %s\n", smofile);
206 fprintf(stderr,
"Error: %s\n", smoimg.
statmsg);
216 if(verbose>=0) fprintf(stdout,
"done.\n");
int backupExistingFile(char *filename, char *backup_ext, char *status)
unsigned long long imgNaNs(IMG *img, int fix)
void imgEmpty(IMG *image)
int imgRead(const char *fname, IMG *img)
int imgWrite(const char *fname, IMG *img)
int imgsegmSimilar(IMG *input, int smoothDim, int smoothNr, IMG *output, int verbose)
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)
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.
Header file for libtpcmodext.