Functions
imgfile.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include "petc99.h"
#include "swap.h"
#include "halflife.h"
#include "substitutions.h"
#include "include/img.h"
#include "include/ecat63.h"
#include "include/ecat7.h"
#include "include/analyze.h"
#include "include/imgmax.h"
#include "include/imgdecay.h"
#include "include/sif.h"
#include "include/imgfile.h"
Include dependency graph for imgfile.c:

Go to the source code of this file.

Functions

int imgRead (const char *fname, IMG *img)
 
int imgWrite (const char *fname, IMG *img)
 
int imgReadHeader (const char *fname, IMG *img)
 
int imgReadFrame (const char *fname, int frame_to_read, IMG *img, int frame_index)
 
int imgWriteFrame (const char *fname, int frame_to_write, IMG *img, int frame_index)
 
void imgFormatFromFName (IMG *img, const char *fname)
 

Function Documentation

void imgFormatFromFName ( IMG img,
const char *  fname 
)

Determine IMG _fileFormat from filename extension, if not already defined. Default if ECAT 7 image volume, if nothing else can be guessed.

Parameters
imgtarget image struture where fileformat is saved, should have IMG_UNKNOWN as file type
fnamename of file that is detemined

Definition at line 547 of file imgfile.c.

References IMG::_fileFormat, IMG_ANA, IMG_E63, IMG_E7, IMG_POLARMAP, and IMG_UNKNOWN.

Referenced by imgWrite(), imgWriteFrame(), and test_modules().

int imgRead ( const char *  fname,
IMG img 
)

Read an image or sinogram file in ECAT 6.3, ECAT 7.x or Analyze 7.5 format.

Parameters
fnameinput filename
imgpointer to initialized IMG structure
Returns
0 if ok, 1 invalid input, 2 image status is not 'initialized', 4 unrecognized format, 5 unsupported Ecat7 type, sets IMG->statmsg in case of error

Definition at line 190 of file imgfile.c.

References anaExists(), ecat63errmsg, ecat63ReadAllToImg(), ecat63ReadMainheader(), ecat7filetype(), ecat7ReadMainheader(), ECAT7V_MAGICNR, ecat63_mainheader::file_type, ecat7_mainheader::file_type, IMG_STATUS_INITIALIZED, IMG_TEST, imgEcat7Supported(), imgReadAnalyze(), imgReadEcat7(), imgStatus(), ecat7_mainheader::magic_number, IMG::statmsg, IMG::status, STATUS_FAULT, STATUS_MISSINGMATRIX, STATUS_NOFILE, STATUS_OK, STATUS_UNKNOWNFORMAT, and STATUS_UNSUPPORTED.

Referenced by test_img_io(), and test_polarmap_io().

Here is the call graph for this function:

int imgReadFrame ( const char *  fname,
int  frame_to_read,
IMG img,
int  frame_index 
)

Read one time frame from a supported PET image or sinogram file into IMG data structure. This functions can be called repeatedly to read all the frames one at a time to conserve memory.

Parameters
fnamename of file from which IMG contents will be read. Currently supported file formats are ECAT 6.3 images and sinograms, ECAT 7.x 2D and 3D images and sinograms, and Analyze 7.5 3D and 4D images.
frame_to_readframe which will be read [1..frameNr]
imgpointer to initiated or occupied IMG data. If occupied, then new frame is tested to match the previous file type, dimensions, and other fundamental information contained in the IMG. If not occupied, then memory is allocated here.
frame_indexIMG frame index (0..dimt-1) where data will be placed. If index is >0, then the memory for that frame must be allocated before calling this function.
Returns
errstatus, which is STATUS_OK (0) when call was successful, and >0 in case of an error. Specifically, return value STATUS_NOMATRIX signals that frame does not exist, i.e. all frames have been read. IMG.statmsg can be set using ERROR_STATUS.

Definition at line 389 of file imgfile.c.

References IMG::_fileFormat, IMG::dimt, IMG::dimx, IMG::dimy, IMG::dimz, IMG_ANA, IMG_ANA_L, IMG_E63, IMG_E7, IMG_E7_2D, IMG_POLARMAP, IMG_STATUS_INITIALIZED, IMG_STATUS_OCCUPIED, IMG_TEST, imgAllocate(), imgEmpty(), imgInfo(), imgInit(), imgReadAnalyzeFrame(), imgReadEcat63Frame(), imgReadEcat7Frame(), imgReadHeader(), imgSetStatus(), IMG::statmsg, IMG::status, STATUS_FAULT, STATUS_INVALIDHEADER, STATUS_NOMEMORY, STATUS_UNSUPPORTED, and IMG::type.

Referenced by imgReadMinMax().

Here is the call graph for this function:

int imgReadHeader ( const char *  fname,
IMG img 
)

Fill IMG struct header information from an image or sinogram file in ECAT 6.3, ECAT 7.x or Analyze 7.5 format. Information concerning separate frames or planes is not filled.

Parameters
fnameimage or sinogram filename
imgpointer to initialized but not allocated IMG structure
Returns
errstatus, which is STATUS_OK (0) when call was successful, and >0 in case of an error.

Definition at line 329 of file imgfile.c.

References anaDatabaseExists(), IMG_STATUS_INITIALIZED, IMG_TEST, imgReadAnalyzeHeader(), imgReadEcat63Header(), imgReadEcat7Header(), imgSetStatus(), IMG::status, STATUS_FAULT, STATUS_OK, and STATUS_UNKNOWNFORMAT.

Referenced by imgReadFrame().

Here is the call graph for this function:

int imgWrite ( const char *  fname,
IMG img 
)

Write an image or sinogram file. Format depends on _fileFormat or filename extension.

Parameters
fnameoutput filename
imgpointer to IMG data
Returns
0 if ok, 1 invalid input, 2 invalid image type or status, 5 failed to write file, sets IMG->statmsg in case of error

Definition at line 277 of file imgfile.c.

References IMG::_fileFormat, ecat63WriteAllImg(), IMG_ANA, IMG_ANA_L, IMG_E63, IMG_E7_2D, IMG_POLARMAP, IMG_STATUS_OCCUPIED, IMG_TEST, IMG_TYPE_IMAGE, IMG_TYPE_POLARMAP, IMG_TYPE_RAW, IMG_UNKNOWN, imgFormatFromFName(), imgSetStatus(), imgWrite2DEcat7(), imgWriteAnalyze(), imgWriteEcat7(), imgWritePolarmap(), IMG::status, STATUS_DISKFULL, STATUS_FAULT, STATUS_NOMEMORY, STATUS_NOWRITEPERM, STATUS_OK, and IMG::type.

Referenced by imgMicropetCTToEcat7(), test_img_io(), and test_polarmap_io().

Here is the call graph for this function:

int imgWriteFrame ( const char *  fname,
int  frame_to_write,
IMG img,
int  frame_index 
)

Write one PET frame from IMG data struct into a supported PET image or sinogram file. This function can be called repeatedly to write all frames one at a time to conserve memory.

Parameters
fnamename of file where IMG contents will be written. Currently supported file formats are ECAT 6.3 images and sinograms, and ECAT 7.x 2D and 3D images and sinograms. Analyze 7.5 images are NOT supported. If file exists, data is either overwritten or catenated as a new frame, depending on the following arguments. If file does not exist, it is created.
frame_to_writePET frame number (1..frameNr) which will be written: If set to 0, frame data will be written to an existing or new PET file as a new frame, never overwriting existing data. If >0, then frame data is written as specified frame number, overwriting any data existing with the same frame number
imgpointer to the IMG data struct
frame_indexIMG frame index (0..dimt-1) which will be written.
Returns
errstatus, which is STATUS_OK (0) when call was successful, and >0 in case of an error.

Definition at line 493 of file imgfile.c.

References IMG::_fileFormat, IMG::dimt, IMG_ANA, IMG_ANA_L, IMG_E63, IMG_E7, IMG_E7_2D, IMG_POLARMAP, IMG_STATUS_OCCUPIED, IMG_TEST, imgFormatFromFName(), imgSetStatus(), imgWriteEcat63Frame(), imgWriteEcat7Frame(), IMG::status, STATUS_FAULT, and STATUS_UNSUPPORTED.

Referenced by imgMicropetPETToEcat7().

Here is the call graph for this function: