TPCCLIB
Loading...
Searching...
No Matches
imgswell.c
Go to the documentation of this file.
1
7/*****************************************************************************/
8#include "tpcclibConfig.h"
9/*****************************************************************************/
10#include <stdio.h>
11#include <stdlib.h>
12#include <math.h>
13#include <string.h>
14#include <math.h>
15#include <time.h>
16/*****************************************************************************/
17#include "libtpcmisc.h"
18#include "libtpcimgio.h"
19#include "libtpcimgp.h"
20/*****************************************************************************/
21
22/*****************************************************************************/
23static char *info[] = {
24 "Inflate the dimensions of PET image by making 8 voxels of each original",
25 "pixel. ECAT 6.3, 7.x, and Analyze 7.5 and NIfTI-1 formats are accepted.",
26 " ",
27 "Usage: @P [Options] image bigimage",
28 " ",
29 "Options:",
30 " -z=<yes|no>",
31 " Image is inflated in z dimension or not inflated. By default, 3D",
32 " is inflated in all dimensions, but 2D image only in x,y dimensions.",
33 " -stdoptions", // List standard options like --help, -v, etc
34 " ",
35 "Example:",
36 " @P i5998dy1.v i5998dy1_swollen.v",
37 " ",
38 "See also: imgshrink, imgdim, imgbox, imgfiltg, imgmask",
39 " ",
40 "Keywords: image, simulation, tool, software testing",
41 0};
42/*****************************************************************************/
43
44/*****************************************************************************/
45/* Turn on the globbing of the command line, since it is disabled by default in
46 mingw-w64 (_dowildcard=0); in MinGW32 define _CRT_glob instead, if necessary;
47 In Unix&Linux wildcard command line processing is enabled by default. */
48/*
49#undef _CRT_glob
50#define _CRT_glob -1
51*/
52int _dowildcard = -1;
53/*****************************************************************************/
54
55/*****************************************************************************/
59int main(int argc, char **argv)
60{
61 int ai, help=0, version=0, verbose=1;
62 char petfile[FILENAME_MAX], outfile[FILENAME_MAX];
63 int inflate_planes=-1;
64 char *cptr;
65 int ret;
66
67
68 /*
69 * Get arguments
70 */
71 if(argc==1) {tpcPrintUsage(argv[0], info, stderr); return(1);}
72 petfile[0]=outfile[0]=(char)0;
73 /* Get options */
74 for(ai=1; ai<argc; ai++) if(*argv[ai]=='-') {
75 if(tpcProcessStdOptions(argv[ai], &help, &version, &verbose)==0) continue;
76 cptr=argv[ai]+1; if(*cptr=='-') cptr++; if(cptr==NULL) continue;
77 if(strncasecmp(cptr, "Z=", 2)==0) {
78 cptr+=2;
79 if(strncasecmp(cptr, "YES", 1)==0) {inflate_planes=1; continue;}
80 if(strncasecmp(cptr, "NO", 1)==0) {inflate_planes=0; continue;}
81 }
82 fprintf(stderr, "Error: invalid option '%s'.\n", argv[ai]);
83 return(1);
84 } else break;
85
86 /* Print help or version? */
87 if(help==2) {tpcHtmlUsage(argv[0], info, ""); return(0);}
88 if(help) {tpcPrintUsage(argv[0], info, stdout); return(0);}
89 if(version) {tpcPrintBuild(argv[0], stdout); return(0);}
90
91 /* Process other arguments, starting from the first non-option */
92 if(ai<argc) {strlcpy(petfile, argv[ai++], FILENAME_MAX);}
93 if(ai<argc) {strlcpy(outfile, argv[ai++], FILENAME_MAX);}
94 if(ai<argc) {
95 fprintf(stderr, "Error: invalid argument '%s'.\n", argv[ai]);
96 return(1);
97 }
98
99 /* Did we get all the information that we need? */
100 if(!outfile[0]) {
101 fprintf(stderr, "Error: missing command-line argument; use option --help\n");
102 return(1);
103 }
104
105 /* In verbose mode print arguments and options */
106 if(verbose>1) {
107 printf("petfile := %s\n", petfile);
108 printf("outfile := %s\n", outfile);
109 if(inflate_planes>=0) printf("inflate_planes := %d\n", inflate_planes);
110 }
111 if(verbose>9) IMG_TEST=verbose-10; else IMG_TEST=0;
112
113
114 /*
115 * Read image
116 */
117 if(verbose>0) fprintf(stdout, "reading image %s\n", petfile);
118 IMG img; imgInit(&img);
119 ret=imgRead(petfile, &img);
120 if(ret) {
121 fprintf(stderr, "Error: %s\n", img.statmsg); if(verbose>1) imgInfo(&img);
122 return(2);
123 }
124 if(verbose>1) {
125 printf("image dimensions: %d %d %d\n", img.dimz, img.dimy, img.dimx);
126 printf("image frame nr: %d\n", img.dimt);
127 }
128 /* Check if PET data is raw or image */
129 if(img.type!=IMG_TYPE_IMAGE) {
130 fprintf(stderr, "Error: %s is not an image.\n", petfile);
131 imgEmpty(&img); return(2);
132 }
133 /* Decide whether to inflate in z dimension, if user did not tell what to do */
134 if(inflate_planes<0) {
135 if(img.dimz==1) inflate_planes=0; else inflate_planes=1;
136 if(verbose>1) printf("inflate_planes := %d\n", inflate_planes);
137 }
138
139 /*
140 * Inflate the image
141 */
142 if(verbose>0) fprintf(stdout, "inflating...\n");
143 IMG out; imgInit(&out);
144 ret=imgSwell(&img, &out, inflate_planes);
145 if(ret) {
146 fprintf(stderr, "Error: cannot inflate image.\n");
147 if(verbose>1) printf("ret=%d\n", ret);
148 imgEmpty(&img); imgEmpty(&out); return(3);
149 }
150
151 /* Free memory allocated for original image */
152 imgEmpty(&img);
153
154
155 /*
156 * Save the swollen image
157 */
158 if(verbose>1) fprintf(stdout, "writing swollen image in %s\n", outfile);
159 ret=imgWrite(outfile, &out);
160 if(ret) {
161 fprintf(stderr, "Error: %s\n", out.statmsg);
162 imgEmpty(&out); return(11);
163 }
164 if(verbose>0) fprintf(stdout, "Inflated image was written in %s\n", outfile);
165
166 /* Free memory allocated for output image */
167 imgEmpty(&out);
168
169 return(0);
170}
171/*****************************************************************************/
172
173/*****************************************************************************/
int IMG_TEST
Definition img.c:6
void imgInfo(IMG *image)
Definition img.c:359
void imgEmpty(IMG *image)
Definition img.c:121
void imgInit(IMG *image)
Definition img.c:60
int imgRead(const char *fname, IMG *img)
Definition imgfile.c:26
int imgWrite(const char *fname, IMG *img)
Definition imgfile.c:136
int imgSwell(IMG *img1, IMG *img2, int doz)
Header file for libtpcimgio.
#define IMG_TYPE_IMAGE
Header file for libtpcimgp.
Header file for libtpcmisc.
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
Definition proginfo.c:40
size_t strlcpy(char *dst, const char *src, size_t dstsize)
Definition strext.c:245
int tpcHtmlUsage(const char *program, char *text[], const char *path)
Definition proginfo.c:213
void tpcPrintBuild(const char *program, FILE *fp)
Definition proginfo.c:383
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
Definition proginfo.c:158
unsigned short int dimx
char type
unsigned short int dimt
unsigned short int dimz
unsigned short int dimy
const char * statmsg