My Project
|
#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"
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) |
int imgGetAnalyzeHeader | ( | IMG * | img, |
ANALYZE_DSR * | h | ||
) |
Copy Analyze 7.5 header information into IMG.
img | image structure |
h | Analyze header structure |
Definition at line 481 of file img_ana.c.
References IMG::_fileFormat, IMG::decayCorrected, ANALYZE_HEADER_HISTORY::descrip, ANALYZE_HEADER_IMGDIM::dim, ANALYZE_DSR::dime, IMG::dimt, IMG::dimx, IMG::dimy, IMG::dimz, ANALYZE_HEADER_IMGDIM::funused3, ANALYZE_DSR::hist, IMG_ANA, IMG_ANA_L, IMG_STATUS_INITIALIZED, IMG_STATUS_OCCUPIED, IMG_TEST, IMG_TYPE_IMAGE, imgSetStatus(), IMG::isotopeHalflife, ANALYZE_DSR::little, ANALYZE_HEADER_HISTORY::patient_id, IMG::patientName, ANALYZE_HEADER_IMGDIM::pixdim, IMG::sizex, IMG::sizey, IMG::sizez, IMG::status, STATUS_FAULT, STATUS_INVALIDHEADER, STATUS_OK, IMG::studyNr, and IMG::type.
Referenced by imgReadAnalyzeHeader().
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.
dbname | Analyze database name with path, with or without extension |
img | Pointer to initialized IMG strucure |
Definition at line 83 of file img_ana.c.
References IMG::_fileFormat, anaExists(), anaFlipping(), anaPrintHeader(), anaReadHeader(), anaReadImagedata(), IMG::decayCorrected, ANALYZE_HEADER_HISTORY::descrip, ANALYZE_HEADER_IMGDIM::dim, ANALYZE_DSR::dime, IMG::dimt, IMG::dimz, IMG::end, SIF::frameNr, ANALYZE_HEADER_IMGDIM::funused3, ANALYZE_DSR::hist, IMG_ANA, IMG_ANA_L, IMG_STATUS_INITIALIZED, IMG_TEST, IMG_TYPE_IMAGE, imgAllocate(), imgSetStatus(), SIF::isotope_name, IMG::isotopeHalflife, ANALYZE_DSR::little, IMG::m, IMG::mid, ANALYZE_HEADER_HISTORY::patient_id, IMG::patientName, ANALYZE_HEADER_IMGDIM::pixdim, IMG::planeNumber, SIF::prompts, IMG::prompts, SIF::randoms, IMG::randoms, IMG::scanStart, SIF::scantime, sifEmpty(), sifInit(), sifRead(), IMG::sizex, IMG::sizey, IMG::sizez, IMG::start, IMG::status, STATUS_FAULT, STATUS_INVALIDHEADER, STATUS_NOHEADERFILE, STATUS_NOIMGDATA, STATUS_NOMEMORY, STATUS_NOSIFDATA, STATUS_OK, STATUS_UNSUPPORTED, STATUS_WRONGSIFDATA, IMG::studyNr, IMG::type, SIF::x1, and SIF::x2.
Referenced by imgRead().
int imgReadAnalyzeFirstFrame | ( | const char * | fname, |
IMG * | img | ||
) |
Read the first frame from an Analyze 7.5 database into IMG data structure.
fname | Name of Analyze database from which IMG contents will be read |
img | pointer to the initiated but not preallocated IMG data |
Definition at line 629 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.
fname | name of Analyze database from which IMG contents will be read |
frame_to_read | frame which will be read [1..frameNr] |
img | pointer to the IMG data. Place for the frame must be preallocated |
frame_index | IMG frame index [0..dimt-1] where data will be placed |
Definition at line 674 of file img_ana.c.
References anaDatabaseExists(), anaFlipping(), anaReadHeader(), anaReadImagedata(), 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.
dbname | name of Analyze database, may contain filename extension |
img | pointer to the initiated IMG data |
Definition at line 414 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 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.
img | pointer to IMG struct |
dbname | Analyze 7.5 database name |
dsr | pointer to Analyze header struct to be filled |
fmin | minimum pixel value in all frames that will be written |
fmax | maximum pixel value in all frames that will be written |
Definition at line 542 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::decayCorrected, 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_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.
dbname | analyze database name with path, without extension |
img | pointer to IMG data |
Definition at line 253 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::decayCorrected, 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_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, 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.
dbname | name 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_write | PET 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 |
img | pointer to the IMG data struct |
frame_index | IMG frame index (0..dimt-1) which will be written |
fmin | minimum pixel value in all frames that will be written; used only when writing the first frame |
fmax | maximum pixel value in all frames that will be written; used only when writing the first frame |
Definition at line 781 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.