# include <stdio.h>
# include <stdlib.h>
# include "mex.h"        
# include "math.h"
# define ROUND(x) (floor((x)+.5))
/* Compute pixel index in the vector that stores image */
int px(int x, int y, int lengthx, int lengthy)  /* the image is lengthx*lengthy */
{            
   return (x + (y-1)*lengthx - 1); 
 }
 /* variables */
float *I, *J;               
int sx, sy; 
/* copy images */
void CopyImage()
{
   
   int x, y, here; 
   
   for (x=1; x<=sx; x++)
       for (y=1; y<=sy; y++)
       {
        here = px(x, y, sx, sy); 
        I[here] = J[here];
       }
}
/* read in images */  
void mexFunction(int nlhs, mxArray *plhs[], 
                 int nrhs, const mxArray *prhs[])                
{
 int c; 
 
 c = 0;
 I = mxGetPr(prhs[c++]);
 J = mxGetPr(prhs[c++]);
 sx = ROUND(mxGetScalar(prhs[c++]));
 sy = ROUND(mxGetScalar(prhs[c++]));   
 CopyImage();
}

     



 

                    