TPCCLIB
Loading...
Searching...
No Matches
idimask.c
Go to the documentation of this file.
1
5/*****************************************************************************/
6#include "libtpcidi.h"
7/*****************************************************************************/
8
9/*****************************************************************************/
19 IMG *img,
22 IMG *mask,
24 double thrs,
27 DFT *dft,
29 int verbose
30) {
31 if(verbose>0) printf("%s()\n", __func__);
32
33 int xi, yi, zi, fi, ri, ret;
34
35 if(img->status<IMG_STATUS_OCCUPIED) return(1);
36 if(mask->status<IMG_STATUS_OCCUPIED) return(2);
37 if(mask->dimz!=img->dimz) return(3);
38 if(mask->dimy!=img->dimy) return(4);
39 if(mask->dimx!=img->dimx) return(5);
40 if(img->dimt<1 || mask->dimt<1) return(6);
41 if(dft==NULL) return(7);
42
43 /* Delete any previous TAC data; do it first so that caller can check
44 the nr of extracted TACs inside DFT */
45 dftEmpty(dft);
46
47 /* Calculate the nr of voxels to extract */
48 long long nr=0;
49 for(zi=0; zi<mask->dimz; zi++)
50 for(yi=0; yi<mask->dimy; yi++)
51 for(xi=0; xi<mask->dimx; xi++)
52 if(mask->m[zi][yi][xi][0]>thrs) nr++;
53 if(verbose>1) printf("mask_pixel_nr := %lld\n", nr);
54 /* Return, if no voxels were marked in mask image */
55 if(nr==0) return(0);
56
57 /* Allocate memory for pixel TACs */
58 ret=dftAllocateWithIMG(dft, nr, img);
59 if(ret!=0) {
60 if(verbose>0) fprintf(stderr, "Error: cannot allocate memory for %lld pixel TACs.\n", nr);
61 return(10);
62 }
63 strcpy(dft->studynr, img->studyNr);
64
65 /* Save the pixel TACs in DFT */
66 ri=0;
67 for(zi=0; zi<mask->dimz; zi++)
68 for(yi=0; yi<mask->dimy; yi++)
69 for(xi=0; xi<mask->dimx; xi++) if(mask->m[zi][yi][xi][0]>thrs)
70 {
71 sprintf(dft->voi[ri].voiname, "%d", 1+xi);
72 sprintf(dft->voi[ri].hemisphere, "%d", 1+yi);
73 sprintf(dft->voi[ri].place, "%d", 1+zi);
74 sprintf(dft->voi[ri].name, "%d %d %d", 1+xi, 1+yi, 1+zi);
75 for(fi=0; fi<img->dimt; fi++) dft->voi[ri].y[fi]=img->m[zi][yi][xi][fi];
76 dft->voi[ri].size=mask->m[zi][yi][xi][0];
77 ri++;
78 }
79 dft->voiNr=ri;
80
81 return(0);
82}
83/*****************************************************************************/
84
85/*****************************************************************************/
void dftEmpty(DFT *data)
Definition dft.c:20
int imgMaskPixelTACs(IMG *img, IMG *mask, double thrs, DFT *dft, int verbose)
Definition idimask.c:17
Header file for libtpcidi.
#define IMG_STATUS_OCCUPIED
int dftAllocateWithIMG(DFT *dft, int tacNr, IMG *img)
Definition misc_model.c:296
Voi * voi
char studynr[MAX_STUDYNR_LEN+1]
int voiNr
unsigned short int dimx
float **** m
char status
unsigned short int dimt
unsigned short int dimz
unsigned short int dimy
char studyNr[MAX_STUDYNR_LEN+1]
double size
char voiname[MAX_REGIONSUBNAME_LEN+1]
double * y
char name[MAX_REGIONNAME_LEN+1]
char hemisphere[MAX_REGIONSUBNAME_LEN+1]
char place[MAX_REGIONSUBNAME_LEN+1]