9#include "tpcclibConfig.h"
24static char *info[] = {
25 "Extract the matrices of an ECAT 6.3 or ECAT 7 image or sinogram, or",
26 "NIfTI, Analyze 7.5, or microPET image, to TIFF 6.0 image.",
28 "Usage: @P [Options] imgfile [tiffile]",
32 " A specified image plane is extracted; by default all planes.",
34 " A specified image frame is extracted; by default all frames.",
36 " Color scale of output images is fixed from 0 to max of all",
37 " image matrices, or from 0 to Value.",
41 " Log10 transform, adding 1 to pixel values before transform.",
43 " Apply rainbow colorscale instead of default grayscale.",
45 " Apply rainbow colorscale with white background.",
47 " Apply grayscale (0=black, highest=white).",
49 " Apply inverse grayscale; default.",
51 " Number of matrices tiled horizontally; set to a large value to draw",
52 " all matrices in one row.",
54 " Number of matrices tiled vertically; set to a large value to draw",
55 " all matrices in one column.",
58 "Example 1: Make TIFF of plane 8 and frame 17, which is yet scaled to",
59 "the level of whole image maximum:",
60 " @P -s -p=8 -f=17 s2345dy1.v s2345_pl08_fr17.tif",
61 "Example 2: Make TIFF of all image matrices in rainbow color scale:",
62 " @P -rb s2345sum.img s2345sum.tif",
63 "Example 3: Make TIFF of all image matrices, scaling the colors to value 3:",
64 " @P -S=3 a3456bp.v a3456bp.tif",
66 "See also: imgslice, imgmax, imgthrs, imgunit, img2flat",
68 "Keywords: image, sinogram, TIFF",
87int main(
int argc,
char **argv)
89 int ai, help=0, version=0, verbose=1;
90 int pi, ret, fixedScale=0, trLog10=0;
91 int frame=-1, plane=-1;
93 char ecatfile[FILENAME_MAX], tiffile[FILENAME_MAX], *cptr=NULL;
103 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
104 ecatfile[0]=tiffile[0]=(char)0;
107 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
108 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(cptr==NULL)
continue;
111 if(strncasecmp(cptr,
"P=", 2)==0 && strlen(cptr)>2) {
112 plane=atoi(cptr+2);
if(plane>0)
continue;
113 }
else if(strncasecmp(cptr,
"F=", 2)==0 && strlen(cptr)>2) {
114 frame=atoi(cptr+2)-1;
if(frame>=0)
continue;
115 }
else if(strcasecmp(cptr,
"RBW")==0) {
117 }
else if(strncasecmp(cptr,
"R", 1)==0) {
119 }
else if(strncasecmp(cptr,
"GR", 2)==0) {
121 }
else if(strncasecmp(cptr,
"GI", 2)==0) {
123 }
else if(strcasecmp(cptr,
"S")==0) {
124 fixedScale=1;
continue;
125 }
else if(strncasecmp(cptr,
"S=", 2)==0) {
126 fixedScale=1; imgmax=
atof_dpi(cptr+2);
if(imgmax>0.0)
continue;
127 }
else if(strcasecmp(cptr,
"L")==0) {
129 }
else if(strcasecmp(cptr,
"L1")==0) {
131 }
else if(strncasecmp(cptr,
"TH=", 3)==0 && strlen(cptr)>3) {
132 tileX=atoi(cptr+3);
if(tileX>0)
continue;
133 }
else if(strncasecmp(cptr,
"TV=", 3)==0 && strlen(cptr)>3) {
134 tileY=atoi(cptr+3);
if(tileY>0)
continue;
136 fprintf(stderr,
"Error: invalid option '%s'\n", argv[ai]);
141 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
146 for(; ai<argc; ai++) {
148 strcpy(ecatfile, argv[ai]);
continue;
149 }
else if(!tiffile[0]) {
150 strcpy(tiffile, argv[ai]);
continue;
152 fprintf(stderr,
"Error: invalid argument '%s'\n", argv[ai]);
157 if(!ecatfile[0]) {
tpcPrintUsage(argv[0], info, stdout);
return(1);}
161 strcpy(tiffile, ecatfile);
162 cptr=strrchr(tiffile,
'.');
if(cptr!=NULL) *cptr=(char)0;
163 strcat(tiffile,
".tif");
165 if(strcasecmp(ecatfile, tiffile)==0) {
166 fprintf(stderr,
"Error: same name for input and output file.\n");
173 for(ai=0; ai<argc; ai++)
174 printf(
"%s ", argv[ai]);
176 printf(
"ecatfile := %s\n", ecatfile);
177 printf(
"tiffile := %s\n", tiffile);
178 printf(
"plane := %d\nframe := %d\nfixedScale := %d\nimgmax := %g\n",
179 plane, 1+frame, fixedScale, imgmax);
180 printf(
"Log10 transformation := %d\n", trLog10);
181 if(tileX>0) printf(
"tileX := %d\n", tileX);
182 if(tileY>0) printf(
"tileY := %d\n", tileY);
189 if(verbose>1) fprintf(stdout,
"reading %s\n", ecatfile);
192 fprintf(stderr,
"Error: %s\n", img.
statmsg);
193 if(verbose>1) printf(
"ret := %d\n", ret);
198 if(verbose>0) fprintf(stderr,
"Warning: missing pixel values.\n");
205 if(frame>=0 && img.
dimt<(frame+1)) {
206 fprintf(stderr,
"Error: file does not contain frame %d\n", frame+1);
210 for(pi=0; pi<img.
dimz; pi++)
213 fprintf(stderr,
"Error: file does not contain plane %d\n", plane);
217 printf(
"Required plane was on index %d in the datafile.\n", plane);
225 if(verbose>0) fprintf(stdout,
"computing logarithms.\n");
226 if(trLog10>1) ret=
imgArithmConst(&img, 1.0,
'+', -1.0, verbose-3);
235 if(fixedScale && imgmax<=0.0) {
236 ret=
imgMax(&img, &imgmax);
237 if(verbose>0) fprintf(stdout,
"maximum pixel value in %s is %g, unit %s\n",
245 if(fixedScale==0) imgmax=-1.0;
246 ret=
tiffWriteImg(&img, plane, frame, &imgmax, colorscale, tiffile,
247 tileX, tileY, verbose-2, tmp);
249 fprintf(stderr,
"Error (%d) in writing %s: %s.\n", ret, tiffile, tmp);
255 fprintf(stdout,
"maximum pixel value in matrix is %g, unit %s\n",
257 if(verbose>1) printf(
"img.unit := %d\n", img.
unit);
258 }
else if(verbose>1) printf(
"imgmax := %g\n", imgmax);
259 if(verbose>0) printf(
"%s written.\n", tiffile);
double atof_dpi(char *str)
unsigned long long imgNaNs(IMG *img, int fix)
void imgEmpty(IMG *image)
int imgArithmConst(IMG *img, float operand, char operation, float ulimit, int verbose)
int imgRead(const char *fname, IMG *img)
int imgMax(IMG *img, float *maxvalue)
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 libtpcimgio.
Header file for libtpcimgp.
#define PET_GRAYSCALE_INV
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)