36 int id = rhs[0].toInt();
37 string method(rhs[1].toString());
40 if (method ==
"new") {
41 nargchk(nrhs>=5 && (nrhs%2)==1 && nlhs<=1);
43 int histogram_bins = 5;
44 bool double_step =
false;
45 for (
int i=5; i<nrhs; i+=2) {
46 string key(rhs[i].toString());
48 prior = rhs[i+1].toInt();
49 else if (key ==
"HistogramBins")
50 histogram_bins = rhs[i+1].toInt();
51 else if (key ==
"DoubleStep")
52 double_step = rhs[i+1].toBool();
55 "Unrecognized option %s", key.
c_str());
58 if (sz.
size() != 2 && sz.
size() != 3)
60 int image_width = sz[1],
62 image_channels = (sz.
size() == 3 ? sz[2] : 1),
63 num_superpixels = rhs[3].toInt(),
64 num_levels = rhs[4].toInt();
66 image_width, image_height, image_channels,
67 num_superpixels, num_levels, prior, histogram_bins, double_step);
77 if (method ==
"delete") {
82 else if (method ==
"clear") {
86 else if (method ==
"load") {
87 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
89 bool loadFromString =
false;
90 for (
int i=3; i<nrhs; i+=2) {
91 string key(rhs[i].toString());
93 objname = rhs[i+1].toString();
94 else if (key ==
"FromString")
95 loadFromString = rhs[i+1].toBool();
98 "Unrecognized option %s", key.
c_str());
107 FileStorage fs(rhs[2].toString(), FileStorage::READ +
108 (loadFromString ? FileStorage::MEMORY : 0));
117 else if (method ==
"save") {
119 obj->
save(rhs[2].toString());
121 else if (method ==
"empty") {
125 else if (method ==
"getDefaultName") {
129 else if (method ==
"iterate") {
130 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
131 int num_iterations = 4;
132 for (
int i=3; i<nrhs; i+=2) {
133 string key(rhs[i].toString());
134 if (key ==
"NumIterations")
135 num_iterations = rhs[i+1].toInt();
138 "Unrecognized option %s", key.
c_str());
142 obj->
iterate(img, num_iterations);
144 else if (method ==
"getNumberOfSuperpixels") {
148 else if (method ==
"getLabels") {
154 else if (method ==
"getLabelContourMask") {
155 nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
156 bool thick_line =
false;
157 for (
int i=2; i<nrhs; i+=2) {
158 string key(rhs[i].toString());
159 if (key ==
"ThickLine")
160 thick_line = rhs[i+1].toBool();
163 "Unrecognized option %s", key.
c_str());
171 "Unrecognized operation %s", method.
c_str());
LIBMWMEX_API_EXTERN_C void mexLock(void)
Lock a MEX-function so that it cannot be cleared from memory.
virtual void getLabelContourMask(OutputArray image, bool thick_line=false)=0
virtual bool isOpened() const
struct mxArray_tag mxArray
Forward declaration for mxArray.
virtual void read(const FileNode &fn)
virtual int getNumberOfSuperpixels()=0
LIBMWMEX_API_EXTERN_C void mexErrMsgIdAndTxt(const char *identifier, const char *err_msg,...)
Issue formatted error message with corresponding error identifier and return to MATLAB prompt...
LIBMWMEX_API_EXTERN_C void mexUnlock(void)
Unlock a locked MEX-function so that it can be cleared from memory.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/output arguments number check.
FileNode getFirstTopLevelNode() const
virtual void getLabels(OutputArray labels_out)=0
virtual void iterate(InputArray img, int num_iterations=4)=0
virtual String getDefaultName() const
Global constant definitions.
Ptr< SuperpixelSEEDS > createSuperpixelSEEDS(int image_width, int image_height, int image_channels, int num_superpixels, int num_levels, int prior=2, int histogram_bins=5, bool double_step=false)
virtual void save(const String &filename) const
virtual bool empty() const
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
int last_id
Last object id to allocate.
map< int, Ptr< SuperpixelSEEDS > > obj_
Object container.