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

Functions for finding peak voxel in PET image. More...

#include "libtpcidi.h"

Go to the source code of this file.

Functions

int imgGetConcWeightedPeakPos (IMG *img, float thrs, IMG_PIXEL *pos, int verbose)

Detailed Description

Functions for finding peak voxel in PET image.

Author
Vesa Oikonen

Definition in file peak.c.

Function Documentation

◆ imgGetConcWeightedPeakPos()

int imgGetConcWeightedPeakPos ( IMG * img,
float thrs,
IMG_PIXEL * pos,
int verbose )

Calculates concentration weighted peak position from a sum image.

See also
imgMaskPixelTACs, imgCircleMask, idiSimulateTubeVol
Returns
Returns 0 if successful.
Parameters
imgPointer to allocated image from which the peak position is searched. If IMG struct contains more than one times frame, then only the first one is used.
thrsThreshold fraction (0<thrs<1) between image min and max.
posPointer to pixel position structure.
verboseVerbose level; set to <=0 to prevent all prints to stdout and stderr.

Definition at line 14 of file peak.c.

24 {
25 if(verbose>0) printf("%s(img, %g, ...)\n", __func__, thrs);
26
27 int xi, yi, zi, fi=0;
28 float d, fmax, fmin, thrslev;
29 float px, py, pz, fsum;
30
31 if(img->status<IMG_STATUS_OCCUPIED) return(1);
32 if(img->dimz<1 || img->dimx<2 || img->dimy<2) return(2);
33 if(img->dimt<1) return(3);
34 if(thrs<=0.0 || thrs>=1.0) return(4);
35 if(pos==NULL) return(5);
36
37
38 /* Search min and max value inside the image volume */
39 zi=yi=xi=0; fmax=fmin=img->m[zi][yi][xi][fi];
40 for(zi=0; zi<img->dimz; zi++)
41 for(yi=0; yi<img->dimy; yi++)
42 for(xi=0; xi<img->dimx; xi++) {
43 if(img->m[zi][yi][xi][fi] > fmax) fmax=img->m[zi][yi][xi][fi];
44 else if(img->m[zi][yi][xi][fi] < fmin) fmin=img->m[zi][yi][xi][fi];
45 }
46 if(verbose>1) printf("fmin := %g\nfmax := %g\n", fmin, fmax);
47
48 /* Calculate threshold level from min and max */
49 d=fmax-fmin; if(d<=0.0) return(10);
50 thrslev=d*thrs+fmin; if(verbose>1) printf("thrslev := %g\n", thrslev);
51
52 /* Calculate concentration weighted peak position */
53 px=py=pz=0.0; fsum=0.0;
54 for(zi=0; zi<img->dimz; zi++)
55 for(yi=0; yi<img->dimy; yi++)
56 for(xi=0; xi<img->dimx; xi++) {
57 d=img->m[zi][yi][xi][fi]-thrslev;
58 if(d>0.0) {
59 px+=(float)(xi+1)*d;
60 py+=(float)(yi+1)*d;
61 pz+=(float)(zi+1)*d;
62 fsum+=d;
63 }
64 }
65 if(fsum<=0.0) return 5;
66 px/=fsum; py/=fsum; pz/=fsum;
67 if(verbose>1) printf("peak_pos := (%g,%g,%g)\n", px, py, pz);
68 pos->x=roundf(px); pos->y=roundf(py); pos->z=roundf(pz); pos->f=1;
69
70 return(0);
71}
#define IMG_STATUS_OCCUPIED
unsigned short int dimx
float **** m
char status
unsigned short int dimt
unsigned short int dimz
unsigned short int dimy