/
watershed_matlab.cpp
65 lines (52 loc) · 1.59 KB
/
watershed_matlab.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*!
* \file watershed_matlab.cpp
* \brief a cpp interface to use the vincent_soille_watershed class (in libwatershed.so)
* \author jwojak
*/
#include "mex.h"
#include "cppimage.h"
#include "vincent_soille_watershed.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
size_t nb_row=0, nb_col=0;
double *input_image;
double *output_image;
double *connectivity;
vincent_soille_watershed vsw;
if(nrhs<1)
{
mexPrintf(" watershed_matlab mex not enough input arg");
return;
}
mexPrintf("number of input args %d \n", nrhs);
nb_row = mxGetN(prhs[0]);
nb_col = mxGetM(prhs[0]);
mexPrintf("input image size [%d, %d] \n", nb_row, nb_col);
input_image = mxGetPr(prhs[0]);
if(nrhs>=2)
{
connectivity = mxGetPr(prhs[1]);
}
else
{
connectivity =(double *)mxMalloc(sizeof(double)) ;
connectivity[0] = 4.0;
}
cppimage input_watershed_image(nb_row, nb_col, input_image);
//input_watershed_image.display_image_tab();
vsw.process_watershed_algo(input_watershed_image, (int)connectivity[0]);
//mexPrintf("ON FAIT LA SAUVEGARDE %d \n" ,nb_row*nb_col);
output_image = (double *)mxMalloc( (nb_row*nb_col)*sizeof(double));
vsw.get_labelled_array(output_image);
plhs[0] = mxCreateNumericMatrix(0, 0, mxDOUBLE_CLASS, mxREAL);
mxSetPr(plhs[0], output_image);
mxSetN(plhs[0], nb_row);
mxSetM(plhs[0], nb_col);
/* nb_col = mxGetN(prhs[1]);
std::cout<<"input image size = [" << nb_row << ", " << nb_col <<"]" << std::endl;*/
if(nrhs < 2)
{
mxFree(connectivity);
}
return;
}