latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 1998, 1999, 2000, 2001 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 #ifndef _LTI_EXAMPLES 00024 #define _LTI_EXAMPLES 00025 00026 /** 00027 00028 \page examples Examples 00029 00030 Loading and processing an image in a file 00031 00032 \code 00033 // Example: Using the ltilib! 00034 00035 #include <iostream> 00036 #include <cstdio> 00037 #include <list> 00038 #include <cmath> 00039 00040 #include "ltiVector.h" 00041 #include "ltiMatrix.h" 00042 #include "ltiLogarithm.h" 00043 00044 #include "ltiTimer.h" 00045 00046 #include "ltiBMPFunctor.h" 00047 #include "ltiDownsampling.h" 00048 #include "ltiConvolution.h" 00049 #include "ltiGaussKernels.h" 00050 00051 #include "ltiSplitImg.h" 00052 #include "ltiMergeChnl.h" 00053 00054 using std::cout; 00055 using std::endl; 00056 00057 ... 00058 00059 void testfunction() { 00060 \endcode 00061 00062 ------------------------ 00063 simple matrix operations 00064 ------------------------ 00065 00066 \code 00067 cout << "Testing matrix operations and constructor..."; 00068 00069 // data to be used by a matrix 00070 double mdata[15] = { 1, 2, 3, 4, 5, 00071 6, 7, 8, 9, 10, 00072 11, 12, 13, 14, 15 }; 00073 00074 // create a matrix "a" and copy the data "mdata" on it. 00075 matrix<double> a(3,5,mdata); 00076 00077 // show the matrix 00078 cout << endl << "Matrix a: " << endl << a << endl; 00079 00080 // add -7 to all elements 00081 a.add(-7.0); 00082 00083 // apply the c-function fabs to all elements 00084 a.apply(fabs); 00085 00086 // show the resulting matrix 00087 cout << " After abs(x-7):" << endl; 00088 00089 cout << a << endl; 00090 00091 // add 0.5 to all elements 00092 a.add(0.5); 00093 00094 // create an instance of the logarithm-iterating functor, 00095 // which apply the log function to all elements of a mathVector 00096 lti::logarithm<double> lg; 00097 lg.apply(a); 00098 00099 // show the matrix after applying "log" to all of its elements 00100 cout << " After log(x+0.5):" << endl << a << endl; 00101 \endcode 00102 00103 --------------------- 00104 image procesing tests 00105 --------------------- 00106 00107 \code 00108 // create an instance of the image loading functor: 00109 lti::loadBMP loader; 00110 00111 lti::image img,img2; 00112 00113 // -- loading an image -- : shortcut 00114 00115 // load the given image using the shortcut! 00116 loader.load("img/leo040801_00_019.bmp",img); 00117 00118 // -- loading an image -- : the standard way 00119 00120 // the "standard" way uses the parameters-class of the functor 00121 // the functor requires a parameter object: 00122 lti::loadBMP::parameters loaderParam; 00123 00124 // give which file should be loaded 00125 loaderParam.filename = "img/leo040801_00_019.bmp"; 00126 00127 // tell the image-loader, which parameters should be used: 00128 loader.setParameters(loaderParam); 00129 00130 // load the image 00131 loader.apply(img2); 00132 00133 // -- extract a monochromatic channel of the image -- 00134 00135 // split image test 00136 00137 lti::channel chnl,chnl2; 00138 00139 // functor to split image in the chromaticity color space 00140 lti::splitImageTorgI splitter; 00141 00142 // extract the intensity channel only! 00143 splitter.getIntensity(img,chnl); 00144 00145 // -- Convolution and Filters -- 00146 00147 // 1D filter tests 00148 00149 cout << "Vector filter..."; 00150 00151 lti::vector<float> vct1(65536,0.5); 00152 lti::vector<float> vct2(65536,0.0f); 00153 00154 // create a gaussian kernel with 5 elements and a variance of 0.7 00155 lti::gaussKernel1D<float> gauss(5,0.7); 00156 00157 // the convolution functor: 00158 lti::convolution convolver; 00159 00160 // the parameters for the convolution functor 00161 lti::convolution::parameters param; 00162 00163 // indicate which kernel should be used 00164 param.setKernel(gauss); 00165 00166 // set the parameters 00167 convolver.setParameters(param); 00168 00169 // convolve the vector vct1 with the gaussian kernel 00170 convolver.apply(vct1,vct2); 00171 00172 // -- 2D separable filters -- 00173 00174 // create a (separable) column filter! 00175 00176 cout << "Creating separable filter..."; 00177 00178 sepKernel<float> sepKern; 00179 sepKern.setNumberOfPairs(1); 00180 // in a column filter, the row filter has only 1 element, with value 1 00181 sepKern.getRowFilter(0).resize(0,0,1,false); 00182 // use the gaussian kernel as the column filter 00183 sepKern.getColFilter(0).copy(gauss); 00184 00185 // indicate that now this column filter should be used 00186 param.setKernel(sepKern); 00187 convolver.setParameters(param); 00188 00189 // filter the intensity channel with this column filter 00190 convolver.apply(chnl,chnl2); 00191 00192 // -- 2D gaussian filter (separable) 00193 00194 // change the kernel to a complete 2D gaussian filter 00195 sepKern.copy(gaussKernel2D<float>(k)); 00196 00197 // indicate the convolution functor to use this kernel 00198 param.setKernel(sepKern); 00199 convolver.setParameters(param); 00200 00201 // convolve the channel with the 2D gaussian kernel 00202 convolver.apply(chnl,chnl2); 00203 00204 // -- 2D gaussian filter (matrix) 00205 00206 // create a 2D (non-separable) kernel 00207 kernel2D<float> gauss2D; 00208 gauss2D.outerProduct(sepKern.getRowFilter(0),sepKern.getColFilter(0)); 00209 00210 // indicate the convolution functor to use this kernel 00211 param.setKernel(gauss2D); 00212 convolver.setParameters(param); 00213 00214 // convolve the 2D kernel with the channel 00215 convolver.apply(chnl,chnl2); 00216 00217 // -- downsampling test 00218 00219 // create the downsampling functor (using the default parameters) 00220 lti::downsampling downsampler; 00221 00222 downsampler.apply(chnl,chnl2); 00223 00224 // create a viewer object to see the images 00225 lti::viewer view; 00226 00227 view.show(chnl2); 00228 00229 getchar(); // wait 'til the user hits a key 00230 00231 } 00232 00233 \endcode 00234 00235 */ 00236 00237 #endif 00238