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