My Project
Functions
ecat7r.c File Reference
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <swap.h>
#include <datetime.h>
#include "include/ecat7.h"
Include dependency graph for ecat7r.c:

Go to the source code of this file.

Functions

int ecat7ReadMainheader (FILE *fp, ECAT7_mainheader *h)
 
int ecat7ReadImageheader (FILE *fp, int blk, ECAT7_imageheader *h)
 
int ecat7ReadAttenheader (FILE *fp, int blk, ECAT7_attenheader *h)
 
int ecat7ReadPolmapheader (FILE *fp, int blk, ECAT7_polmapheader *h)
 
int ecat7ReadNormheader (FILE *fp, int blk, ECAT7_normheader *h)
 
int ecat7ReadScanheader (FILE *fp, int blk, ECAT7_scanheader *h)
 
int ecat7Read2DScanheader (FILE *fp, int blk, ECAT7_2Dscanheader *h)
 
int ecat7Read2DNormheader (FILE *fp, int blk, ECAT7_2Dnormheader *h)
 
int ecat7ReadMatrixdata (FILE *fp, int start_block, int block_nr, char *data, int dtype)
 
int ecat7ReadImageMatrix (FILE *fp, int first_block, int last_block, ECAT7_imageheader *h, float **fdata)
 
int ecat7Read2DScanMatrix (FILE *fp, int first_block, int last_block, ECAT7_2Dscanheader *h, float **fdata)
 
int ecat7ReadScanMatrix (FILE *fp, int first_block, int last_block, ECAT7_scanheader *h, float **fdata)
 
int ecat7ReadPolarmapMatrix (FILE *fp, int first_block, int last_block, ECAT7_polmapheader *h, float **fdata)
 
float ecat7rFloat (void *bufi, int isvax, int islittle)
 
int ecat7rInt (void *bufi, int isvax, int islittle)
 
int ecat7pxlbytes (short int data_type)
 

Function Documentation

◆ ecat7pxlbytes()

int ecat7pxlbytes ( short int  data_type)

Returns the nr of bytes required for storage of one pixel of specified data_type

Parameters
data_typedefined value for data type
Returns
number of bytes (1,2 or 4) or 0 if type not recognized

Definition at line 1055 of file ecat7r.c.

References ECAT7_BYTE, ECAT7_IEEER4, ECAT7_SUNI2, ECAT7_SUNI4, ECAT7_VAXI2, ECAT7_VAXI4, and ECAT7_VAXR4.

Referenced by ecat7ReadScanMatrix(), ecat7Write2DScanMatrix(), ecat7WriteImageMatrix(), ecat7WritePolarmapMatrix(), and ecat7WriteScanMatrix().

Here is the caller graph for this function:

◆ ecat7Read2DNormheader()

int ecat7Read2DNormheader ( FILE *  fp,
int  blk,
ECAT7_2Dnormheader h 
)

Read ECAT 7.x 2D normalization header

Parameters
fpinput file pointer
blkblock number [1..number of blocks]
hEcat7 normalization header
Returns
0 if ok, 1 == invalid parameters, 2 == first header block not found, 3 == header block not read properly

Definition at line 546 of file ecat7r.c.

References ecat7_2Dnormheader::data_type, ECAT7_TEST, ecat7_2Dnormheader::fill_cti, ecat7_2Dnormheader::fill_user, ecat7_2Dnormheader::fov_source_width, MatBLKSIZE, ecat7_2Dnormheader::norm_max, ecat7_2Dnormheader::norm_min, ecat7_2Dnormheader::norm_quality_factor, ecat7_2Dnormheader::norm_quality_factor_code, ecat7_2Dnormheader::num_angles, ecat7_2Dnormheader::num_dimensions, ecat7_2Dnormheader::num_r_elements, ecat7_2Dnormheader::num_z_elements, ecat7_2Dnormheader::ring_difference, ecat7_2Dnormheader::scale_factor, ecat7_2Dnormheader::span, and ecat7_2Dnormheader::storage_order.

Referenced by ecat7PrintSubheader().

Here is the caller graph for this function:

◆ ecat7Read2DScanheader()

int ecat7Read2DScanheader ( FILE *  fp,
int  blk,
ECAT7_2Dscanheader h 
)

Read ECAT 7.x 2D scan header

Parameters
fpinput file pointer
blkblock number [1..number of blocks]
hEcat7 2D scan header
Returns
0 if ok, 1 == invalid parameters, 2 == first header block not found, 3 == header block not read properly

Definition at line 485 of file ecat7r.c.

References ecat7_2Dscanheader::cor_singles, ecat7_2Dscanheader::corrections_applied, ecat7_2Dscanheader::data_type, ecat7_2Dscanheader::deadtime_correction_factor, ecat7_2Dscanheader::delayed, ECAT7_TEST, ecat7_2Dscanheader::fill_cti, ecat7_2Dscanheader::fill_gate, ecat7_2Dscanheader::fill_user, ecat7_2Dscanheader::frame_duration, ecat7_2Dscanheader::frame_start_time, ecat7_2Dscanheader::gate_duration, MatBLKSIZE, ecat7_2Dscanheader::multiples, ecat7_2Dscanheader::net_trues, ecat7_2Dscanheader::num_accepted_beats, ecat7_2Dscanheader::num_angles, ecat7_2Dscanheader::num_dimensions, ecat7_2Dscanheader::num_r_elements, ecat7_2Dscanheader::num_z_elements, ecat7_2Dscanheader::physical_planes, ecat7_2Dscanheader::prompts, ecat7_2Dscanheader::r_wave_offset, ecat7_2Dscanheader::ring_difference, ecat7_2Dscanheader::scale_factor, ecat7_2Dscanheader::scan_max, ecat7_2Dscanheader::scan_min, ecat7_2Dscanheader::tot_avg_cor, ecat7_2Dscanheader::tot_avg_uncor, ecat7_2Dscanheader::total_coin_rate, ecat7_2Dscanheader::uncor_singles, ecat7_2Dscanheader::w_resolution, ecat7_2Dscanheader::x_resolution, ecat7_2Dscanheader::y_resolution, and ecat7_2Dscanheader::z_resolution.

Referenced by ecat7PrintSubheader(), ecat7Read2DScanMatrix(), imgReadEcat7(), and imgReadEcat7Header().

Here is the caller graph for this function:

◆ ecat7Read2DScanMatrix()

int ecat7Read2DScanMatrix ( FILE *  fp,
int  first_block,
int  last_block,
ECAT7_2Dscanheader h,
float **  fdata 
)

Read ECAT7 2D sinogram matrix header and data Memory for fdata[] is allocated here, remember to free memory after usage. Note: data is not calibrated with factor in main header. Note: data is not multiplied with deadtime_correction_factor.

Parameters
fpECAT file pointer
first_blockSubheader record number
last_blockLast data block number
hPtr to subheader data which is filled
fdataPtr to the address of the matrix data
Returns
0 if ok, 1 invalid input, 5 failed to read scan header, 6 invalid image (x,y,z) dimensions, 8 failed to allocate memory for meta-data, 9 failed to read matrix data, 11 failed to allocate memory for voxel data

Definition at line 749 of file ecat7r.c.

References ecat7_2Dscanheader::data_type, ECAT7_BYTE, ECAT7_IEEER4, ECAT7_SUNI2, ECAT7_SUNI4, ECAT7_TEST, ECAT7_VAXI2, ECAT7_VAXI4, ECAT7_VAXR4, ecat7errmsg, ecat7Print2DScanheader(), ecat7Read2DScanheader(), ecat7ReadMatrixdata(), MatBLKSIZE, MatFirstDirBlk, ecat7_2Dscanheader::num_angles, ecat7_2Dscanheader::num_dimensions, ecat7_2Dscanheader::num_r_elements, ecat7_2Dscanheader::num_z_elements, and ecat7_2Dscanheader::scale_factor.

Referenced by imgReadEcat7(), and imgReadEcat7Frame().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ecat7ReadAttenheader()

int ecat7ReadAttenheader ( FILE *  fp,
int  blk,
ECAT7_attenheader h 
)

◆ ecat7ReadImageheader()

int ecat7ReadImageheader ( FILE *  fp,
int  blk,
ECAT7_imageheader h 
)

Read ECAT 7.x image header

Parameters
fpinput file pointer
blkblock number [1..number of blocks]
hEcat7 image header
Returns
0 if ok, 1 == invalid parameters, 2 == first header block not found, 3 == header block not read properly

Definition at line 177 of file ecat7r.c.

References ecat7_imageheader::annotation, ecat7_imageheader::data_type, ecat7_imageheader::decay_corr_fctr, ECAT7_TEST, ecat7_imageheader::fill_cti, ecat7_imageheader::fill_user, ecat7_imageheader::filter_code, ecat7_imageheader::filter_cutoff_frequency, ecat7_imageheader::filter_order, ecat7_imageheader::filter_ramp_slope, ecat7_imageheader::filter_resolution, ecat7_imageheader::filter_scatter_fraction, ecat7_imageheader::filter_scatter_slope, ecat7_imageheader::frame_duration, ecat7_imageheader::frame_start_time, ecat7_imageheader::gate_duration, ecat7_imageheader::image_max, ecat7_imageheader::image_min, MatBLKSIZE, ecat7_imageheader::mt_1_1, ecat7_imageheader::mt_1_2, ecat7_imageheader::mt_1_3, ecat7_imageheader::mt_1_4, ecat7_imageheader::mt_2_1, ecat7_imageheader::mt_2_2, ecat7_imageheader::mt_2_3, ecat7_imageheader::mt_2_4, ecat7_imageheader::mt_3_1, ecat7_imageheader::mt_3_2, ecat7_imageheader::mt_3_3, ecat7_imageheader::mt_3_4, ecat7_imageheader::num_accepted_beats, ecat7_imageheader::num_angles, ecat7_imageheader::num_dimensions, ecat7_imageheader::num_r_elements, ecat7_imageheader::processing_code, ecat7_imageheader::r_wave_offset, ecat7_imageheader::recon_type, ecat7_imageheader::recon_views, ecat7_imageheader::recon_zoom, ecat7_imageheader::rfilter_code, ecat7_imageheader::rfilter_cutoff, ecat7_imageheader::rfilter_order, ecat7_imageheader::rfilter_resolution, ecat7_imageheader::scale_factor, ecat7_imageheader::scatter_type, ecat7_imageheader::x_dimension, ecat7_imageheader::x_offset, ecat7_imageheader::x_pixel_size, ecat7_imageheader::x_resolution, ecat7_imageheader::y_dimension, ecat7_imageheader::y_offset, ecat7_imageheader::y_pixel_size, ecat7_imageheader::y_resolution, ecat7_imageheader::z_dimension, ecat7_imageheader::z_offset, ecat7_imageheader::z_pixel_size, ecat7_imageheader::z_resolution, ecat7_imageheader::z_rotation_angle, ecat7_imageheader::zfilter_code, ecat7_imageheader::zfilter_cutoff, ecat7_imageheader::zfilter_order, and ecat7_imageheader::zfilter_resolution.

Referenced by ecat7GetNums(), ecat7PrintSubheader(), ecat7ReadImageMatrix(), imgReadEcat7(), and imgReadEcat7Header().

Here is the caller graph for this function:

◆ ecat7ReadImageMatrix()

int ecat7ReadImageMatrix ( FILE *  fp,
int  first_block,
int  last_block,
ECAT7_imageheader h,
float **  fdata 
)

Read ECAT7 image matrix header and data. If only header is to be read, set last_block=first_block. Note: data is not calibrated with factor in main header.

Parameters
fpECAT file pointer
first_blockSubheader record number
last_blockLast data block number
hPtr to subheader data which is filled
fdataPtr to the address of the matrix data
Returns
0 if ok, 1 invalid input, 5 failed to read subheader, 6 invalid image (x,y,z) dimensions, 8 failed to allocate memory for meta-data, 9 failed to read matrix data, 11 failed to allocate memory for voxel data

Definition at line 656 of file ecat7r.c.

References ecat7_imageheader::data_type, ECAT7_BYTE, ECAT7_IEEER4, ECAT7_SUNI2, ECAT7_SUNI4, ECAT7_TEST, ECAT7_VAXI2, ECAT7_VAXI4, ECAT7_VAXR4, ecat7errmsg, ecat7PrintImageheader(), ecat7ReadImageheader(), ecat7ReadMatrixdata(), MatBLKSIZE, MatFirstDirBlk, ecat7_imageheader::num_dimensions, ecat7_imageheader::scale_factor, ecat7_imageheader::x_dimension, ecat7_imageheader::y_dimension, and ecat7_imageheader::z_dimension.

Referenced by imgReadEcat7(), and imgReadEcat7Frame().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ecat7ReadMainheader()

int ecat7ReadMainheader ( FILE *  fp,
ECAT7_mainheader h 
)

Read ECAT 7.x main header

Parameters
fpinput file pointer
hEcat7 main header
Returns
0 if ok, 1 == invalid parameters, 2 == first header block not found, 3 == header block not read properly

Definition at line 78 of file ecat7r.c.

References ecat7_mainheader::acquisition_mode, ecat7_mainheader::acquisition_type, ecat7_mainheader::angular_compression, ecat7_mainheader::axial_samp_mode, ecat7_mainheader::bed_elevation, ecat7_mainheader::bed_position, ecat7_mainheader::bin_size, ecat7_mainheader::branching_fraction, ecat7_mainheader::calibration_units, ecat7_mainheader::calibration_units_label, ecat7_mainheader::coin_samp_mode, ecat7_mainheader::compression_code, ecat7_mainheader::data_units, ecat7_mainheader::distance_scanned, ecat7_mainheader::dosage, ecat7_mainheader::dose_start_time, ECAT7_TEST, ecat7_mainheader::ecat_calibration_factor, ecat7_mainheader::facility_name, ecat7_mainheader::file_type, ecat7_mainheader::fill_cti, ecat7_mainheader::gantry_rotation, ecat7_mainheader::gantry_tilt, ecat7_mainheader::init_bed_position, ecat7_mainheader::intrinsic_tilt, ecat7_mainheader::isotope_halflife, ecat7_mainheader::isotope_name, ecat7_mainheader::lwr_sctr_thres, ecat7_mainheader::lwr_true_thres, ecat7_mainheader::magic_number, MatBLKSIZE, ecat7_mainheader::num_bed_pos, ecat7_mainheader::num_frames, ecat7_mainheader::num_gates, ecat7_mainheader::num_planes, ecat7_mainheader::operator_name, ecat7_mainheader::original_file_name, ecat7_mainheader::patient_age, ecat7_mainheader::patient_birth_date, ecat7_mainheader::patient_dexterity, ecat7_mainheader::patient_height, ecat7_mainheader::patient_id, ecat7_mainheader::patient_name, ecat7_mainheader::patient_orientation, ecat7_mainheader::patient_sex, ecat7_mainheader::patient_weight, ecat7_mainheader::physician_name, ecat7_mainheader::plane_separation, ecat7_mainheader::radiopharmaceutical, ecat7_mainheader::scan_start_time, ecat7_mainheader::septa_state, ecat7_mainheader::serial_number, ecat7_mainheader::study_description, ecat7_mainheader::study_type, ecat7_mainheader::sw_version, ecat7_mainheader::system_type, ecat7_mainheader::transaxial_fov, ecat7_mainheader::transm_source_type, ecat7_mainheader::upr_true_thres, ecat7_mainheader::user_process_code, ecat7_mainheader::well_counter_corr_factor, and ecat7_mainheader::wobble_speed.

Referenced by imgRead(), imgReadEcat7(), imgReadEcat7Frame(), imgReadEcat7Header(), and imgWriteEcat7Frame().

Here is the caller graph for this function:

◆ ecat7ReadMatrixdata()

int ecat7ReadMatrixdata ( FILE *  fp,
int  start_block,
int  block_nr,
char *  data,
int  dtype 
)

Read ECAT7 matrix data and convert byte order if necessary Remember to allocate memory for full blocks! There are differences here when compared to ecat63.c

Parameters
fpinput file pointer
start_blockstarting block index
block_nrnumber of blocks to be read
datatarget buffer
dtypedata type of target buffer
Returns
0 if ok, 1 == invalid parameters, 9 == start block not found, 2 == data blocks read properly

Definition at line 595 of file ecat7r.c.

References ECAT7_BYTE, ECAT7_IEEER4, ECAT7_SUNI2, ECAT7_SUNI4, ECAT7_TEST, ECAT7_VAXI2, ECAT7_VAXI4, ECAT7_VAXR4, ecat7rFloat(), ecat7rInt(), and MatBLKSIZE.

Referenced by ecat7Read2DScanMatrix(), ecat7ReadImageMatrix(), ecat7ReadPolarmapMatrix(), and ecat7ReadScanMatrix().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ecat7ReadNormheader()

int ecat7ReadNormheader ( FILE *  fp,
int  blk,
ECAT7_normheader h 
)

◆ ecat7ReadPolarmapMatrix()

int ecat7ReadPolarmapMatrix ( FILE *  fp,
int  first_block,
int  last_block,
ECAT7_polmapheader h,
float **  fdata 
)

Read ECAT7 polar map matrix header and data. If only header is to be read, set last_block=first_block. Note: data is not calibrated with factor in main header.

Parameters
fpECAT file pointer
first_blockSubheader record number
last_blockLast data block number
hPtr to subheader data which is filled
fdataPtr to the address of the matrix data
Returns
0 if ok, 1 invalid input, 5 failed to read scan header, 6 invalid image (x,y,z) dimensions, 8 failed to allocate memory for meta-data, 9 failed to read matrix data, 11 failed to allocate memory for voxel data

Definition at line 939 of file ecat7r.c.

References ecat7_polmapheader::data_type, ECAT7_BYTE, ECAT7_IEEER4, ECAT7_SUNI2, ECAT7_SUNI4, ECAT7_TEST, ECAT7_VAXI2, ECAT7_VAXI4, ECAT7_VAXR4, ecat7errmsg, ecat7PrintPolmapheader(), ecat7ReadMatrixdata(), ecat7ReadPolmapheader(), MatBLKSIZE, MatFirstDirBlk, ecat7_polmapheader::num_rings, ecat7_polmapheader::scale_factor, and ecat7_polmapheader::sectors_per_ring.

Referenced by imgReadEcat7(), and imgReadEcat7Frame().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ecat7ReadPolmapheader()

int ecat7ReadPolmapheader ( FILE *  fp,
int  blk,
ECAT7_polmapheader h 
)

◆ ecat7ReadScanheader()

int ecat7ReadScanheader ( FILE *  fp,
int  blk,
ECAT7_scanheader h 
)

Read ECAT 7.x 3D scan header (512 bytes)

Parameters
fpinput file pointer
blkblock number [1..number of blocks]
hEcat7 scan header
Returns
0 if ok, 1 == invalid parameters, 2 == first header block not found, 3 == header block not read properly

Definition at line 424 of file ecat7r.c.

References ecat7_scanheader::axial_compression, ecat7_scanheader::corrections_applied, ecat7_scanheader::data_type, ecat7_scanheader::deadtime_correction_factor, ecat7_scanheader::delayed, ECAT7_TEST, ecat7_scanheader::fill_cti, ecat7_scanheader::fill_gate, ecat7_scanheader::fill_user, ecat7_scanheader::frame_duration, ecat7_scanheader::frame_start_time, ecat7_scanheader::gate_duration, MatBLKSIZE, ecat7_scanheader::multiples, ecat7_scanheader::net_trues, ecat7_scanheader::num_accepted_beats, ecat7_scanheader::num_angles, ecat7_scanheader::num_dimensions, ecat7_scanheader::num_r_elements, ecat7_scanheader::num_z_elements, ecat7_scanheader::prompts, ecat7_scanheader::r_wave_offset, ecat7_scanheader::ring_difference, ecat7_scanheader::scale_factor, ecat7_scanheader::scan_max, ecat7_scanheader::scan_min, ecat7_scanheader::storage_order, ecat7_scanheader::tot_avg_cor, ecat7_scanheader::tot_avg_uncor, ecat7_scanheader::total_coin_rate, ecat7_scanheader::uncor_singles, ecat7_scanheader::v_resolution, ecat7_scanheader::w_resolution, ecat7_scanheader::x_resolution, and ecat7_scanheader::z_resolution.

Referenced by ecat7GetNums(), ecat7PrintSubheader(), ecat7ReadScanMatrix(), imgReadEcat7(), and imgReadEcat7Header().

Here is the caller graph for this function:

◆ ecat7ReadScanMatrix()

int ecat7ReadScanMatrix ( FILE *  fp,
int  first_block,
int  last_block,
ECAT7_scanheader h,
float **  fdata 
)

Read ECAT7 3D sinogram matrix header and data. Memory for fdata[] is allocated here, remember to free memory after usage. Note: data is converted to floats with scale_factor in the scan matrix header. Note: data is not calibrated with ecat_calibration_factor in main header. Note: data is not multiplied with deadtime_correction_factor.

Parameters
fpECAT file pointer
first_blockSubheader record number
last_blockLast data block number
hPtr to subheader data which is filled
fdataPtr to the address of the matrix data
Returns
0 if ok, 1 invalid input, 5 failed to read scan header, 6 invalid image (x,y,z) dimensions, 8 failed to allocate memory for meta-data, 9 failed to read matrix data, 11 failed to allocate memory for voxel data

Definition at line 844 of file ecat7r.c.

References ecat7_scanheader::data_type, ECAT7_BYTE, ECAT7_IEEER4, ECAT7_SUNI2, ECAT7_SUNI4, ECAT7_TEST, ECAT7_VAXI2, ECAT7_VAXI4, ECAT7_VAXR4, ecat7errmsg, ecat7PrintScanheader(), ecat7pxlbytes(), ecat7ReadMatrixdata(), ecat7ReadScanheader(), MatBLKSIZE, MatFirstDirBlk, ecat7_scanheader::num_angles, ecat7_scanheader::num_r_elements, ecat7_scanheader::num_z_elements, and ecat7_scanheader::scale_factor.

Referenced by imgReadEcat7(), and imgReadEcat7Frame().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ecat7rFloat()

float ecat7rFloat ( void *  bufi,
int  isvax,
int  islittle 
)

Read ECAT7 floats

Parameters
bufipointer to 32-bit data block
isvax!= 0 for VAX format
islittle!= 0 for little endian conversion
Returns
data in bufi as float value

Definition at line 1015 of file ecat7r.c.

Referenced by ecat7ReadMatrixdata().

Here is the caller graph for this function:

◆ ecat7rInt()

int ecat7rInt ( void *  bufi,
int  isvax,
int  islittle 
)

Reading and writing ECAT7 32-bit ints 32-bit int format is same in VAX and i386

Parameters
bufipointer to one 32-bit data block
isvaxignored
islittle!= 0 for little endian conversion
Returns
converted 32-bit integer

Definition at line 1038 of file ecat7r.c.

Referenced by ecat7ReadMatrixdata().

Here is the caller graph for this function: