3
#include <fff_graphlib.h>
10
SYNTAX: [size, label, depth] = fffMat_clusters( XYZ, T );
12
Warning: the input array XYZ must be in C-compatible long int format
13
(most often, 32 bits or 64 bits).
15
The returned arrays (size, label, depth) are all C-compatible long int
20
void mexFunction( int nlhs, mxArray *plhs[],
21
int nrhs, const mxArray*prhs[] )
27
long *label, *bufL, *size;
28
gsl_vector_long depth;
29
int nvox, edges, clusters, maxima;
32
/* Check for proper number of arguments. */
34
mexErrMsgTxt("Two input arguments required.");
37
mexErrMsgTxt("Too many output arguments");
41
nvox = mxGetN( prhs[0] );
43
/* Consistency check */
44
if ( ( mxGetM( prhs[0] )!= 3 ) ||
45
( mxGetN( prhs[1] )!= nvox ) )
46
mexErrMsgTxt("Inconsistent input arrays.");
48
/* Check input type */
49
if ( ! mxArray_is_long( prhs[0], &mxLong ) )
50
mexErrMsgTxt("Input array XYZ is not in proper int format.");
56
XYZ.data = (long*) mxGetPr( prhs[0] );
61
T = gsl_vector_from_mxArray( prhs[1] );
64
plhs[1] = mxCreateNumericMatrix( nvox, 1, mxLong, mxREAL );
65
plhs[2] = mxCreateNumericMatrix( nvox, 1, mxLong, mxREAL );
67
/* Make a graph out of the input coordinates */
68
edges = fff_graph_grid( &G, &XYZ, 18 );
70
/* Assign cluster label to each voxel */
71
label = (long*) mxGetPr( plhs[1] );
72
clusters = fff_graph_cc_label( label, G );
74
/* Compute the cluster sizes */
75
plhs[0] = mxCreateNumericMatrix( clusters, 1, mxLong, mxREAL );
76
size = (long*) mxGetPr( plhs[0] );
78
for( j=0; j<nvox; j++, bufL++ ) {
81
*bufL = i+1; /* To return indices starting from 1... */
84
/* Compute depth for each voxel */
85
depth.size = (size_t) nvox;
87
depth.data = (long*) mxGetPr( plhs[2] );
90
maxima = fff_field_maxima( &depth, G, T );
93
fff_graph_delete( G );