mex to .m conversion or debugging in windows

Dear all,
I have a MEX file related problem in MATLAB.
I have accessed to an open source MATLAB code that I am trying to adapt to my work but actually I have no clue about C coding or MEX files.
Till now the function has been performing superbly but today I encountered a problem that I couldn't fix.
Basically, I am processing batches of images and at a certain point, I have this MEX file to perform a transverse for the spline fit on one of the images. Unfortunately, MATLAB directly crashes for this set of image and I couldn't find a solution. For the remaining sets of images I have no problem, just this one.
I was thinking, maybe the most optimal way to pass this problem is to convert MEX file to .m file (which will cost me more time to be processed but not very important at this point) or trying to find a way to debug in Windows. The other problem is I don't have enough C background, so debugging can be a bit tricky for me.
I tried to simplify the code as much as possible in case one of you tries to help me. The matlab part is just as follows for simplicity:
[pts_ind_t, kk] = skelTrans(skr, PtInit, PtEnd);
And the content of skelTrans is as follows:
#include "mex.h"
#include "matrix.h"
#include <stdlib.h>
#include <string.h>
void skelRetrive(int *skelTrk, double *LenTrk,
double *PtInit, double *PtEnd,
mxLogical *shapeMap, int m, int n)
{
/* Initialize the start & end points */
int k; /* skeleton length counter */
double xInit, yInit; /* Components of start & */
double xEnd , yEnd; /* end of the skeleton points */
int x , y; /* the pair of a skeleton points */
xInit = PtInit[0];
yInit = PtInit[1];
xEnd = PtEnd[0];
yEnd = PtEnd[1];
k = 0;
x = (int)xInit;
y = (int)yInit;
/* Tracking the skeleton via a clockwise direction */
while (!((x == (int)xEnd) && (y == (int)yEnd))) {
skelTrk[1+k*2] = x;
skelTrk[0+k*2] = y;
/* Column-majored storage */
shapeMap[x+y*m]= 0;
if (shapeMap[(x-1)+(y-1)*m]) {
x = x-1;
y = y-1;
k = k+1;
}
else if (shapeMap[x+(y-1)*m]) {
y = y-1;
k = k+1;
}
else if (shapeMap[(x+1)+(y-1)*m]){
x = x+1;
y = y-1;
k = k+1;
}
else if (shapeMap[(x-1)+(y)*m]) {
x = x-1;
k = k+1;
}
else if (shapeMap[(x+1)+(y)*m]) {
x = x+1;
k = k+1;
}
else if (shapeMap[(x-1)+(y+1)*m]){
x = x-1;
y = y+1;
k = k+1;
}
else if (shapeMap[x+(y+1)*m]) {
y = y+1;
k = k+1;
}
else if (shapeMap[(x+1)+(y+1)*m]){
x = x+1;
y = y+1;
k = k+1;
}
else {break;}
}
skelTrk[1+k*2] = x;
skelTrk[0+k*2] = y;
*LenTrk = k;
return;
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
int m, n;
int arr_size;
int *skelTrk; /* Tracks of the skeleton points */
double *PtInit, *PtEnd; /* The coordinates of initial and end points */
double *k;
mxArray *shapeImg;
mxLogical *shapeMap; /* The replicated segmented image */
/* mxArray *MexInput[1]; */
if(nrhs != 3)
mexErrMsgTxt("Need exactly one input argument\n");
if(!mxIsLogical(prhs[0]))
mexErrMsgTxt("Input argument must be logical\n");
if(mxGetNumberOfDimensions(prhs[0])!=2)
mexErrMsgTxt("Input argument has too many dimensions\n");
/* Retrieve the input and create the array */
/* Read in the start & end points, and the size of the array */
shapeImg= mxDuplicateArray(prhs[0]);
arr_size= mxGetNumberOfElements(prhs[0]);
PtInit = (double*)mxGetData(prhs[1]);
PtEnd = (double*)mxGetData(prhs[2]);
/* Make a copy of the segmented image of the skeleton */
m = mxGetM(prhs[0]);
n = mxGetN(prhs[0]);
shapeMap= mxGetLogicals(shapeImg);
arr_size= mxGetNumberOfElements(shapeMap);
plhs[0] = mxCreateNumericMatrix(0, 0, mxINT32_CLASS, mxREAL);
mxSetM(plhs[0], 2);
mxSetN(plhs[0], 1000);
mxSetData(plhs[0], mxMalloc(4*2*1000));
skelTrk = (int *)mxGetData(plhs[0]);
plhs[1] = mxCreateNumericMatrix(1,1, mxDOUBLE_CLASS, mxREAL);
k = (double *)mxGetData(plhs[1]);
skelRetrive(skelTrk, k, PtInit, PtEnd, shapeMap, m, n);
mxDestroyArray(shapeImg);
}
I attached a sample .mat file that can be used to run this file.
As a side information, I am using Windows x64.
Thanks for your help in advance.
Best regards,
Baris

Respuestas (0)

Etiquetas

Preguntada:

el 6 de Feb. de 2017

Editada:

el 6 de Feb. de 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by