libtpcimgio
 All Data Structures Files Functions Variables Typedefs Enumerator Macros Pages
Functions
img_ana.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 "include/img.h"
#include "include/analyze.h"
#include "include/imgmax.h"
#include "include/imgdecay.h"
#include "include/sif.h"
#include "include/imgfile.h"
#include "include/img_sif.h"

Go to the source code of this file.

Functions

int imgReadAnalyze (const char *dbname, IMG *img)
 
int imgWriteAnalyze (const char *dbname, IMG *img)
 
int imgReadAnalyzeHeader (const char *dbname, IMG *img)
 
int imgGetAnalyzeHeader (IMG *img, ANALYZE_DSR *h)
 
int imgSetAnalyzeHeader (IMG *img, const char *dbname, ANALYZE_DSR *dsr, float fmin, float fmax)
 
int imgReadAnalyzeFirstFrame (const char *fname, IMG *img)
 
int imgReadAnalyzeFrame (const char *fname, int frame_to_read, IMG *img, int frame_index)
 
int imgWriteAnalyzeFrame (const char *dbname, int frame_to_write, IMG *img, int frame_index, float fmin, float fmax)
 

Function Documentation

int imgGetAnalyzeHeader ( IMG img,
ANALYZE_DSR h 
)
int imgReadAnalyze ( const char *  dbname,
IMG img 
)

Read Analyze 7.5 image. Analyze database name must be given with path. Image and header files with .img and .hdr extensions must exist. Also SIF file with .sif extension is used, if it exists. anaFlipping() determines whether image is flipped in z-direction; image is always flipped in x,y-directions.

Parameters
dbnameAnalyze database name with path, with or without extension
imgPointer to initialized IMG structure
Returns
0 if ok, and otherwise IMG status code; sets IMG->statmsg in case of error.

Definition at line 103 of file img_ana.c.

References IMG::_fileFormat, anaExistsNew(), anaFlipping(), anaPrintHeader(), anaReadHeader(), anaReadImagedata(), IMG::decayCorrection, ANALYZE_HEADER_HISTORY::descrip, ANALYZE_HEADER_IMGDIM::dim, ANALYZE_DSR::dime, IMG::dimz, ANALYZE_HEADER_IMGDIM::funused3, ANALYZE_DSR::hist, IMG_ANA, IMG_ANA_L, IMG_DC_CORRECTED, IMG_DC_NONCORRECTED, IMG_STATUS_INITIALIZED, IMG_TEST, IMG_TYPE_IMAGE, imgAllocate(), imgSetStatus(), IMG::isotopeHalflife, ANALYZE_DSR::little, IMG::m, ANALYZE_HEADER_HISTORY::patient_id, IMG::patientName, ANALYZE_HEADER_IMGDIM::pixdim, IMG::planeNumber, sif2img(), sifEmpty(), sifInit(), sifRead(), IMG::sizex, IMG::sizey, IMG::sizez, IMG::status, STATUS_FAULT, STATUS_INVALIDHEADER, STATUS_NOHEADERFILE, STATUS_NOIMGDATA, STATUS_NOMEMORY, STATUS_NOSIFDATA, STATUS_OK, STATUS_UNSUPPORTED, STATUS_WRONGSIFDATA, IMG::studyNr, and IMG::type.

Referenced by imgRead().

int imgReadAnalyzeFirstFrame ( const char *  fname,
IMG img 
)

Read the first frame from an Analyze 7.5 database into IMG data structure.

Parameters
fnameName of Analyze database from which IMG contents will be read
imgpointer to the initiated but not preallocated IMG data
Returns
errstatus, which is STATUS_OK (0) when call was successful, and >0 in case of an error.

Definition at line 672 of file img_ana.c.

References IMG::dimt, IMG::dimx, IMG::dimy, IMG::dimz, IMG_STATUS_INITIALIZED, IMG_TEST, imgAllocate(), imgInfo(), imgReadAnalyzeFrame(), imgReadAnalyzeHeader(), imgSetStatus(), IMG::status, STATUS_FAULT, STATUS_NOMEMORY, and STATUS_OK.

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

Read a specified frame from an Analyze 7.5 database into preallocated IMG data structure. Analyze database consists of two or three files in the same directory: fname.hdr, fname.img, and optionally fname.sif. IMG header is assumed to be filled correctly before calling this function, except for information concerning separate planes and this frame, which is filled here. If frame does not exist, then and only then STATUS_NOMATRIX is returned.

Parameters
fnamename of Analyze database from which IMG contents will be read
frame_to_readframe which will be read [1..frameNr]
imgpointer to the IMG data. Place for the frame must be preallocated
frame_indexIMG frame index [0..dimt-1] where data will be placed
Returns
errstatus, which is STATUS_OK (0) when call was successful, and >0 in case of an error.

Definition at line 717 of file img_ana.c.

References anaDatabaseExists(), anaFlipping(), anaReadHeader(), anaReadImagedata(), IMG::decayCorrFactor, IMG::dimt, IMG::dimx, IMG::dimy, IMG::dimz, IMG::end, SIF::frameNr, IMG_STATUS_OCCUPIED, IMG_TEST, imgSetStatus(), IMG::m, IMG::mid, SIF::prompts, IMG::prompts, SIF::randoms, IMG::randoms, sifEmpty(), sifInit(), sifRead(), IMG::start, IMG::status, STATUS_FAULT, STATUS_NOFILE, STATUS_NOHEADERFILE, STATUS_NOIMGDATA, STATUS_NOMATRIX, STATUS_NOMEMORY, STATUS_OK, STATUS_UNSUPPORTED, SIF::x1, and SIF::x2.

Referenced by imgReadAnalyzeFirstFrame(), and imgReadFrame().

int imgReadAnalyzeHeader ( const char *  dbname,
IMG img 
)

Fill IMG struct header information from Analyze 7.5 database files. SIF file is read if available. Information concerning separate frames or planes is not filled though.

Parameters
dbnamename of Analyze database, may contain filename extension
imgpointer to the initiated IMG data
Returns
errstatus, which is STATUS_OK (0) when call was successful, and >0 in case of an error.

Definition at line 441 of file img_ana.c.

References anaDatabaseExists(), anaReadHeader(), IMG_STATUS_INITIALIZED, IMG_TEST, imgGetAnalyzeHeader(), imgSetStatus(), SIF::isotope_name, IMG::isotopeHalflife, IMG::scanStart, SIF::scantime, sifEmpty(), sifInit(), sifRead(), IMG::status, STATUS_FAULT, STATUS_NOFILE, STATUS_NOHEADERFILE, STATUS_OK, STATUS_UNSUPPORTED, SIF::studynr, and IMG::studyNr.

Referenced by imgFormatDetermine(), imgReadAnalyzeFirstFrame(), imgReadHeader(), and imgWriteAnalyzeFrame().

int imgSetAnalyzeHeader ( IMG img,
const char *  dbname,
ANALYZE_DSR dsr,
float  fmin,
float  fmax 
)

Copy header information in IMG struct into Analyze 7.5 header struct. Min, max, and scale factor are set here and they apply to all frames.

Returns
errstatus, which is STATUS_OK (0) when call was successful, and >0 in case of an error.
Parameters
imgpointer to IMG struct from which header information is read
dbnameAnalyze 7.5 database name
dsrpointer to Analyze header struct to be filled
fminminimum pixel value in all frames that will be written
fmaxmaximum pixel value in all frames that will be written

Definition at line 565 of file img_ana.c.

References IMG::_fileFormat, ANALYZE_DT_SIGNED_SHORT, ANALYZE_HEADER_IMGDIM::bitpix, ANALYZE_HEADER_IMGDIM::cal_max, ANALYZE_HEADER_IMGDIM::cal_min, ANALYZE_HEADER_KEY::data_type, ANALYZE_HEADER_IMGDIM::datatype, ANALYZE_HEADER_KEY::db_name, IMG::decayCorrection, ANALYZE_HEADER_HISTORY::descrip, ANALYZE_HEADER_IMGDIM::dim, ANALYZE_DSR::dime, IMG::dimt, IMG::dimx, IMG::dimy, IMG::dimz, ANALYZE_HEADER_HISTORY::exp_date, ANALYZE_HEADER_HISTORY::exp_time, ANALYZE_HEADER_KEY::extents, ANALYZE_HEADER_IMGDIM::funused1, ANALYZE_HEADER_IMGDIM::funused3, ANALYZE_HEADER_IMGDIM::glmax, ANALYZE_HEADER_IMGDIM::glmin, ANALYZE_DSR::hist, ANALYZE_DSR::hk, IMG_ANA_L, IMG_DC_CORRECTED, IMG_DC_NONCORRECTED, IMG_STATUS_INITIALIZED, IMG_STATUS_OCCUPIED, IMG_TEST, imgMinMax(), imgSetStatus(), IMG::isotopeHalflife, ANALYZE_DSR::little, ANALYZE_HEADER_IMGDIM::pixdim, ANALYZE_HEADER_KEY::regular, ANALYZE_HEADER_HISTORY::scannum, IMG::scanStart, ANALYZE_HEADER_KEY::sizeof_hdr, IMG::sizex, IMG::sizey, IMG::sizez, IMG::status, STATUS_FAULT, STATUS_OK, and IMG::studyNr.

Referenced by imgWriteAnalyzeFrame().

int imgWriteAnalyze ( const char *  dbname,
IMG img 
)

Write Analyze 7.5 image. Analyze database name must be given with path. Path must exist. Image and header files with .img and .hdr extensions are created. Existing files are overwritten. anaFlipping() determines whether image is flipped in z-direction; image is always flipped in x,y-directions. Byte order is determined based on _fileFormat field.

Parameters
dbnameanalyze database name with path, without extension
imgpointer to IMG data
Returns
0 if ok, 1 invalid input, 2 invalid image status (image not occupied), 3 failed to resolve extreme values (min and max), 12 failed to allocate temp memory, 14 failed to open file for writing, 15 failed to write data, 21 failed to write header, and sets IMG->statmsg in case of error

Definition at line 239 of file img_ana.c.

References IMG::_fileFormat, anaFlipping(), ANALYZE_DT_SIGNED_SHORT, anaWriteHeader(), ANALYZE_HEADER_IMGDIM::bitpix, ANALYZE_HEADER_IMGDIM::cal_max, ANALYZE_HEADER_IMGDIM::cal_min, ANALYZE_HEADER_KEY::data_type, ANALYZE_HEADER_IMGDIM::datatype, ANALYZE_HEADER_KEY::db_name, IMG::decayCorrection, ANALYZE_HEADER_HISTORY::descrip, ANALYZE_HEADER_IMGDIM::dim, ANALYZE_DSR::dime, IMG::dimt, IMG::dimx, IMG::dimy, IMG::dimz, ANALYZE_HEADER_HISTORY::exp_date, ANALYZE_HEADER_HISTORY::exp_time, ANALYZE_HEADER_KEY::extents, SIF::frameNr, ANALYZE_HEADER_IMGDIM::funused1, ANALYZE_HEADER_IMGDIM::funused3, ANALYZE_HEADER_IMGDIM::glmax, ANALYZE_HEADER_IMGDIM::glmin, ANALYZE_DSR::hist, ANALYZE_DSR::hk, img2sif(), IMG_ANA_L, IMG_DC_CORRECTED, IMG_DC_NONCORRECTED, IMG_STATUS_OCCUPIED, IMG_TEST, imgMinMax(), imgSetStatus(), IMG::isotopeHalflife, ANALYZE_DSR::little, IMG::m, ANALYZE_HEADER_IMGDIM::pixdim, ANALYZE_HEADER_KEY::regular, ANALYZE_HEADER_HISTORY::scannum, IMG::scanStart, sifInit(), sifRead(), sifWrite(), ANALYZE_HEADER_KEY::sizeof_hdr, IMG::sizex, IMG::sizey, IMG::sizez, IMG::status, STATUS_CANTWRITEHEADERFILE, STATUS_CANTWRITEIMGFILE, STATUS_FAULT, STATUS_NOMEMORY, STATUS_OK, and IMG::studyNr.

Referenced by imgWrite().

int imgWriteAnalyzeFrame ( const char *  dbname,
int  frame_to_write,
IMG img,
int  frame_index,
float  fmin,
float  fmax 
)

Write one PET frame from IMG data struct into Analyze 7.5 database file. This function can be called repeatedly to write all frames one at a time to conserve memory. This function does not write SIF.

Parameters
dbnamename of file where IMG contents will be written. If file does not exist, it is created. Make sure to delete existing file, unless you want to add data
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
fminminimum pixel value in all frames that will be written; used only when writing the first frame
fmaxmaximum pixel value in all frames that will be written; used only when writing the first frame
Returns
errstatus, which is STATUS_OK (0) when call was successful, and >0 in case of an error.

Definition at line 829 of file img_ana.c.

References IMG::_fileFormat, anaDatabaseExists(), anaFlipping(), anaReadHeader(), anaWriteHeader(), ANALYZE_HEADER_IMGDIM::dim, ANALYZE_DSR::dime, IMG::dimt, IMG::dimx, IMG::dimy, IMG::dimz, ANALYZE_HEADER_IMGDIM::funused1, IMG_ANA, IMG_ANA_L, IMG_STATUS_OCCUPIED, IMG_TEST, imgEmpty(), imgInit(), imgReadAnalyzeHeader(), imgSetAnalyzeHeader(), ANALYZE_DSR::little, IMG::m, IMG::status, STATUS_CANTWRITEHEADERFILE, STATUS_CANTWRITEIMGFILE, STATUS_FAULT, STATUS_MISSINGMATRIX, STATUS_NOMAINHEADER, STATUS_NOMEMORY, STATUS_NOWRITEPERM, STATUS_OK, STATUS_VARMATSIZE, STATUS_WRONGFILETYPE, and IMG::type.