
#define mat(a, nrows, i, j) (*(a + (nrows*(j)+i)))


/* Copy matlab mex image memory segment to a Pandore image.
*/
void mex2pan(Float* input, int m, int n, Img2dsf& imdest)
{
  imdest.New(m,n);
  for(int i=0;i < m;i++)
  for(int j=0;j < n;j++){
   	imdest[i][j] = mat(input, m, i, j);
  }
}

/* Copy matlab Pandore image into a mex image memory segment.
   output array vector is supposed to be correctly allocated.
*/
void pan2mex(Img2dsf& imsrc, Float* output)
{
  int m = imsrc.Height();
  int n = imsrc.Width();
  for(int i=0;i < m;i++)
  for(int j=0;j < n;j++){
   	mat(output, m, i, j) = imsrc[i][j];
  }
}
