9#include "tpcclibConfig.h"
25static char *info[] = {
26 "Find maximum pixel value in PET image file(s) in ECAT 6.3 or 7.x, NIfTI-1,",
27 "or Analyze 7.5 format.",
29 "Usage: @P [Options] imgfile(s)",
33 " Minimum values are printed instead of maximum values.",
35 " Both max and min values are printed.",
37 " Only the max and/or min value of all specified files is printed.",
40 "Example: get the maximum and minimum values inside all ECAT 7 image files",
41 "in the current folder:"
44 "See also: imgmaxp, imgunit, lmhdr, lshdr, eframe, img2tif, img2flat",
46 "Keywords: image, ECAT, NIfTI, Analyze, max, min",
65int main(
int argc,
char **argv)
67 int ai, help=0, version=0, verbose=1;
68 int ret, fileNr=0, firstfile=0;
70 int differing_units=0;
72 char imgfile[FILENAME_MAX], *cptr=NULL, imgunit[128];
74 float imgmax=-FLT_MAX, allmax=-FLT_MAX;
75 float imgmin=FLT_MAX, allmin=FLT_MAX;
81 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
82 imgfile[0]=(char)0; strcpy(imgunit,
"");
85 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
86 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(cptr==NULL)
continue;
88 if(strncasecmp(cptr,
"CLEAN", 1)==0) {
89 cleanOutput=1;
continue;
90 }
else if(strncasecmp(cptr,
"MINIMUM", 3)==0) {
91 print_what=1;
continue;
92 }
else if(strncasecmp(cptr,
"BOTH", 2)==0) {
93 print_what=2;
continue;
95 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
100 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
105 for(; ai<argc; ai++) {
106 if(firstfile==0) firstfile=ai;
110 if(fileNr==0) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
115 printf(
"cleanOutput := %d\n", cleanOutput);
116 printf(
"fileNr := %d\n", fileNr);
117 printf(
"print_what := %d\n", print_what);
126 if(verbose>0) printf(
"processing %d file(s)...\n", fileNr);
128 for(ai=firstfile; ai<argc; ai++) {
130 strlcpy(imgfile, argv[ai], FILENAME_MAX);
131 imgmax=-FLT_MAX; imgmin=FLT_MAX;
134 if(!cleanOutput) {fprintf(stdout,
"%s :\n", imgfile); fflush(stdout);}
137 fprintf(stderr,
"Warning: %s\n", img.
statmsg);
138 if(verbose>1) printf(
"ret := %d\n", ret);
145 fprintf(stderr,
"Warning: cannot read maximum.\n");
150 if(imgunit[0] && strcasecmp(imgunit, cptr)!=0) differing_units=1;
153 if(print_what==0 || print_what==2)
154 fprintf(stdout,
" max := %g %s\n", imgmax, imgunit);
155 if(print_what==1 || print_what==2)
156 fprintf(stdout,
" min := %g %s\n", imgmin, imgunit);
158 if(imgmax>allmax) allmax=imgmax;
159 if(imgmin<allmin) allmin=imgmin;
164 fprintf(stderr,
"Error: no file(s) could be read.\n");
173 if(print_what==0 || print_what==2)
174 fprintf(stdout,
"%g\n", allmax);
175 if(print_what==1 || print_what==2)
176 fprintf(stdout,
"%g\n", allmin);
177 }
else if(fileNr>1) {
178 if(differing_units) strcpy(imgunit,
"");
179 if(print_what==0 || print_what==2)
180 fprintf(stdout,
"Maximum of all files := %g %s\n", allmax, imgunit );
181 if(print_what==1 || print_what==2)
182 fprintf(stdout,
"Minimum of all files := %g %s\n", allmin, imgunit );
void imgEmpty(IMG *image)
int imgRead(const char *fname, IMG *img)
int imgMinMax(IMG *img, float *minvalue, float *maxvalue)
char * imgUnit(int dunit)
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)