TPCCLIB
Loading...
Searching...
No Matches
cluster_tac.c
Go to the documentation of this file.
1
5/*****************************************************************************/
6
7/*****************************************************************************/
8#include "libtpcmodext.h"
9/*****************************************************************************/
10
11/*****************************************************************************/
17 IMG *dimg,
19 IMG *cimg,
21 int nr,
23 DFT *tac,
25 int verbose
26) {
27 if(verbose>0) printf("clusterTACs(dimg, cimg, %d, tac, %d)\n", nr, verbose);
28
29 /* Check the arguments */
30 if(dimg==NULL || cimg==NULL || nr<1 || tac==NULL) return(1);
31 if(dimg->dimt<1 || cimg->dimt<1) return(1);
32 if(cimg->dimx!=dimg->dimx || cimg->dimy!=dimg->dimy || cimg->dimz!=dimg->dimz)
33 return(2);
34
35 /* Allocate memory for the TACs */
36 dftEmpty(tac);
37 if(dftSetmem(tac, dimg->dimt, nr+1)) return(3);
38
39 /* Set TAC info */
40 tac->voiNr=0; tac->frameNr=dimg->dimt; tac->_type=1;
41 for(int fi=0; fi<tac->frameNr; fi++) {
42 tac->x1[fi]=dimg->start[fi];
43 tac->x2[fi]=dimg->end[fi];
44 tac->x[fi] =dimg->mid[fi];
45 }
47 tac->timeunit=TUNIT_SEC;
48 strcpy(tac->unit, imgUnit(dimg->unit));
49
50 /* Calculate one cluster at a time */
51 float y[dimg->dimt];
52 int clusterID;
53 for(clusterID=1; clusterID<=nr; clusterID++) {
54 char buf[128]; snprintf(buf, 128, "%06d", clusterID);
55 char *p=buf+strlen(buf)-6;
56 snprintf(tac->voi[clusterID-1].voiname, MAX_REGIONSUBNAME_LEN+1, "%s", p);
57 int n=imgsegmClusterMean(dimg, cimg, clusterID, y, verbose);
58 if(verbose>1) printf(" clusterID%d -> %d pixels\n", clusterID, n);
59 if(n<0) return(5); else if(n==0) return(6);
60 for(int fi=0; fi<tac->frameNr; fi++) tac->voi[clusterID-1].y[fi]=(double)y[fi];
61 tac->voi[clusterID-1].size=(double)n*dimg->sizex*dimg->sizey*dimg->sizez;
62 tac->voiNr++;
63 }
64 /* and once more for cluster 0, i.e. the thresholded pixels; */
65 /* note that it is possible that there is no cluster 0 at all */
66 clusterID=0;
67 sprintf(tac->voi[tac->voiNr].voiname, "%06d", clusterID);
68 strcpy(tac->voi[tac->voiNr].name, tac->voi[tac->voiNr].voiname);
69 int n=imgsegmClusterMean(dimg, cimg, clusterID, y, verbose);
70 if(n<0) return(7);
71 if(n>0) {
72 for(int fi=0; fi<tac->frameNr; fi++) tac->voi[tac->voiNr].y[fi]=(double)y[fi];
73 tac->voi[tac->voiNr].size=(double)n*dimg->sizex*dimg->sizey*dimg->sizez;
74 tac->voiNr++;
75 }
76
77 return(0);
78}
79/*****************************************************************************/
80
81/*****************************************************************************/
int clusterTACs(IMG *dimg, IMG *cimg, int nr, DFT *tac, int verbose)
Definition cluster_tac.c:15
int dftSetmem(DFT *data, int frameNr, int voiNr)
Definition dft.c:57
void dftEmpty(DFT *data)
Definition dft.c:20
int imgsegmClusterMean(IMG *dimg, IMG *cimg, int clusterID, float *avg, int verbose)
Definition imgsegm.c:357
char * imgUnit(int dunit)
Definition imgunits.c:315
#define DFT_TIME_STARTEND
#define MAX_REGIONSUBNAME_LEN
Definition libtpcmisc.h:158
Header file for libtpcmodext.
int _type
int timetype
Voi * voi
int timeunit
double * x1
int voiNr
double * x2
int frameNr
double * x
char unit[MAX_UNITS_LEN+1]
float sizex
unsigned short int dimx
char unit
unsigned short int dimt
float sizey
float * start
unsigned short int dimz
unsigned short int dimy
float * end
float * mid
float sizez
double size
char voiname[MAX_REGIONSUBNAME_LEN+1]
double * y
char name[MAX_REGIONNAME_LEN+1]