1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/PTdecode/CImg-1.3.0/examples/use_cimgmatlab.cpp Mon Aug 03 14:09:20 2009 +0100 1.3 @@ -0,0 +1,102 @@ 1.4 +/*----------------------------------------------------------------------- 1.5 + 1.6 + File : use_cimgmatlab.cpp 1.7 + 1.8 + Description: Example of use for the CImg plugin 'plugins/cimgmatlab.h' 1.9 + which allows to use CImg in order to develop matlab external 1.10 + functions (mex functions). 1.11 + User should be familiar with Matlab C/C++ mex function concepts, 1.12 + as this file is by no way a mex programming tutorial. 1.13 + 1.14 + This simple example implements a mex function that can be called 1.15 + as 1.16 + 1.17 + - v = cimgmatlab_cannyderiche(u,s) 1.18 + - v = cimgmatlab_cannyderiche(u,sx,sy) 1.19 + - v = cimgmatlab_cannyderiche(u,sx,sy,sz) 1.20 + 1.21 + The corresponding m-file is cimgmatlab_cannyderiche.m 1.22 + 1.23 + 1.24 + Copyright : Francois Lauze - http://www.itu.dk/people/francois 1.25 + This software is governed by the Gnu Lesser General Public License 1.26 + see http://www.gnu.org/copyleft/lgpl.html 1.27 + 1.28 + The plugin home page is at 1.29 + http://www.itu.dk/people/francois/cimgmatlab.html 1.30 + 1.31 + for the compilation: using the mex utility provided with matlab, just 1.32 + remember to add the -I flags with paths to CImg.h and/or cimgmatlab.h. 1.33 + The default lcc cannot be used, it is a C compiler and not a C++ one! 1.34 + 1.35 +--------------------------------------------------------------------------*/ 1.36 + 1.37 +#include <mex.h> 1.38 +#define cimg_plugin "plugins/cimgmatlab.h" 1.39 +#include <CImg.h> 1.40 + 1.41 +void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { 1.42 + if (nrhs < 2) mexErrMsgTxt("No enough input arguments."); 1.43 + if (nrhs > 4) mexErrMsgTxt("Too many input arguments."); 1.44 + cimg_library::CImg<> u(prhs[0],true); 1.45 + if (nrhs == 2) { 1.46 + const float s = (float)mxGetScalar(prhs[1]); 1.47 + plhs[0] = u.get_blur(s).toMatlab(); 1.48 + } else if (nrhs == 3) { 1.49 + const float sx = (float)mxGetScalar(prhs[1]); 1.50 + const float sy = (float)mxGetScalar(prhs[2]); 1.51 + plhs[0] = u.get_blur(sx,sy,0).toMatlab(); 1.52 + } else if (nrhs == 4) { 1.53 + const float sx = (float)mxGetScalar(prhs[1]); 1.54 + const float sy = (float)mxGetScalar(prhs[2]); 1.55 + const float sz = (float)mxGetScalar(prhs[3]); 1.56 + plhs[0] = u.get_blur(sx,sy,sz).toMatlab(); 1.57 + } 1.58 +} 1.59 + 1.60 +/*------------------------------------------------------------------ 1.61 + 1.62 + SPECIAL NOTE : 1.63 + ------------- 1.64 + 1.65 + How to read a .mat file using plugin 'cimgmatlab.h' ? 1.66 + (contribution by Vo Duc Khanh/Denso IT Lab, Tokyo, Japan). 1.67 + 1.68 + #include <mex.h> 1.69 + #include <mat.h> 1.70 + #include <matrix.h> 1.71 + 1.72 + #define cimg_plugin "cimgmatlab.h" 1.73 + 1.74 + #include "CImg.h" 1.75 + #include <iostream> 1.76 + #include <string> 1.77 + 1.78 + ......... 1.79 + 1.80 + using namespace cimg_library; 1.81 + using namespace std; 1.82 + 1.83 + // Load input images (125700 images) from training database 'BmpTrainingDb.mat' 1.84 + MATFile *pmat, *pmat_out; 1.85 + mxArray *pa, *pa_out; 1.86 + const char data_path[256] = ".\\BmpTrainingDb.mat\0"; 1.87 + const char *var_name; 1.88 + 1.89 + pmat = matOpen(data_path, "r"); 1.90 + if (pmat == NULL) { 1.91 + cout << "Error opening file " << data_path << endl; 1.92 + return (1); 1.93 + } 1.94 + 1.95 + pa = matGetNextVariable(pmat, &var_name); 1.96 + if (pa == NULL){ 1.97 + cout << "Error reading in file " << data_path << endl; 1.98 + return (1); 1.99 + } 1.100 + 1.101 + CImg<unsigned char> train_db(pa,false); 1.102 + ........ 1.103 + 1.104 + 1.105 + -----------------------------------------------------------------------------*/