TPCCLIB
Loading...
Searching...
No Matches
img2scn.c
Go to the documentation of this file.
1
9/*****************************************************************************/
10#include "tpcclibConfig.h"
11/*****************************************************************************/
12#include <stdio.h>
13#include <stdlib.h>
14#include <math.h>
15#include <string.h>
16#include <unistd.h>
17#include <ctype.h>
18#include <dirent.h>
19#include <sys/stat.h>
20#include <time.h>
21/*****************************************************************************/
22#include "libtpcmisc.h"
23#include "libtpcimgio.h"
24#include "libtpcrec.h"
25/*****************************************************************************/
26
27/*****************************************************************************/
28static char *info[] = {
29 "Make 2D sinogram from PET image in CTI ECAT 931 format for program testing",
30 "and simulations.",
31 "Image plane number is used to guess the scanner and to set sinogram size.",
32 "This program cannot remove calibrations, or normalization, attenuation,",
33 "or dead-time correction. Decay correction is not removed.",
34 " ",
35 "Usage: @P [Options] imgfile scnfile",
36 " ",
37 "Options:",
38//" -dtc=<Y|n>",
39//" Dead-time correction is done (y, default), or not done (n).",
40 " -stdoptions", // List standard options like --help, -v, etc
41 " ",
42 "Example:",
43 " @P a2345dy1.img a2345dy1.scn",
44 " ",
45 "See also: ecatfbp, ecatmrp, eframe, edecay, ecalibr, flat2img, dft2img",
46 " ",
47 "Keywords: ECAT, sinogram, reconstruction, software testing",
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*/
59int _dowildcard = -1;
60/*****************************************************************************/
61
62/*****************************************************************************/
66int main(int argc, char **argv)
67{
68 int ai, help=0, version=0, verbose=1;
69 char imgfile[FILENAME_MAX], scnfile[FILENAME_MAX];
70 char *cptr;
71 int ret;
72
73
74
75 /*
76 * Get arguments
77 */
78 if(argc==1) {tpcPrintUsage(argv[0], info, stderr); return(1);}
79 imgfile[0]=scnfile[0]=(char)0;
80 /* Options */
81 for(ai=1; ai<argc; ai++) if(*argv[ai]=='-') { /* options */
82 cptr=argv[ai]+1; if(*cptr=='-') cptr++; if(cptr==NULL) continue;
83 if(tpcProcessStdOptions(argv[ai], &help, &version, &verbose)==0) continue;
84 fprintf(stderr, "Error: invalid option '%s'.\n", argv[ai]);
85 return(1);
86 } else break;
87
88 /* Print help or version? */
89 if(help==2) {tpcHtmlUsage(argv[0], info, ""); return(0);}
90 if(help) {tpcPrintUsage(argv[0], info, stdout); return(0);}
91 if(version) {tpcPrintBuild(argv[0], stdout); return(0);}
92
93 /* Process other arguments, starting from the first non-option */
94 if(ai<argc) {strlcpy(imgfile, argv[ai++], FILENAME_MAX);}
95 if(ai<argc) {strlcpy(scnfile, argv[ai++], FILENAME_MAX);}
96 if(ai<argc) {
97 fprintf(stderr, "Error: too many arguments.\n");
98 return(1);
99 }
100
101 /* Is something missing? */
102 if(!scnfile[0]) {
103 fprintf(stderr, "Error: missing command-line argument; use --help\n");
104 return(1);
105 }
106
107 /* In verbose mode print arguments and options */
108 if(verbose>1) {
109 printf("imgfile := %s\n", imgfile);
110 printf("scnfile := %s\n", scnfile);
111 }
112
113 /* Check that input and output files do not have the same filename */
114 if(strcasecmp(imgfile, scnfile)==0) {
115 fprintf(stderr, "Error: original image must not be overwritten.\n");
116 return(1);
117 }
118
119
120 /*
121 * Read PET image
122 */
123 if(verbose>0) printf("reading image %s\n", imgfile);
124 IMG img; imgInit(&img);
125 ret=imgRead(imgfile, &img);
126 if(ret) {
127 fprintf(stderr, "Error: %s\n", img.statmsg);
128 if(verbose>1) printf("ret := %d\n", ret);
129 return(2);
130 }
131 if(verbose>1) {
132 printf("dimx := %d\n", img.dimx);
133 printf("dimy := %d\n", img.dimy);
134 printf("dimz := %d\n", img.dimz);
135 printf("dimt := %d\n", img.dimt);
136 }
137
138 /*
139 * Reprojection
140 */
141 if(verbose>0) printf("reprojecting...\n");
142 IMG scn; imgInit(&scn);
143 ret=imgReprojection(&img, &scn, verbose-2);
144 if(ret) {
145 fprintf(stderr, "Error: cannot do reprojection.\n");
146 if(verbose>1) printf("ret := %d\n", ret);
147 imgEmpty(&scn); imgEmpty(&img);
148 return(3);
149 }
150
151 /* Save the sinogram */
152 if(verbose>0) printf("writing sinogram %s\n", scnfile);
153 if(imgWrite(scnfile, &scn)) {
154 fprintf(stderr, "Error: %s\n", scn.statmsg);
155 imgEmpty(&img); imgEmpty(&scn);
156 return(11);
157 }
158
159 imgEmpty(&img); imgEmpty(&scn);
160 if(verbose>0) fprintf(stdout, "done.\n");
161
162 return(0);
163}
164/*****************************************************************************/
165
166/*****************************************************************************/
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
Header file for libtpcimgio.
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
Header file for libtpcrec.
int imgReprojection(IMG *img, IMG *scn, int verbose)
unsigned short int dimx
unsigned short int dimt
unsigned short int dimz
unsigned short int dimy
const char * statmsg