1 /*****************************************************************************
2 Major portions of this software are copyrighted by the Medical College
3 of Wisconsin, 1994-2000, and are released under the Gnu General Public
4 License, Version 2. See the file README.Copyright for details.
5 ******************************************************************************/
6
7 #include "mrilib.h"
8
9 /*-----------------------------------------------------------------------------
10 Routine to edit cluster array.
11
12 clar = cluster array to be edited
13 edit_clust = flag to indicate cluster editing option
14 dxyz = volume of a voxel
15 vmul = minimum volume for a cluster
16
17 The edited cluster array is returned in clar.
18
19 Author : B. D. Ward
20 Date : 10 September 1996
21
22 Modified 09 June 1998 by RWCox to add ECFLAG_ORDER option.
23 and on 02 March 2010 by ZSS to add ECFLAG_DEPTH option.
24 -----------------------------------------------------------------------------*/
25
EDIT_cluster_array(MCW_cluster_array * clar,int edit_clust,float dxyz,float vmul)26 void EDIT_cluster_array (MCW_cluster_array * clar, int edit_clust,
27 float dxyz, float vmul)
28 {
29 int iclu; /* cluster index */
30 int nclu; /* non-empty cluster index */
31 int ii; /* voxel index */
32 float
33 mag, /* voxel intensity */
34 sum, /* sum of voxel intensities */
35 max, /* maximum of voxel intensities */
36 amax, /* maximum of absolute voxel intensities */
37 smax, /* signed maximum of absolute voxel intensities */
38 mean=0.0, /* mean of voxel intensities */
39 size=0.0; /* size of cluster (multiples of vmul) */
40
41 ENTRY("EDIT_cluster_array") ;
42
43 if( edit_clust == ECFLAG_ORDER){
44 SORT_CLARR(clar) ;
45 }
46
47 nclu = 0;
48 for (iclu = 0; iclu < clar->num_clu; iclu++)
49 {
50 if ((clar->clar[iclu] != NULL) && (clar->clar[iclu]->num_pt > 0))
51 {
52 nclu++;
53
54 /* initialization of basic statistics for this cluster */
55 sum = max = smax = clar->clar[iclu]->mag[0];
56 amax = fabs(smax);
57
58 /* calculate basic statistics for this cluster */
59 for (ii = 1; ii < clar->clar[iclu]->num_pt; ii++)
60 {
61 mag = clar->clar[iclu]->mag[ii];
62 switch (edit_clust)
63 {
64 case ECFLAG_MEAN :
65 sum += mag; break;
66 case ECFLAG_MAX :
67 if (mag > max) max = mag; break;
68 case ECFLAG_AMAX :
69 if (fabs(mag) > amax) amax = fabs(mag); break;
70 case ECFLAG_SMAX :
71 if (fabs(mag) > fabs(smax)) smax = mag; break;
72 case ECFLAG_SIZE : break;
73 case ECFLAG_DEPTH : break; /* handled outside of this function*/
74 default : break;
75 }
76
77 }
78
79 /* additional calculations */
80 if (edit_clust == ECFLAG_MEAN)
81 mean = sum / clar->clar[iclu]->num_pt;
82 if (edit_clust == ECFLAG_SIZE)
83 size = clar->clar[iclu]->num_pt * dxyz / vmul;
84
85 /* set all voxel intensities in this cluster to the same value */
86 for (ii = 0; ii < clar->clar[iclu]->num_pt; ii++)
87 {
88 switch (edit_clust)
89 {
90 case ECFLAG_MEAN : clar->clar[iclu]->mag[ii] = mean; break;
91 case ECFLAG_MAX : clar->clar[iclu]->mag[ii] = max; break;
92 case ECFLAG_AMAX : clar->clar[iclu]->mag[ii] = amax; break;
93 case ECFLAG_SMAX : clar->clar[iclu]->mag[ii] = smax; break;
94 case ECFLAG_SIZE : clar->clar[iclu]->mag[ii] = size; break;
95 case ECFLAG_ORDER: clar->clar[iclu]->mag[ii] = nclu; break;
96 case ECFLAG_DEPTH: break; /* Done outside, ZSS March 02 2010 */
97 default : break;
98 }
99 }
100
101 }
102 } /* iclu */
103
104 EXRETURN ;
105 }
106