MATLAB MEX function for scan conversion