As being well known, the computational speed for a code running under under MATLAB is slower than that under C or Fortran, generally. The easiest remedy here is to use `MCC MATLAB to C/C++ Compiler'. Since most of CPU time is consumed when running the correlation or MQD functions (as well as the median filter and Kriging interpolation) in mpiv, the MATLAB-to-C compiler is suggested to be used only for these functions. A typical command is
>> mcc -x piv_crsThe C-complied .mex?? format files have higher preference than the original .m format files when running MATLAB, even if they are both placed in the same directory.
The following is a list of CPU time-consuming functions in mpiv.
func_findpeak2.m piv_mqd.m piv_mqr.m piv_mrs.m piv_cor.m piv_crr.m piv_crs.m vector_filter_median.m xcorr2.m
The following is an example for running the C-complied mpiv using the sample images:
>> mcc -x piv_mqd
>> im1 = imread('image1.bmp');
>> im2 = imread('image2.bmp');
>> tic; [xi, yi, iu, iv] = mpiv(im1, im2, 32, 32, 0.5, 0.5, 20, 20, 1,'mqd', 2, 1); toc
>> [iu_ft,iv_ft,iu_ip,iv_ip]=mpiv_filter(iu, iv, 2, 2.0, 3, 1);
In this example, the CPU time was reduced from 29.7 second originally to 19.1
second with the mex files piv_mqd.m (on an AMD Athlon 2000+).
Using the MATLAB-to-C complier, mpiv saves 36% of time in comparison to the same
MATLAB program without using the compiler.
We would like to point out that the two-dimensional correlation algorithm in the program uses the MATLAB function `xcorr2' to compute the cross-correlation function. However, xcorr2.m in MATLAB does not use fast Fourier transform (FFT) therefore it is relatively slow. We replaced xcorr2.m to another faster routine for correlation computation applying FFT, CPU time is found to be greatly reduced (we cannot include this file in the mpiv toolbox due to copyright issue because it was directly modified from xcorr2.m).