TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
imginform
imgdim.c
Go to the documentation of this file.
1
8
/*****************************************************************************/
9
#include "tpcclibConfig.h"
10
/*****************************************************************************/
11
#include <stdio.h>
12
#include <stdlib.h>
13
#include <math.h>
14
#include <string.h>
15
#include <unistd.h>
16
#include <time.h>
17
/*****************************************************************************/
18
#include "
libtpcmisc.h
"
19
#include "
libtpcimgio.h
"
20
#include "
libtpcimgp.h
"
21
/*****************************************************************************/
22
23
/*****************************************************************************/
24
static
char
*info[] = {
25
"Report the image dimensions."
,
26
" "
,
27
"Usage: @P [Options] imgfile"
,
28
" "
,
29
"Image file can be in ECAT 6.3 or 7.x, NIfTI-1, or Analyze 7.5 format."
,
30
" "
,
31
"Options:"
,
32
" -x | -y | -z | -t"
,
33
" Report only the width (x), height (y), planes (z), or time frames (t);"
,
34
" by default all are printed in stdout."
,
35
" -size"
,
36
" Instead of image dimension, report the pixel size(s) in mm."
,
37
" -stdoptions"
,
// List standard options like --help, -v, etc
38
" "
,
39
"Example: print dimensions of all ECAT 7 images in Windows command shell"
,
40
" for %f in (*.v) do @P %f"
,
41
" "
,
42
"Example: print dimensions of all ECAT 7 images in Linux/OSX command shell"
,
43
" for file in ./*.v; do @P $file; done"
,
44
" "
,
45
"See also: imgdelfr, imgdelpl, lmlist, imgbox, imgshrink, imgadd"
,
46
" "
,
47
"Keywords: image, pixel, header, cropping, tool"
,
48
0};
49
/*****************************************************************************/
50
51
/*****************************************************************************/
52
/* Turn on the globbing of the command line, since it is disabled by default in
53
mingw-w64 (_dowildcard=0); in MinGW32 define _CRT_glob instead, if necessary;
54
In Unix&Linux wildcard command line processing is enabled by default. */
55
/*
56
#undef _CRT_glob
57
#define _CRT_glob -1
58
*/
59
int
_dowildcard = -1;
60
/*****************************************************************************/
61
62
/*****************************************************************************/
66
int
main(
int
argc,
char
**argv)
67
{
68
int
ai, help=0, version=0, verbose=1;
69
char
imgfile[FILENAME_MAX];
70
char
dim=(char)0;
71
int
item=0;
// 0=dim; 1=pxlsize
72
73
/*
74
* Get arguments
75
*/
76
if
(argc==1) {
tpcPrintUsage
(argv[0], info, stderr);
return
(1);}
77
imgfile[0]=(char)0;
78
/* Options */
79
for
(ai=1; ai<argc; ai++)
if
(*argv[ai]==
'-'
) {
/* options */
80
if
(
tpcProcessStdOptions
(argv[ai], &help, &version, &verbose)==0)
continue
;
81
char
*cptr=argv[ai]+1;
if
(*cptr==
'-'
) cptr++;
if
(cptr==NULL)
continue
;
82
if
(!strcasecmp(cptr,
"X"
)) {dim=
'x'
;
continue
;}
83
if
(!strcasecmp(cptr,
"Y"
)) {dim=
'y'
;
continue
;}
84
if
(!strcasecmp(cptr,
"Z"
)) {dim=
'z'
;
continue
;}
85
if
(!strcasecmp(cptr,
"T"
)) {dim=
't'
;
continue
;}
86
if
(!strcasecmp(cptr,
"P"
)) {dim=
'z'
;
continue
;}
87
if
(!strcasecmp(cptr,
"F"
)) {dim=
't'
;
continue
;}
88
if
(!strcasecmp(cptr,
"SIZE"
)) {item=1;
continue
;}
89
fprintf(stderr,
"Error: invalid option '%s'.\n"
, argv[ai]);
90
return
(1);
91
}
else
break
;
92
93
/* Print help or version? */
94
if
(help==2) {
tpcHtmlUsage
(argv[0], info,
""
);
return
(0);}
95
if
(help) {
tpcPrintUsage
(argv[0], info, stdout);
return
(0);}
96
if
(version) {
tpcPrintBuild
(argv[0], stdout);
return
(0);}
97
98
/* Process other arguments, starting from the first non-option */
99
if
(ai<argc) {
strlcpy
(imgfile, argv[ai], FILENAME_MAX); ai++;}
100
if
(ai<argc) {fprintf(stderr,
"Error: too many arguments.\n"
);
return
(1);}
101
102
/* Did we get all the information that we need? */
103
if
(!imgfile[0]) {
104
fprintf(stderr,
"Error: missing command-line argument; use option --help\n"
);
105
return
(1);
106
}
107
108
109
/* In verbose mode print options */
110
if
(verbose>1) {
111
printf(
"imgfile := %s\n"
, imgfile);
112
if
(dim) printf(
"dim := %c\n"
, dim);
113
if
(item) printf(
"item := %d\n"
, item);
114
}
115
116
117
/*
118
* Read PET image
119
*/
120
if
(verbose>2) printf(
"reading %s\n"
, imgfile);
121
IMG
img;
imgInit
(&img);
122
if
(
imgRead
(imgfile, &img)) {fprintf(stderr,
"Error: %s\n"
, img.
statmsg
);
return
(2);}
123
124
/*
125
* Print the requested item(s)
126
*/
127
if
(item==0) {
128
/* Print the dimension(s) */
129
if
(dim==
'x'
) fprintf(stdout,
"%d\n"
, img.
dimx
);
130
else
if
(dim==
'y'
) fprintf(stdout,
"%d\n"
, img.
dimy
);
131
else
if
(dim==
'z'
) fprintf(stdout,
"%d\n"
, img.
dimz
);
132
else
if
(dim==
't'
) fprintf(stdout,
"%d\n"
, img.
dimt
);
133
else
fprintf(stdout,
"%d %d %d %d\n"
, img.
dimx
, img.
dimy
, img.
dimz
, img.
dimt
);
134
}
else
{
135
/* Print the pixel size(s) */
136
if
(dim==
'x'
) fprintf(stdout,
"%g\n"
, img.
sizex
);
137
else
if
(dim==
'y'
) fprintf(stdout,
"%g\n"
, img.
sizey
);
138
else
if
(dim==
'z'
) fprintf(stdout,
"%g\n"
, img.
sizez
);
139
else
fprintf(stdout,
"%g %g %g\n"
, img.
sizex
, img.
sizey
, img.
sizez
);
140
}
141
142
imgEmpty
(&img);
143
144
return
(0);
145
}
146
/*****************************************************************************/
147
148
/*****************************************************************************/
imgEmpty
void imgEmpty(IMG *image)
Definition
img.c:121
imgInit
void imgInit(IMG *image)
Definition
img.c:60
imgRead
int imgRead(const char *fname, IMG *img)
Definition
imgfile.c:26
libtpcimgio.h
Header file for libtpcimgio.
libtpcimgp.h
Header file for libtpcimgp.
libtpcmisc.h
Header file for libtpcmisc.
tpcProcessStdOptions
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
Definition
proginfo.c:40
strlcpy
size_t strlcpy(char *dst, const char *src, size_t dstsize)
Definition
strext.c:244
tpcHtmlUsage
int tpcHtmlUsage(const char *program, char *text[], const char *path)
Definition
proginfo.c:213
tpcPrintBuild
void tpcPrintBuild(const char *program, FILE *fp)
Definition
proginfo.c:383
tpcPrintUsage
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
Definition
proginfo.c:158
IMG
Definition
libtpcimgio.h:1657
IMG::sizex
float sizex
Definition
libtpcimgio.h:1714
IMG::dimx
unsigned short int dimx
Definition
libtpcimgio.h:1780
IMG::dimt
unsigned short int dimt
Definition
libtpcimgio.h:1778
IMG::sizey
float sizey
Definition
libtpcimgio.h:1716
IMG::dimz
unsigned short int dimz
Definition
libtpcimgio.h:1784
IMG::dimy
unsigned short int dimy
Definition
libtpcimgio.h:1782
IMG::statmsg
const char * statmsg
Definition
libtpcimgio.h:1667
IMG::sizez
float sizez
Definition
libtpcimgio.h:1718
Generated on
for TPCCLIB by
1.17.0