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 312 of file nii2ecat.c.

323 {
324 IMG img;
325 int zi, fi, ret, file_format=0;
326
327 if(verbose>0) printf("\nimgNiftiToEcat(%s, %s)\n", dbname, ecatfile);
328 /* Check the arguments */
329 if(dbname==NULL || ecatfile==NULL) return STATUS_FAULT;
330
331 /* Read the first frame */
332 imgInit(&img); fi=0;
333 if(verbose>1) printf(" reading the first frame\n");
334 ret=imgReadNiftiFirstFrame(dbname, &img, verbose-1);
335 if(ret!=STATUS_OK) {imgEmpty(&img); return ret;}
336 /* ... and then the rest of the frames */
337 do {
338 fi++;
339 if(verbose>1) printf(" frame %d\n", fi);
340 /* Set header information */
341 if(fi==0) // must be saved for reading next frame
342 file_format=img._fileFormat;
343 if(scanner_type>0) imgSetScanner(&img, scanner_type);
344 if(zoom>0.0) img.zoom=zoom;
345 for(zi=0; zi<img.dimz; zi++) img.planeNumber[zi]=zi+1;
346 if(verbose>15) imgInfo(&img);
347 /* Write the frame in ECAT 7 format */
349 ret=imgWriteFrame(ecatfile, fi, &img, 0); //printf("ret := %d\n", ret);
350 if(ret!=STATUS_OK) break;
351 if(verbose>1) printf(" frame written.\n");
352 /* Try to read the next frame */
353 img._fileFormat=file_format;
354 ret=imgReadNiftiFrame(dbname, fi+1, &img, 0, verbose-1);
355 } while(ret==0);
356 imgEmpty(&img);
357 if(verbose>0 && ret==STATUS_NOMATRIX) {
358 fprintf(stdout, " %d frame(s) processed.\n", fi);
359 }
360 if(ret!=STATUS_OK && ret!=STATUS_NOMATRIX) {
361 remove(ecatfile); return ret;
362 }
363 /*if(verbose>2)
364 fprintf(stdout, " Image saved in ECAT format in %s\n", ecatfile);*/
365 return STATUS_OK;
366}
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

Referenced by imgNiftiToEcat().