8#include "tpcclibConfig.h"
23static char *info[] = {
24 "Flip PET image in X, Y, and/or Z direction(s).",
25 "By default, if no options are given, flipping in X and Y directions.",
27 "Usage: @P [Options] imagefile outputfile",
31 " Flip image in X direction (horizontally).",
33 " Flip image in Y direction (vertically).",
35 " Flip image in Z direction (image planes/slices).",
37 " Flip image to view it from above or right side.",
40 "See also: esplit, img2cube, imgbox, imgslice, img2tif, ecat2ana",
42 "Keywords: image, tool, software testing",
61int main(
int argc,
char **argv)
63 int ai, help=0, version=0, verbose=1;
65 int flip_vertical=0, flip_horizontal=0, flip_planes=0;
66 int flip_right=0, flip_up=0;
67 char imgfile[FILENAME_MAX], resfile[FILENAME_MAX],
68 *cptr, tmp[FILENAME_MAX];
75 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
76 imgfile[0]=resfile[0]=(char)0;
79 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
80 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(cptr==NULL)
continue;
82 if(strcasecmp(cptr,
"X")==0) {
83 flip_horizontal=1;
continue;
84 }
else if(strcasecmp(cptr,
"Y")==0) {
85 flip_vertical=1;
continue;
86 }
else if(strcasecmp(cptr,
"Z")==0) {
87 flip_planes=1;
continue;
88 }
else if(strspn(cptr,
"XYZxyz")==strlen(cptr)) {
89 if(strpbrk(
"Xx", cptr)!=NULL) flip_horizontal=1;
90 if(strpbrk(
"Yy", cptr)!=NULL) flip_vertical=1;
91 if(strpbrk(
"Zz", cptr)!=NULL) flip_planes=1;
93 }
else if(strcasecmp(cptr,
"RIGHT")==0 || strcasecmp(cptr,
"RIGTH")==0) {
94 flip_right=1;
continue;
95 }
else if(strcasecmp(cptr,
"UP")==0) {
98 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
103 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
108 for(; ai<argc; ai++) {
110 strcpy(imgfile, argv[ai]);
continue;
111 }
else if(!resfile[0]) {
112 strcpy(resfile, argv[ai]);
continue;
115 fprintf(stderr,
"Error: invalid argument '%s'.\n", argv[ai]);
121 fprintf(stderr,
"Error: missing command-line argument; use option --help\n");
124 if(flip_horizontal==0 && flip_vertical==0 && flip_planes==0
125 && flip_up==0 && flip_right==0)
128 fprintf(stderr,
"Warning: no flipping was requested; assuming X and Y.\n");
129 flip_vertical=flip_horizontal=1;
131 if(flip_right && flip_up) {
132 fprintf(stderr,
"Error: do not use options -right and -up together.\n");
138 printf(
"imgfile := %s\n", imgfile);
139 printf(
"resfile := %s\n", resfile);
140 printf(
"flip_x := %d\n", flip_horizontal);
141 printf(
"flip_y := %d\n", flip_vertical);
142 printf(
"flip_z := %d\n", flip_planes);
143 printf(
"flip_right := %d\n", flip_right);
144 printf(
"flip_up := %d\n", flip_up);
152 if(verbose>1) fprintf(stdout,
"reading %s\n", imgfile);
155 fprintf(stderr,
"Error: %s\n", img.
statmsg);
if(verbose>1)
imgInfo(&img);
159 if(flip_planes || flip_right || flip_up) {
160 for(zi=1; zi<img.
dimz; zi++)
162 fprintf(stderr,
"Error: plane numbers are not continuous.\n");
167 if(flip_right || flip_up) {
169 fprintf(stderr,
"Error: image has only one plane.\n");
173 fprintf(stderr,
"Error: image has only one column.\n");
177 fprintf(stderr,
"Error: image has only one row.\n");
184 fprintf(stderr,
"Error: %s\n", tmp);
192 if(verbose>1) printf(
"flipping the image...\n");
194 if(flip_horizontal) {
195 if(verbose>0) fprintf(stdout,
"horizontal flipping\n");
200 if(verbose>0) fprintf(stdout,
"vertical flipping\n");
206 if(verbose>0) fprintf(stdout,
"flipping planes\n");
217 if(verbose>0) fprintf(stdout,
"flipping from right\n");
221 if(verbose>0) fprintf(stdout,
"flipping from above\n");
226 fprintf(stderr,
"Error: cannot flip the image.\n");
234 if(verbose>1) fprintf(stdout,
"writing %s\n", resfile);
237 fprintf(stderr,
"Error: %s\n", img.
statmsg);
if(verbose>2)
imgInfo(&img);
241 if(verbose>0) fprintf(stdout,
"done.\n");
int backupExistingFile(char *filename, char *backup_ext, char *status)
void imgEmpty(IMG *image)
int imgRead(const char *fname, IMG *img)
int imgWrite(const char *fname, IMG *img)
void imgFlipVertical(IMG *img)
void imgFlipHorizontal(IMG *img)
int imgFlipRight(IMG *img)
void imgFlipPlanes(IMG *img)
int imgFlipAbove(IMG *img)
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)