TPCCLIB
Loading...
Searching...
No Matches
img.c File Reference

Basic tools for working with IMG data struct. More...

#include "libtpcimgio.h"

Go to the source code of this file.

Functions

void imgInit (IMG *image)
 
void imgEmpty (IMG *image)
 
int imgAllocate (IMG *image, int planes, int rows, int columns, int frames)
 
int imgAllocateWithHeader (IMG *image, int planes, int rows, int columns, int frames, IMG *image_from)
 
int imgDup (IMG *img1, IMG *img2)
 
char * imgStatus (int status_index)
 
void imgSetStatus (IMG *img, int status_index)
 
void imgInfo (IMG *image)
 
int imgCopyhdr (IMG *image1, IMG *image2)
 
int imgExtractRange (IMG *img1, IMG_RANGE r, IMG *img2)
 
int imgExistentTimes (IMG *img)
 
int imgExistentCounts (IMG *img)
 
unsigned long long imgNaNs (IMG *img, int fix)
 

Variables

int IMG_TEST
 

Detailed Description

Basic tools for working with IMG data struct.

Author
Vesa Oikonen

Definition in file img.c.

Function Documentation

◆ imgAllocate()

int imgAllocate ( IMG * image,
int planes,
int rows,
int columns,
int frames )

Allocates memory for img data. Old contents are not saved.

See also
imgAllocateWithHeader, imgDup, imgEmpty, imgInit
Returns
0 if ok, 1 image is not initialized, 2 invalid input dimension(s), 3 failed to allocate header, 4 - 8 failed to allocate image data
Parameters
imagePointer to initialized image struct; old contents are deleted.
planesNr of image planes (dim z) to allocate.
rowsNr of image rows (dim y) to allocate.
columnsNr of image columns (dim x) to allocate.
framesNr of image time frames (dim t) to allocate.

Definition at line 194 of file img.c.

205 {
206 if(IMG_TEST) printf("imgAllocate(*image, %d, %d, %d, %d)\n", planes, rows, columns, frames);
207 /* Check arguments */
208 if(image==NULL) return(1);
209 imgSetStatus(image, STATUS_FAULT);
210 if(image->status==IMG_STATUS_UNINITIALIZED) return(1);
211 if(planes<1 || rows<1 || columns<1 || frames<1) return(2);
212 if(image->status>=IMG_STATUS_OCCUPIED) imgEmpty(image);
213 /* Allocate memory for header data */
214 imgSetStatus(image, STATUS_NOMEMORY);
215 image->_header=(float*)calloc(8*frames, sizeof(float));
216 if(image->_header==NULL) return(3);
217 image->planeNumber=(int*)calloc(planes, sizeof(int));
218 if(image->planeNumber==NULL) {free(image->_header); return(4);}
219 /* Allocate memory for image data */
220 image->_pln=(float****)calloc((size_t)planes, sizeof(float***));
221 if(image->_pln==NULL) {
222 free(image->_header); free(image->planeNumber);
223 return(5);
224 }
225 image->_row=(float***)calloc((size_t)planes*rows, sizeof(float**));
226 if(image->_row==NULL) {
227 free(image->_header); free(image->planeNumber);
228 free(image->_pln); return(6);
229 }
230 image->_col=(float**)calloc((size_t)planes*rows*columns, sizeof(float*));
231 if(image->_col==NULL) {
232 free(image->_header); free(image->planeNumber);
233 free(image->_pln); free(image->_row); return(7);
234 }
235 image->_pxl=(float*)calloc((size_t)planes*rows*columns*frames, sizeof(float));
236 if(image->_pxl==NULL) {
237 free(image->_header); free(image->planeNumber);
238 free(image->_pln); free(image->_row); free(image->_col); return(8);
239 }
240 /* Set data pointers */
241 float ***rptr, **cptr, *pptr;
242 rptr=image->_row; cptr=image->_col; pptr=image->_pxl;
243 for(unsigned short int zi=0; zi<planes; zi++) {
244 image->_pln[zi]=rptr;
245 for(unsigned short int ri=0; ri<rows; ri++) {
246 *rptr++=cptr;
247 for(unsigned short int ci=0; ci<columns; ci++) {
248 *cptr++=pptr; pptr+=frames;
249 }
250 }
251 }
252 image->m=image->_pln;
253 image->plane=image->_pln;
254 image->column=image->_col;
255 image->row=image->_row;
256 image->pixel=image->_pxl;
257 /* Set header pointers */
258 image->start= image->_header+0*frames;
259 image->end= image->_header+1*frames;
260 image->mid= image->_header+2*frames;
261 image->weight= image->_header+3*frames;
262 image->sd= image->_header+4*frames;
263 image->prompts= image->_header+5*frames;
264 image->randoms= image->_header+6*frames;
265 image->decayCorrFactor=image->_header+7*frames;
266 /* Ok */
267 image->dimz=planes; image->dimy=rows; image->dimx=columns; image->dimt=frames;
268 imgSetStatus(image, STATUS_OK);
270 return(0);
271}
int IMG_TEST
Definition img.c:6
void imgSetStatus(IMG *img, int status_index)
Definition img.c:345
void imgEmpty(IMG *image)
Definition img.c:121
#define IMG_STATUS_OCCUPIED
#define IMG_STATUS_UNINITIALIZED
float * pixel
unsigned short int dimx
float * sd
float **** m
float *** row
char status
float * prompts
unsigned short int dimt
int * planeNumber
float * weight
float **** plane
float * start
unsigned short int dimz
unsigned short int dimy
float * end
float ** column
float * decayCorrFactor
float * randoms
float * mid

Referenced by ecat63ReadAllToImg(), ecat63ReadPlaneToImg(), img2cube(), img_k1_using_ki(), imgAllocateWithHeader(), imgAUMC(), imgExtractRange(), imgFBP(), imgGetFrameDiff(), imgGetFrameDyn(), imgGetMaxFrame(), imgGetMaxTime(), imgMicropetCTToEcat7(), imgMicropetPETToEcat7(), imgMRP(), imgMRT(), imgOutlierFilter(), imgReadAnalyze(), imgReadAnalyzeFirstFrame(), imgReadEcat63FirstFrame(), imgReadEcat7(), imgReadEcat7FirstFrame(), imgReadFrame(), imgReadMicropetFirstFrame(), imgReadNifti(), imgReadNiftiFirstFrame(), imgReprojection(), imgStructuringElement(), imgThresholdingLowHigh(), and imgThresholdMaskCount().

◆ imgAllocateWithHeader()

int imgAllocateWithHeader ( IMG * image,
int planes,
int rows,
int columns,
int frames,
IMG * image_from )

This functions just combines imgAllocate() and imgCopyhdr().

See also
imgAllocate, imgCopyhdr, imgDup
Returns
Returns 0 if successful, otherwise returns <>0.
Parameters
imagePointer to IMG struct which will be allocated here.
planesImage matrix dimensions; z.
rowsImage matrix dimensions; y.
columnsImage matrix dimensions; x.
framesImage matrix dimensions; t.
image_fromPointer to IMG struct where header contents will be copied from.

Definition at line 279 of file img.c.

292 {
293 int ret;
294 ret=imgAllocate(image, planes, rows, columns, frames); if(ret) return ret;
295 ret=imgCopyhdr(image_from, image); return ret;
296}
int imgAllocate(IMG *image, int planes, int rows, int columns, int frames)
Definition img.c:194
int imgCopyhdr(IMG *image1, IMG *image2)
Definition img.c:471

Referenced by img_logan(), img_patlak(), imgDup(), imgFlipAbove(), imgFlipRight(), imgFrameIntegral(), imgMeanZ(), imgNoiseTemplate(), imgPVCRRL(), imgPVCRVC(), imgsegmSimilar(), imgsegmThresholdMask(), imgShrink(), imgSwell(), and imgTimeIntegral().

◆ imgCopyhdr()

int imgCopyhdr ( IMG * image1,
IMG * image2 )

Copy the header fields from one image struct to another.

Does not copy memory addresses or IMG sizes. Frame times, decay correction factors etc are copied, when possible. Plane numbers are copied, when possible.

See also
imgAllocateWithHeader, imgDup
Returns
0 if successful, 1 invalid input, 2 pointers are to the same image
Parameters
image1Pointer to input IMG data.
image2Pointer to output IMG data.

Definition at line 471 of file img.c.

476 {
477 if(IMG_TEST) printf("imgCopyhdr()\n");
478 /* check */
479 if(image1==NULL || image2==NULL) return(1);
480 if(image1==image2) return(2);
481 /* copy */
482 image2->type=image1->type;
483 image2->unit=image1->unit;
484 image2->calibrationFactor=image1->calibrationFactor;
485 strcpy(image2->studyNr, image1->studyNr);
486 strcpy(image2->patientName, image1->patientName);
487 strcpy(image2->patientID, image1->patientID);
488 strcpy(image2->userProcessCode, image1->userProcessCode);
489 strcpy(image2->studyDescription, image1->studyDescription);
490 image2->zoom=image1->zoom;
491 strcpy(image2->radiopharmaceutical, image1->radiopharmaceutical);
492 image2->isotopeHalflife=image1->isotopeHalflife;
493 image2->decayCorrection=image1->decayCorrection;
494 image2->branchingFraction=image1->branchingFraction;
495 image2->scanStart=image1->scanStart;
496 image2->axialFOV=image1->axialFOV;
497 image2->transaxialFOV=image1->transaxialFOV;
498 image2->sampleDistance=image1->sampleDistance;
499 image2->sizex=image1->sizex;
500 image2->sizey=image1->sizey;
501 image2->sizez=image1->sizez;
502 image2->gapx=image1->gapx;
503 image2->gapy=image1->gapy;
504 image2->gapz=image1->gapz;
505 image2->resolutionx=image1->resolutionx;
506 image2->resolutiony=image1->resolutiony;
507 image2->resolutionz=image1->resolutionz;
508 image2->_dataType=image1->_dataType;
509 image2->_fileFormat=image1->_fileFormat;
510 image2->orientation=image1->orientation;
511 image2->scanner=image1->scanner;
512 image2->modality=image1->modality;
513 for(int i=0; i<2; i++) image2->xform[i]=image1->xform[i];
514 for(int i=0; i<18; i++) image2->quatern[i]=image1->quatern[i];
515 for(int i=0; i<12; i++) image2->mt[i]=image1->mt[i];
516 if(iftdup(&image1->ift, &image2->ift, 0)!=0) return(8);
518 for(int i=0; i<MAX_POLARMAP_NUM_RINGS; i++) {
521 image2->polarmap_ring_angle[i]=image1->polarmap_ring_angle[i];
522 }
524 if(image1->dimz==image2->dimz) for(int i=0; i<image1->dimz; i++) {
525 image2->planeNumber[i]=image1->planeNumber[i];
526 }
527 if(image1->dimt==image2->dimt) for(int i=0; i<image1->dimt; i++) {
528 image2->start[i]=image1->start[i]; image2->end[i]=image1->end[i];
529 image2->mid[i]=image1->mid[i];
530 image2->weight[i]=image1->weight[i]; image2->sd[i]=image1->sd[i];
531 image2->prompts[i]=image1->prompts[i];
532 image2->randoms[i]=image1->randoms[i];
533 image2->decayCorrFactor[i]=image1->decayCorrFactor[i];
534 }
535 image2->isWeight=image1->isWeight;
536 return(0);
537}
int iftdup(IFT *ift1, IFT *ift2, int verbose)
Definition ift.c:235
#define MAX_POLARMAP_NUM_RINGS
float sizex
int polarmap_num_rings
float branchingFraction
char type
float resolutionx
char patientName[32]
float resolutiony
char studyDescription[32]
float sampleDistance
short int polarmap_start_angle
float gapx
char decayCorrection
float transaxialFOV
short int xform[2]
char unit
time_t scanStart
int _fileFormat
char userProcessCode[11]
int _dataType
char patientID[16]
IFT ift
int scanner
float sizey
int modality
int polarmap_sectors_per_ring[MAX_POLARMAP_NUM_RINGS]
int orientation
float calibrationFactor
float mt[12]
float quatern[18]
float zoom
char radiopharmaceutical[32]
float isotopeHalflife
short int polarmap_ring_angle[MAX_POLARMAP_NUM_RINGS]
char studyNr[MAX_STUDYNR_LEN+1]
float gapy
float gapz
float axialFOV
char isWeight
float polarmap_ring_position[MAX_POLARMAP_NUM_RINGS]
float sizez
float resolutionz

Referenced by img2cube(), img_k1_using_ki(), imgAllocateWithHeader(), imgAUMC(), imgExtractRange(), imgGetFrameDiff(), imgGetFrameDyn(), imgGetMaxFrame(), imgGetMaxTime(), imgMRT(), imgThresholdingLowHigh(), and imgThresholdMaskCount().

◆ imgDup()

int imgDup ( IMG * img1,
IMG * img2 )

Duplicate IMG struct. Any existing contents in img2 will be deleted.

See also
imgAllocate, imgAllocateWithHeader, imgExtractRange
Returns
Returns 0 if successful.
Parameters
img1Pointer to IMG struct which will be duplicated
img2Pointer to initiated IMG struct into which the duplicate will be made

Definition at line 304 of file img.c.

309 {
310 if(img1==NULL || img2==NULL) return(1);
311 /* Delete any old contents */
312 imgEmpty(img2);
313 /* Allocate memory and copy headers */
314 int ret=imgAllocateWithHeader(img2, img1->dimz, img1->dimy, img1->dimx, img1->dimt, img1);
315 if(ret!=0) return(10+ret);
316 /* Copy voxel contents */
317 unsigned long long int n=img1->dimx*img1->dimy*img1->dimz*img1->dimt;
318 for(unsigned long long int i=0; i<n; i++) img2->pixel[i]=img1->pixel[i];
319 return 0;
320}
int imgAllocateWithHeader(IMG *image, int planes, int rows, int columns, int frames, IMG *image_from)
Definition img.c:279

Referenced by imgFlipAbove(), imgFlipRight(), imgMaskDilate(), imgMaskErode(), and imgMeanZ().

◆ imgEmpty()

void imgEmpty ( IMG * image)

Free memory that is allocated for IMG.

See also
imgInit, imgAllocate, imgRead
Parameters
imagePointer to IMG struct

Definition at line 121 of file img.c.

124 {
125 if(IMG_TEST) printf("imgEmpty()\n");
126 if(image==NULL || image->status<IMG_STATUS_OCCUPIED) return;
127 /* Free up memory */
128 if(image->_pxl!=NULL) free(image->_pxl);
129 if(image->_col!=NULL) free(image->_col);
130 if(image->_row!=NULL) free(image->_row);
131 if(image->_pln!=NULL) free(image->_pln);
132 if(image->dimz>0) {free(image->planeNumber);}
133 if(image->dimt>0) free(image->_header);
134 /* Set variables */
135 imgSetStatus(image, STATUS_OK);
136 image->type=0;
137 image->unit=0;
138 image->calibrationFactor=0;
139 image->zoom=0.0;
140 image->radiopharmaceutical[0]=(char)0;
141 image->isotopeHalflife=0.0;
142 image->decayCorrection=(char)IMG_DC_UNKNOWN;
143 image->branchingFraction=0.0;
144 image->unit=0;
145 image->scanStart=0;
146 image->orientation=0;
147 image->axialFOV=image->transaxialFOV=image->sampleDistance=0.0;
148 image->studyNr[0]=image->patientName[0]=image->patientID[0]=(char)0;
149 image->userProcessCode[0]=image->studyDescription[0]=(char)0;
150 image->sizex=image->sizey=image->sizez=0;
151 image->gapx=image->gapy=image->gapz=0.0;
152 image->resolutionx=image->resolutiony=image->resolutionz=0.0;
153 image->_dataType=0;
154 image->_fileFormat=0;
155 image->scanner=0;
156 image->modality=0;
157 for(int i=0; i<2; i++) image->xform[i]=NIFTI_XFORM_UNKNOWN;
158 for(int i=0; i<18; i++) image->quatern[i]=0.0;
159 for(int i=0; i<12; i++) image->mt[i]=0.0;
160 iftEmpty(&image->ift);
161 image->polarmap_num_rings=0;
162 for(int i=0; i<MAX_POLARMAP_NUM_RINGS; i++) {
163 image->polarmap_sectors_per_ring[i]=0;
164 image->polarmap_ring_position[i]=0.0;
165 image->polarmap_ring_angle[i]=0;
166 }
167 image->polarmap_start_angle=0;
168 image->dimt=image->dimx=image->dimy=image->dimz=0;
169 image->m=(float****)NULL;
170 image->_header=(float*)NULL;
171 image->pixel=(float*)NULL;
172 image->column=(float**)NULL;
173 image->row=(float***)NULL;
174 image->plane=(float****)NULL;
175 image->planeNumber=(int*)NULL;
176 image->start=image->end=image->mid=(float*)NULL;
177 image->isWeight=0;
178 image->weight=image->sd=(float*)NULL;
179 image->decayCorrFactor=(float*)NULL;
180 /* Set status */
182 image->errstatus=STATUS_OK;
183}
void iftEmpty(IFT *ift)
Definition ift.c:60
#define NIFTI_XFORM_UNKNOWN
#define IMG_DC_UNKNOWN
#define IMG_STATUS_INITIALIZED
int errstatus

Referenced by ecat63ReadPlaneToImg(), img2cube(), img_k1_using_ki(), img_logan(), img_patlak(), imgAllocate(), imgAnalyzeToEcat(), imgAUMC(), imgDup(), imgExtractRange(), imgFBP(), imgFlipAbove(), imgFlipRight(), imgFormatDetermine(), imgFrameIntegral(), imgGetFrameDiff(), imgGetFrameDyn(), imgGetMaxFrame(), imgGetMaxTime(), imgMaskDilate(), imgMaskErode(), imgMaskRegionLabeling(), imgMicropetCTToEcat7(), imgMicropetPETToEcat7(), imgMRP(), imgMRT(), imgNiftiToEcat(), imgOutlierFilter(), imgPVCRRL(), imgPVCRVC(), imgReadFrame(), imgReadMicropet(), imgReadMinMax(), imgReadModelingData(), imgReprojection(), imgsegmSimilar(), imgStructuringElement(), imgThresholding(), imgThresholdingLowHigh(), imgWriteAnalyzeFrame(), imgWriteEcat63Frame(), imgWriteEcat7Frame(), and imgWriteNiftiFrame().

◆ imgExistentCounts()

int imgExistentCounts ( IMG * img)

Verify that IMG contains prompts and randoms.

See also
imgExistentTimes
Returns
Returns 0 if neither prompts or randoms can be found, 1 or 2 if prompts or randoms can be found, and 3 if both prompts and randoms are there.
Parameters
imgPointer to IMG struct

Definition at line 630 of file img.c.

633 {
634 int p=0, r=0;
635 float v1, v2;
636 if(img==NULL || img->status!=IMG_STATUS_OCCUPIED || img->dimt<1) return 0;
637 /* If just one frame, then value > 0 is fine */
638 if(img->dimt==1) {
639 if(img->prompts[0]>0.00000001) p=1;
640 if(img->randoms[0]>0.00000001) r=2;
641 return(p+r);
642 }
643 /* Otherwise, check also that frames have different count level */
644 for(int fi=1; fi<img->dimt; fi++) {
645 v1=img->prompts[fi]-img->prompts[fi-1]; if(fabs(v1)>0.001) p=1;
646 v2=img->randoms[fi]-img->randoms[fi-1]; if(fabs(v2)>0.001) r=2;
647 if((p+r)>2) break;
648 }
649 return(p+r);
650}

Referenced by img2sif().

◆ imgExistentTimes()

int imgExistentTimes ( IMG * img)

Verify that IMG contains frame times.

See also
imgExistentCounts, imgFramesCheck
Returns
Returns nonzero if frame times are there, and 0 if not.
Parameters
imgPointer to IMG struct.

Definition at line 613 of file img.c.

616 {
617 if(img==NULL || img->status!=IMG_STATUS_OCCUPIED || img->dimt<1) return 0;
618 for(int fi=0; fi<img->dimt; fi++) if(img->end[fi]>0.00000001) return 1;
619 return 0;
620}

Referenced by img2sif(), imgAUMC(), imgFrameIntegral(), imgMRT(), imgNoiseTemplate(), and imgReadModelingData().

◆ imgExtractRange()

int imgExtractRange ( IMG * img1,
IMG_RANGE r,
IMG * img2 )

Extract a smaller 4D image from inside an IMG.

Any existing data is overwritten.

See also
imgInit, imgEmpty, imgDup
Returns
0 if ok, 1 invalid input, 2 failed to allocate memory for target image
Parameters
img1Source image structure, 'occupied' (has allocated data).
rImage range structure.
img2Target image structure 'initialized' (has not allocated data).

Definition at line 548 of file img.c.

555 {
556 int zi, yi, xi, fi, zj, yj, xj, fj;
557
558 if(IMG_TEST) {
559 printf("imgExtractRange(*img1, r, *img2)\n");
560 printf(" z=[%d,%d] y=[%d,%d] x=[%d,%d] f=[%d,%d]\n",
561 r.z1, r.z2, r.y1, r.y2, r.x1, r.x2, r.f1, r.f2);
562 }
563 /* Check arguments */
564 if(img2==NULL) return(1); else imgSetStatus(img2, STATUS_FAULT);
565 if(img1->status!=IMG_STATUS_OCCUPIED) return(1);
566 if(img2->status==IMG_STATUS_UNINITIALIZED) return(1);
567 if(r.z1<1 || r.z2>img1->dimz || r.z1>r.z2) return(1);
568 if(r.y1<1 || r.y2>img1->dimy || r.y1>r.y2) return(1);
569 if(r.x1<1 || r.x2>img1->dimx || r.x1>r.x2) return(1);
570 if(r.f1<1 || r.f2>img1->dimt || r.f1>r.f2) return(1);
571
572 /* Allocate memory unless the same size was previously allocated */
573 imgSetStatus(img2, STATUS_NOMEMORY);
574 zi=r.z2-r.z1+1; yi=r.y2-r.y1+1; xi=r.x2-r.x1+1; fi=r.f2-r.f1+1;
575 if(img2->status>=IMG_STATUS_OCCUPIED)
576 if(img2->dimz!=zi || img2->dimy!=yi || img2->dimx!=xi || img2->dimt!=fi)
577 imgEmpty(img2);
578 if(img2->status!=IMG_STATUS_OCCUPIED) {
579 if(imgAllocate(img2, zi, yi, xi, fi)!=0) return(2);
580 }
581
582 /* Copy data */
583 imgCopyhdr(img1, img2);
584 for(fi=r.f1-1, fj=0; fi<r.f2; fi++, fj++) {
585 img2->start[fj]=img1->start[fi];
586 img2->end[fj]=img1->end[fi];
587 img2->mid[fj]=img1->mid[fi];
588 img2->weight[fj]=img1->weight[fi];
589 img2->sd[fj]=img1->sd[fi];
590 img2->prompts[fj]=img1->prompts[fi];
591 img2->randoms[fj]=img1->randoms[fi];
592 img2->decayCorrFactor[fj]=img1->decayCorrFactor[fi];
593 }
594 for(zi=r.z1-1, zj=0; zi<r.z2; zi++, zj++) {
595 img2->planeNumber[zj]=img1->planeNumber[zi];
596 }
597 for(zi=r.z1-1, zj=0; zi<r.z2; zi++, zj++)
598 for(yi=r.y1-1, yj=0; yi<r.y2; yi++, yj++)
599 for(xi=r.x1-1, xj=0; xi<r.x2; xi++, xj++)
600 for(fi=r.f1-1, fj=0; fi<r.f2; fi++, fj++)
601 img2->m[zj][yj][xj][fj]=img1->m[zi][yi][xi][fi];
602
603 imgSetStatus(img2, STATUS_OK);
604 return(0);
605}

◆ imgInfo()

void imgInfo ( IMG * image)

Prints img information to stdout; mainly for testing purposes.

Parameters
imagePointer to IMG data.

Definition at line 359 of file img.c.

362 {
363 char buf[64];
364
365 if(IMG_TEST) printf("imgInfo()\n");
366 if(image==NULL) {
367 fprintf(stdout, "image := NULL\n"); return;
368 } else if(image->status<=IMG_STATUS_UNINITIALIZED) {
369 fprintf(stdout, "image_status := not initialized\n"); return;
370 } else if(image->status==IMG_STATUS_INITIALIZED) {
371 fprintf(stdout, "image_status := initialized but empty\n"); /* return; */
372 } else if(image->status==IMG_STATUS_ERROR) {
373 fprintf(stdout, "image_status := error\n");
374 }
375 fprintf(stdout, "image_error_status := %s\n", image->statmsg);
376 fprintf(stdout, "image_type := %d\n", image->type);
377 fprintf(stdout, "saved_data_type := %d\n", image->_dataType);
378 fprintf(stdout, "file_format := %d\n", image->_fileFormat);
379 fprintf(stdout, "scanner := %d\n", image->scanner);
380 fprintf(stdout, "modality := %d\n", image->modality);
381
382 fprintf(stdout, "qform := %d\n", image->xform[0]);
383 fprintf(stdout, "sform := %d\n", image->xform[1]);
384 fprintf(stdout, "quatern_b := %g\n", image->quatern[0]);
385 fprintf(stdout, "quatern_c := %g\n", image->quatern[1]);
386 fprintf(stdout, "quatern_d := %g\n", image->quatern[2]);
387 fprintf(stdout, "quatern_x_shift := %g\n", image->quatern[3]);
388 fprintf(stdout, "quatern_y_shift := %g\n", image->quatern[4]);
389 fprintf(stdout, "quatern_z_shift := %g\n", image->quatern[5]);
390 for(int i=0; i<4; i++)
391 fprintf(stdout, "srow_x[%d] := %g\n", 1+i, image->quatern[6+i]);
392 for(int i=0; i<4; i++)
393 fprintf(stdout, "srow_y[%d] := %g\n", 1+i, image->quatern[10+i]);
394 for(int i=0; i<4; i++)
395 fprintf(stdout, "srow_z[%d] := %g\n", 1+i, image->quatern[14+i]);
396 for(int i=0; i<12; i++)
397 fprintf(stdout, "matrix_transformation[%d] := %g\n", 1+i, image->mt[i]);
398
399 fprintf(stdout, "ift.keyNr := %d\n", image->ift.keyNr);
400 fprintf(stdout, "identification_code := %.*s\n",
401 MAX_STUDYNR_LEN, image->studyNr);
402 fprintf(stdout, "data_unit := %s\n", imgUnit((int)image->unit));
403 fprintf(stdout, "image_zoom := %g\n", image->zoom);
404 fprintf(stdout, "radiopharmaceutical := %.32s\n", image->radiopharmaceutical);
405 fprintf(stdout, "isotope_halflife := %e [sec]\n", image->isotopeHalflife);
406 fprintf(stdout, "branching_fraction := %f\n", image->branchingFraction);
407 fprintf(stdout, "calibration_factor := %e\n", image->calibrationFactor);
408 if(!ctime_r_int(&image->scanStart, buf)) strcpy(buf, "1900-01-01 00:00:00");
409 fprintf(stdout, "scan_start_time := %s\n", buf);
410 fprintf(stdout, "patient_name := %s\n", image->patientName);
411 fprintf(stdout, "patient_id := %s\n", image->patientID);
412 fprintf(stdout, "patient_orientation := %d\n", image->orientation);
413 fprintf(stdout, "FOV_axial := %g [mm]\n", image->axialFOV);
414 fprintf(stdout, "FOV_transaxial := %g [mm]\n", image->transaxialFOV);
415 fprintf(stdout, "sample_distance := %g [mm]\n", image->sampleDistance);
416 fprintf(stdout, "pixel_size_x := %g [mm]\n", image->sizex);
417 fprintf(stdout, "pixel_size_y := %g [mm]\n", image->sizey);
418 fprintf(stdout, "pixel_size_z := %g [mm]\n", image->sizez);
419 fprintf(stdout, "dimension_x := %d\n", image->dimx);
420 fprintf(stdout, "dimension_y := %d\n", image->dimy);
421 fprintf(stdout, "dimension_z := %d\n", image->dimz);
422 fprintf(stdout, "dimension_t := %d\n", image->dimt);
423 /* Polar map */
424 fprintf(stdout, "polarmap_num_rings := %d\n", image->polarmap_num_rings);
425 if(image->polarmap_num_rings>0) {
426 fprintf(stdout, "polarmap_sectors_per_ring :=");
427 for(int i=0; i<image->polarmap_num_rings; i++)
428 fprintf(stdout, " %d", image->polarmap_sectors_per_ring[i]);
429 fprintf(stdout, "\n");
430 fprintf(stdout, "polarmap_ring_position :=");
431 for(int i=0; i<image->polarmap_num_rings; i++)
432 fprintf(stdout, " %g", image->polarmap_ring_position[i]);
433 fprintf(stdout, "\n");
434 fprintf(stdout, "polarmap_ring_angle :=");
435 for(int i=0; i<image->polarmap_num_rings; i++)
436 fprintf(stdout, " %d", image->polarmap_ring_angle[i]);
437 fprintf(stdout, "\n");
438 fprintf(stdout, "polarmap_start_angle := %d\n", image->polarmap_start_angle);
439 }
440 /* Check if the rest is available */
441 if(image->status==IMG_STATUS_INITIALIZED) return;
442
443 fprintf(stdout, "actual_plane_numbers := %d", image->planeNumber[0]);
444 for(int i=1; i<image->dimz; i++) fprintf(stdout, " %d", image->planeNumber[i]);
445 fprintf(stdout, "\n");
446 fprintf(stdout, "Frame times (sec):\n");
447 for(int i=0; i<image->dimt; i++) fprintf(stdout, " %e %e %e\n",
448 image->start[i], image->end[i], image->mid[i]);
449 if(image->isWeight) fprintf(stdout, "Frames are weighted.\n");
450 else fprintf(stdout, "Frames are not weighted.\n");
452 fprintf(stdout, "Decay correction factors for each frame:\n");
453 for(int i=0; i<image->dimt; i++)
454 fprintf(stdout, "%03i %e\n", i+1, image->decayCorrFactor[i]);
455 } else
456 fprintf(stdout, "Image is not decay corrected.\n");
457 return;
458}
char * ctime_r_int(const time_t *t, char *buf)
Convert calendard time t into a null-terminated string of the form YYYY-MM-DD hh:mm:ss,...
Definition datetime.c:110
char * imgUnit(int dunit)
Definition imgunits.c:315
#define IMG_DC_CORRECTED
#define IMG_STATUS_ERROR
#define MAX_STUDYNR_LEN
Definition libtpcmisc.h:163
int keyNr
Definition libtpcmisc.h:270
const char * statmsg

Referenced by ecat63AddImg(), img_k1_using_ki(), img_logan(), img_patlak(), imgAnalyzeToEcat(), imgNiftiToEcat(), imgReadAnalyzeFirstFrame(), imgReadEcat63FirstFrame(), imgReadEcat7FirstFrame(), imgReadFrame(), imgReadMicropetFirstFrame(), imgReadNifti(), and imgReadNiftiFirstFrame().

◆ imgInit()

void imgInit ( IMG * image)

Call this once before any use of IMG data.

See also
imgAllocate, imgEmpty
Parameters
imagePointer to IMG struct.

Definition at line 60 of file img.c.

63 {
64 if(IMG_TEST) printf("imgInit()\n");
65 if(image==NULL) return;
66 memset(image, 0, sizeof(IMG));
67 /*if(image->status!=IMG_STATUS_UNINITIALIZED) return;*/
69 imgSetStatus(image, STATUS_OK);
70 image->type=0;
71 image->unit=0;
72 image->calibrationFactor=0.0;
73 image->zoom=0.0;
74 image->radiopharmaceutical[0]=(char)0;
75 image->isotopeHalflife=0.0;
77 image->branchingFraction=0.0;
78 image->unit=0;
79 image->scanStart=0;
80 image->orientation=0;
81 image->axialFOV=image->transaxialFOV=image->sampleDistance=0.0;
82 image->studyNr[0]=image->patientName[0]=(char)0;
83 image->sizex=image->sizey=image->sizez=0;
84 image->_dataType=0;
85 image->_fileFormat=0;
86 image->scanner=0;
87 image->modality=0;
88 for(int i=0; i<2; i++) image->xform[i]=NIFTI_XFORM_UNKNOWN;
89 for(int i=0; i<18; i++) image->quatern[i]=0.0;
90 for(int i=0; i<12; i++) image->mt[i]=0.0;
91 iftInit(&image->ift);
92 image->polarmap_num_rings=0;
93 for(int i=0; i<MAX_POLARMAP_NUM_RINGS; i++) {
94 image->polarmap_sectors_per_ring[i]=0;
95 image->polarmap_ring_position[i]=0.0;
96 image->polarmap_ring_angle[i]=0;
97 }
98 image->polarmap_start_angle=0;
99 image->dimt=image->dimx=image->dimy=image->dimz=0;
100 image->gapx=image->gapy=image->gapz=0.0;
101 image->resolutionx=image->resolutiony=image->resolutionz=0.0;
102 image->m=(float****)NULL;
103 image->_header=(float*)NULL;
104 image->pixel=(float*)NULL;
105 image->column=(float**)NULL;
106 image->row=(float***)NULL;
107 image->plane=(float****)NULL;
108 image->planeNumber=(int*)NULL;
109 image->start=image->end=image->mid=(float*)NULL;
110 image->isWeight=0;
111 image->weight=image->sd=image->prompts=image->randoms=(float*)NULL;
112 image->decayCorrFactor=(float*)NULL;
113 image->errstatus=STATUS_OK;
114}
void iftInit(IFT *ift)
Definition ift.c:45

Referenced by imgAnalyzeToEcat(), imgFlipAbove(), imgFlipRight(), imgFormatDetermine(), imgMaskDilate(), imgMaskErode(), imgMicropetCTToEcat7(), imgMicropetPETToEcat7(), imgNiftiToEcat(), imgOutlierFilter(), imgPVCRRL(), imgPVCRVC(), imgReadFrame(), imgReadMinMax(), imgReadModelingData(), imgsegmSimilar(), imgThresholding(), imgThresholdingLowHigh(), imgWriteAnalyzeFrame(), imgWriteEcat63Frame(), imgWriteEcat7Frame(), and imgWriteNiftiFrame().

◆ imgNaNs()

unsigned long long imgNaNs ( IMG * img,
int fix )

Searches the image data for missing pixel values, optionally setting those to zero.

See also
imgExistentTimes
Returns
the number of missing pixel values.
Parameters
imgPointer to IMG structure.
fixSet (1) or do not set (0) missing pixels to zero.

Definition at line 658 of file img.c.

663 {
664 if(img==NULL) return(0);
665 unsigned long long n=0;
666 for(int zi=0; zi<img->dimz; zi++) {
667 for(int yi=0; yi<img->dimy; yi++) {
668 for(int xi=0; xi<img->dimx; xi++) {
669 for(int ti=0; ti<img->dimt; ti++) {
670 if(!isfinite(img->m[zi][yi][xi][ti])) {
671 n++;
672 if(fix!=0) img->m[zi][yi][xi][ti]=0.0;
673 }
674 }
675 }
676 }
677 }
678 return(n);
679}

◆ imgSetStatus()

void imgSetStatus ( IMG * img,
int status_index )

◆ imgStatus()

char * imgStatus ( int status_index)

Return pointer to string describing the image error status message

Parameters
status_indexindex of img_status_string
Returns
pointer to string

Definition at line 330 of file img.c.

330 {
331 int n=0;
332 while(imgmsg[n]!=0) n++;
333 if(status_index<0 || status_index>n-1) return((char*)imgmsg[STATUS_FAULT]);
334 else return((char*)imgmsg[status_index]);
335}

Referenced by ecatFixMatrixlist(), imgRead(), and imgWriteNifti().

Variable Documentation

◆ IMG_TEST