107 #include "halflife.h"
115 "fault in calling routine",
118 "unknown file format",
119 "unsupported file type",
120 "missing matrix/matrices",
121 "no permission to write",
123 "cannot read matrix list",
124 "invalid matrix list",
125 "variable matrix size",
126 "cannot read mainheader",
127 "cannot read subheader",
128 "cannot read matrix",
129 "axial compression is not supported",
130 "image datafile does not exist",
131 "header file does not exist",
132 "invalid header contents",
133 "cannot read image data",
134 "cannot read sif data",
136 "cannot write image datafile",
137 "cannot write header file",
142 "polar map is not supported",
148 static const char *_imgStatusMessage[] =
151 "fault in calling routine",
166 memset(image, 0,
sizeof(
IMG));
195 image->
m=(
float****)NULL;
197 image->
pixel=(
float*)NULL;
198 image->
column=(
float**)NULL;
199 image->
row=(
float***)NULL;
200 image->
plane=(
float****)NULL;
218 if(
IMG_TEST) printf(
"imgEmpty()\n");
221 if(image->
_pxl!=NULL) free(image->
_pxl);
222 if(image->
_col!=NULL) free(image->
_col);
223 if(image->
_row!=NULL) free(image->
_row);
224 if(image->
_pln!=NULL) free(image->
_pln);
255 image->
m=(
float****)NULL;
257 image->
pixel=(
float*)NULL;
258 image->
column=(
float**)NULL;
259 image->
row=(
float***)NULL;
260 image->
plane=(
float****)NULL;
264 image->
weight=image->
sd=(
float*)NULL;
286 unsigned short int zi, ri, ci;
287 float ***rptr, **cptr, *pptr;
289 if(
IMG_TEST) printf(
"imgAllocate(*image, %d, %d, %d, %d)\n", planes, rows, columns, frames);
293 if(planes<1 || rows<1 || columns<1 || frames<1)
return(2);
297 image->
_header=(
float*)calloc(8*frames,
sizeof(
float));
300 image->
planeNumber=(
int*)calloc(planes,
sizeof(
int));
302 free(image->
_header);
return(4);}
304 image->
_pln=(
float****)malloc(planes*
sizeof(
float***));
305 if(image->
_pln==NULL) {
307 image->
_row=(
float***)malloc(planes*rows*
sizeof(
float**));
308 if(image->
_row==NULL) {
310 image->
_col=(
float**)malloc(planes*rows*columns*
sizeof(
float*));
311 if(image->
_col==NULL) {
313 free(image->
_pln); free(image->
_row);
return(7);
315 image->
_pxl=(
float*)calloc(planes*rows*columns*frames,
sizeof(
float));
316 if(image->
_pxl==NULL) {
318 free(image->
_pln); free(image->
_row); free(image->
_col);
return(8);
322 for(zi=0; zi<planes; zi++) {
323 image->
_pln[zi]=rptr;
324 for(ri=0; ri<rows; ri++) {
326 for(ci=0; ci<columns; ci++) {
327 *cptr++=pptr; pptr+=frames;
331 image->
m=image->
_pln;
346 image->
dimz=planes; image->
dimy=rows; image->
dimx=columns; image->
dimt=frames;
372 ret=
imgAllocate(image, planes, rows, columns, frames);
if(ret)
return ret;
373 ret=
imgCopyhdr(image_from, image);
return ret;
388 else return((
char*)
imgmsg[status_index]);
421 fprintf(stdout,
"image_status := not initialized\n");
return;
423 fprintf(stdout,
"image_status := initialized but empty\n");
425 fprintf(stdout,
"image_status := error\n");
427 fprintf(stdout,
"image_error_status := %s\n", image->
statmsg);
428 fprintf(stdout,
"image_type := %d\n", image->
type);
429 fprintf(stdout,
"saved_data_type := %d\n", image->
_dataType);
430 fprintf(stdout,
"file_format := %d\n", image->
_fileFormat);
431 fprintf(stdout,
"scanner := %d\n", image->
scanner);
432 fprintf(stdout,
"identification_code := %.*s\n", MAX_STUDYNR_LEN, image->
studyNr);
433 fprintf(stdout,
"data_unit := %s\n",
imgUnit((
int)image->
unit));
434 fprintf(stdout,
"image_zoom := %g\n", image->
zoom);
436 fprintf(stdout,
"isotope_halflife := %e [sec]\n", image->
isotopeHalflife);
438 if(st!=NULL) strftime(buf, 64,
"%Y-%m-%d %H:%M:%S", st);
else strcpy(buf,
"1900-01-01 00:00:00");
439 fprintf(stdout,
"scan_start_time := %s\n", buf);
440 fprintf(stdout,
"patient_orientation := %d\n", image->
orientation);
441 fprintf(stdout,
"FOV_axial := %g [mm]\n", image->
axialFOV);
442 fprintf(stdout,
"FOV_transaxial := %g [mm]\n", image->
transaxialFOV);
443 fprintf(stdout,
"sample_distance := %g [mm]\n", image->
sampleDistance);
444 fprintf(stdout,
"pixel_size_x := %g [mm]\n", image->
sizex);
445 fprintf(stdout,
"pixel_size_y := %g [mm]\n", image->
sizey);
446 fprintf(stdout,
"pixel_size_z := %g [mm]\n", image->
sizez);
447 fprintf(stdout,
"dimension_x := %d\n", image->
dimx);
448 fprintf(stdout,
"dimension_y := %d\n", image->
dimy);
449 fprintf(stdout,
"dimension_z := %d\n", image->
dimz);
450 fprintf(stdout,
"dimension_t := %d\n", image->
dimt);
454 fprintf(stdout,
"polarmap_sectors_per_ring :=");
457 fprintf(stdout,
"\n");
458 fprintf(stdout,
"polarmap_ring_position :=");
461 fprintf(stdout,
"\n");
462 fprintf(stdout,
"polarmap_ring_angle :=");
465 fprintf(stdout,
"\n");
471 fprintf(stdout,
"actual_plane_numbers := %d", image->
planeNumber[0]);
472 for(i=1; i<image->
dimz; i++) fprintf(stdout,
" %d", image->
planeNumber[i]);
473 fprintf(stdout,
"\n");
474 fprintf(stdout,
"Frame times (sec):\n");
475 for(i=0; i<image->
dimt; i++) fprintf(stdout,
" %e %e %e\n",
477 if(image->
isWeight) fprintf(stdout,
"Frames are weighted.\n");
478 else fprintf(stdout,
"Frames are not weighted.\n");
480 fprintf(stdout,
"Decay correction factors for each frame:\n");
481 for(i=0; i<image->
dimt; i++)
484 fprintf(stdout,
"Image is not decay corrected.\n");
504 if(
IMG_TEST) printf(
"imgCopyhdr()\n");
506 if(image1==NULL || image2==NULL)
return(1);
507 if(image1==image2)
return(2);
544 if(image1->
dimz==image2->
dimz)
for(i=0; i<image1->
dimz; i++)
546 if(image1->
dimt==image2->
dimt)
for(i=0; i<image1->
dimt; i++) {
548 image2->
mid[i]=image1->
mid[i];
571 int zi, yi, xi, fi, zj, yj, xj, fj;
574 printf(
"imgExtractRange(*img1, r, *img2)\n");
575 printf(
" z=[%d,%d] y=[%d,%d] x=[%d,%d] f=[%d,%d]\n",
594 if(
imgAllocate(img2, zi, yi, xi, fi)!=0)
return(2);
599 for(fi=r.
f1-1, fj=0; fi<r.
f2; fi++, fj++) {
601 img2->
end[fj]=img1->
end[fi];
602 img2->
mid[fj]=img1->
mid[fi];
604 img2->
sd[fj]=img1->
sd[fi];
609 for(zi=r.
z1-1, zj=0; zi<r.
z2; zi++, zj++)
611 for(zi=r.
z1-1, zj=0; zi<r.
z2; zi++, zj++)
612 for(yi=r.
y1-1, yj=0; yi<r.
y2; yi++, yj++)
613 for(xi=r.
x1-1, xj=0; xi<r.
x2; xi++, xj++)
614 for(fi=r.
f1-1, fj=0; fi<r.
f2; fi++, fj++)
615 img2->
m[zj][yj][xj][fj]=img1->
m[zi][yi][xi][fi];
int imgAllocate(IMG *image, int planes, int rows, int columns, int frames)
char radiopharmaceutical[32]
void imgEmpty(IMG *image)
char * imgStatus(int status_index)
float polarmap_ring_position[MAX_POLARMAP_NUM_RINGS]
short int polarmap_start_angle
static const char * imgmsg[]
int imgCopyhdr(IMG *image1, IMG *image2)
#define IMG_STATUS_OCCUPIED
int imgExtractRange(IMG *img1, IMG_RANGE r, IMG *img2)
char studyDescription[32]
#define MAX_POLARMAP_NUM_RINGS
#define IMG_STATUS_INITIALIZED
int polarmap_sectors_per_ring[MAX_POLARMAP_NUM_RINGS]
short int polarmap_ring_angle[MAX_POLARMAP_NUM_RINGS]
#define IMG_STATUS_UNINITIALIZED
int imgAllocateWithHeader(IMG *image, int planes, int rows, int columns, int frames, IMG *image_from)
char studyNr[MAX_STUDYNR_LEN+1]
char * imgUnit(int dunit)
void imgSetStatus(IMG *img, int status_index)