TPCCLIB
Loading...
Searching...
No Matches
nii2ecat.c File Reference

Convert NIfTI-1 PET image to ECAT 7 format. More...

Go to the source code of this file.

Functions

int imgNiftiToEcat (char *dbname, char *ecatfile, int scanner_type, float zoom, int verbose)

Detailed Description

Convert NIfTI-1 PET image to ECAT 7 format.

Author
Vesa Oikonen

Definition in file nii2ecat.c.

Function Documentation

◆ imgNiftiToEcat()

int imgNiftiToEcat ( char * dbname,
char * ecatfile,
int scanner_type,
float zoom,
int verbose )

Read NIfTI-1 image database and write ECAT7 image frame-by-frame

Returns
Returns errstatus, which is STATUS_OK (0) when call was successful, and >0 in case of an error.
Parameters
dbnameNIfTI database name
ecatfileECAT image filename, output extension must be .v
scanner_typeScanner type, 0 if not set
zoomrecon_zoom, 0.0 or 1.0, if not known
verboseVerbose level; if zero, then nothing is printed to stderr or stdout

Definition at line 305 of file nii2ecat.c.

316 {
317 IMG img;
318 int zi, fi, ret, file_format=0;
319
320 if(verbose>0) printf("\nimgNiftiToEcat(%s, %s)\n", dbname, ecatfile);
321 /* Check the arguments */
322 if(dbname==NULL || ecatfile==NULL) return STATUS_FAULT;
323
324 /* Read the first frame */
325 imgInit(&img); fi=0;
326 if(verbose>1) printf(" reading the first frame\n");
327 ret=imgReadNiftiFirstFrame(dbname, &img, verbose-1);
328 if(ret!=STATUS_OK) {imgEmpty(&img); return ret;}
329 /* ... and then the rest of the frames */
330 do {
331 fi++;
332 if(verbose>1) printf(" frame %d\n", fi);
333 /* Set header information */
334 if(fi==0) // must be saved for reading next frame
335 file_format=img._fileFormat;
336 if(scanner_type>0) imgSetScanner(&img, scanner_type);
337 if(zoom>0.0) img.zoom=zoom;
338 for(zi=0; zi<img.dimz; zi++) img.planeNumber[zi]=zi+1;
339 if(verbose>15) imgInfo(&img);
340 /* Write the frame in ECAT 7 format */
342 ret=imgWriteFrame(ecatfile, fi, &img, 0); //printf("ret := %d\n", ret);
343 if(ret!=STATUS_OK) break;
344 if(verbose>1) printf(" frame written.\n");
345 /* Try to read the next frame */
346 img._fileFormat=file_format;
347 ret=imgReadNiftiFrame(dbname, fi+1, &img, 0, verbose-1);
348 } while(ret==0);
349 imgEmpty(&img);
350 if(verbose>0 && ret==STATUS_NOMATRIX) {
351 fprintf(stdout, " %d frame(s) processed.\n", fi);
352 }
353 if(ret!=STATUS_OK && ret!=STATUS_NOMATRIX) {
354 remove(ecatfile); return ret;
355 }
356 /*if(verbose>2)
357 fprintf(stdout, " Image saved in ECAT format in %s\n", ecatfile);*/
358 return STATUS_OK;
359}
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 imgReadNiftiFirstFrame(const char *filename, IMG *img, int verbose)
Definition img_nii.c:78
int imgReadNiftiFrame(const char *filename, int frame_to_read, IMG *img, int frame_index, int verbose)
Definition img_nii.c:311
int imgWriteFrame(const char *fname, int frame_to_write, IMG *img, int frame_index)
Definition imgfile.c:392
int imgSetScanner(IMG *img, int scanner_type)
Definition imgscanner.c:14
#define IMG_E7
int _fileFormat
int * planeNumber
unsigned short int dimz
float zoom