00001 #include <vector>
00002 #include "Basis/CmdOptions.h"
00003 #include "Basis/Timer.h"
00004 #include "Util/TimePlot.h"
00005 #include "Core/Array/Arrays.h"
00006 #include "Core/Array/Set.h"
00007 #include "Core/Array/RGB2Intensity.h"
00008 #include "Core/Array/GaussDerivative.h"
00009 #include "Core/Array/RecGauss.h"
00010 #include "Core/Array/RecGabor.h"
00011 #include "Core/Array/ReadRaw.h"
00012 #include "Core/Array/WriteRaw.h"
00013 #include "Core/Array/Norm2.h"
00014
00015 namespace Impala
00016 {
00017 namespace Samples
00018 {
00019 namespace Timing
00020 {
00021
00022
00023 using namespace Impala::Util;
00024 using namespace Impala::Core::Array;
00025
00026 void
00027 DoOneConvSep(String machineName, String srcName, int runCount)
00028 {
00029 Array2dVec3UInt8* srcData = 0;
00030 ReadRaw(srcData, srcName, &Util::Database::GetInstance());
00031 int borderSize = 39;
00032 Array2dScalarReal64* rData;
00033 rData = ArrayClone<Array2dScalarReal64>(srcData, borderSize, borderSize);
00034 RGB2Intensity(rData, srcData);
00035 delete srcData;
00036
00037 int f, g, i;
00038
00039 const int numFunc = 3;
00040 const int numGauss = 10;
00041 Array2dScalarReal64* gauss[numGauss];
00042 gauss[0] = MakeGaussian1d(1.0, 0, 2.0, 3);
00043 gauss[1] = MakeGaussian1d(1.0, 0, 3.0, 100);
00044 gauss[2] = MakeGaussian1d(1.0, 0, 5.0, 100);
00045 gauss[3] = MakeGaussian1d(1.7, 0, 4.0, 100);
00046 gauss[4] = MakeGaussian1d(2.3, 1, 4.0, 100);
00047 gauss[5] = MakeGaussian1d(2.7, 1, 4.0, 100);
00048 gauss[6] = MakeGaussian1d(3.2, 1, 4.0, 100);
00049 gauss[7] = MakeGaussian1d(3.7, 1, 4.0, 100);
00050 gauss[8] = MakeGaussian1d(4.2, 1, 4.0, 100);
00051 gauss[9] = MakeGaussian1d(4.7, 1, 4.0, 100);
00052 int gaussSize[numGauss];
00053 for (i=0 ; i<numGauss ; i++)
00054 gaussSize[i] = gauss[i]->CW();
00055 int nrSplitTimes = 5;
00056 TimePlot plotter(numFunc, numGauss, gaussSize, nrSplitTimes, runCount);
00057
00058 Array2dScalarReal64* res = ArrayClone<Array2dScalarReal64>(rData);
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 for (i=0 ; i<runCount ; i++)
00074 {
00075 for (g=0 ; g<numGauss ; g++)
00076 {
00077 for (f=0 ; f<numFunc ; f++)
00078 {
00079 plotter.Start(f, g, i);
00080 ConvKernelSeparated(res, rData, gauss[g], gauss[g], f, &plotter);
00081 plotter.Stop();
00082 }
00083 }
00084 }
00085
00086 String* funcName = new String[numFunc];
00087 funcName[0] = "0nai";
00088 funcName[1] = "1sim";
00089 funcName[2] = "2siminc";
00090
00091
00092
00093
00094
00095
00096
00097
00098 String baseName = srcName.substr(0, srcName.find('.'));
00099 plotter.SaveData(machineName, String("convsep"), baseName, funcName);
00100
00101 delete [] funcName;
00102 delete rData;
00103 delete res;
00104 }
00105
00106 void
00107 DoConvSep(int argc, char* argv[])
00108 {
00109 if (argc < 3)
00110 {
00111 std::cout << "convsep requires more arguments" << std::endl;
00112 return;
00113 }
00114 String machineName = String(argv[2]);
00115 DoOneConvSep(machineName, "trui_256.raw", 10);
00116 DoOneConvSep(machineName, "trui_255.raw", 5);
00117 DoOneConvSep(machineName, "trui_257.raw", 5);
00118 DoOneConvSep(machineName, "trui_352x288.raw", 5);
00119 DoOneConvSep(machineName, "trui_512.raw", 5);
00120 DoOneConvSep(machineName, "trui_720x576.raw", 5);
00121 DoOneConvSep(machineName, "trui_1280.raw", 5);
00122 }
00123
00124 void
00125 DoOneRecConvSep(String machineName, String srcName, int runCount)
00126 {
00127 Array2dVec3UInt8* srcData = 0;
00128 ReadRaw(srcData, srcName, &Util::Database::GetInstance());
00129 int borderSize = 22;
00130 Array2dScalarReal64* rData;
00131 rData = ArrayClone<Array2dScalarReal64>(srcData, borderSize, borderSize);
00132 RGB2Intensity(rData, srcData);
00133 delete srcData;
00134
00135 int f, g, i;
00136 const int numFunc = 1;
00137 const int numGauss = 5;
00138 Array2dScalarReal64* gauss[numGauss];
00139 gauss[0] = MakeGaussIIR1d(5.0, 0, 1);
00140 gauss[1] = MakeGaussIIR1d(5.0, 0, 2);
00141 gauss[2] = MakeGaussIIR1d(5.0, 0, 3);
00142 gauss[3] = MakeGaussIIR1d(5.0, 0, 4);
00143 gauss[4] = MakeGaussIIR1d(5.0, 0, 5);
00144 int gaussSize[numGauss];
00145 for (i=0 ; i<numGauss ; i++)
00146 gaussSize[i] = gauss[i]->CW();
00147 int nrSplitTimes = 4;
00148 TimePlot plotter(numFunc, numGauss, gaussSize, nrSplitTimes, runCount);
00149
00150 Array2dScalarReal64* res = ArrayClone<Array2dScalarReal64>(rData);
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 for (i=0 ; i<runCount ; i++)
00166 {
00167 for (g=0 ; g<numGauss ; g++)
00168 {
00169 for (f=0 ; f<numFunc ; f++)
00170 {
00171 plotter.Start(f, g, i);
00172 RecConvKernelSeparated(res, rData, gauss[g], gauss[g], &plotter);
00173 plotter.Stop();
00174 }
00175 }
00176 }
00177
00178 String* funcName = new String[numFunc];
00179 funcName[0] = "only variation";
00180
00181 String baseName = srcName.substr(0, srcName.find('.'));
00182 plotter.SaveData(machineName, String("recconvsep"), baseName, funcName);
00183
00184 delete [] funcName;
00185 delete rData;
00186 delete res;
00187 }
00188
00189 void
00190 DoRecConvSep(int argc, char* argv[])
00191 {
00192 if (argc < 3)
00193 {
00194 std::cout << "recconvsep requires more arguments" << std::endl;
00195 return;
00196 }
00197 String machineName = String(argv[2]);
00198 DoOneRecConvSep(machineName, "trui_256.raw", 10);
00199 DoOneRecConvSep(machineName, "trui_255.raw", 5);
00200 DoOneRecConvSep(machineName, "trui_257.raw", 5);
00201 DoOneRecConvSep(machineName, "trui_352x288.raw", 5);
00202 DoOneRecConvSep(machineName, "trui_512.raw", 5);
00203 DoOneRecConvSep(machineName, "trui_720x576.raw", 5);
00204 DoOneRecConvSep(machineName, "trui_1280.raw", 5);
00205 }
00206
00207 void
00208 DoOneRecConvSepComlex(String machineName, String srcName, int runCount)
00209 {
00210 Array2dVec3UInt8* srcData = 0;
00211 ReadRaw(srcData, srcName, &Util::Database::GetInstance());
00212 int borderSize = 22;
00213 Array2dScalarReal64* rData;
00214 rData = ArrayClone<Array2dScalarReal64>(srcData, borderSize, borderSize);
00215 RGB2Intensity(rData, srcData);
00216 delete srcData;
00217 Array2dComplex64* comData = 0;
00218 Set(comData, rData);
00219
00220 int f, g, i;
00221 const int numFunc = 2;
00222 const int numGabor = 1;
00223 Array2dComplex64* gabor;
00224 Complex64 leftBorder;
00225 Complex64 rightBorder;
00226 gabor = MakeGaborIIR1d(6.0, 1, leftBorder, rightBorder);
00227 int gaborSize = gabor->CW();
00228 int nrSplitTimes = 4;
00229 TimePlot plotter(numFunc, numGabor, &gaborSize, nrSplitTimes, runCount);
00230
00231 Array2dComplex64* res = ArrayClone<Array2dComplex64>(comData);
00232
00233 for (i=0 ; i<runCount ; i++)
00234 {
00235 for (g=0 ; g<numGabor ; g++)
00236 {
00237 for (f=0 ; f<numFunc ; f++)
00238 {
00239 plotter.Start(f, g, i);
00240 RecConvKernelSeparated(res, comData, gabor, gabor,
00241 leftBorder, rightBorder,
00242 leftBorder, rightBorder, &plotter);
00243 if (f == 1)
00244 Norm2(rData, res);
00245 plotter.Stop();
00246 }
00247 }
00248 }
00249
00250 String* funcName = new String[numFunc];
00251 funcName[0] = "recconvsepcomplex";
00252 funcName[1] = "recconvsepcomplex + norm";
00253
00254 String baseName = srcName.substr(0, srcName.find('.'));
00255 plotter.SaveData(machineName, String("recconvsepcomplex"), baseName,
00256 funcName);
00257
00258 delete [] funcName;
00259 delete rData;
00260 delete comData;
00261 delete res;
00262 }
00263
00264 void
00265 DoRecConvSepComlex(int argc, char* argv[])
00266 {
00267 if (argc < 3)
00268 {
00269 std::cout << "recconvsepcomplex requires more arguments" << std::endl;
00270 return;
00271 }
00272 String machineName = String(argv[2]);
00273 DoOneRecConvSepComlex(machineName, "trui_256.raw", 10);
00274 DoOneRecConvSepComlex(machineName, "trui_255.raw", 5);
00275 DoOneRecConvSepComlex(machineName, "trui_257.raw", 5);
00276 DoOneRecConvSepComlex(machineName, "trui_352x288.raw", 5);
00277 DoOneRecConvSepComlex(machineName, "trui_512.raw", 5);
00278 DoOneRecConvSepComlex(machineName, "trui_720x576.raw", 5);
00279 DoOneRecConvSepComlex(machineName, "trui_1280.raw", 5);
00280 }
00281
00282 void
00283 ShowUsage(char *progName)
00284 {
00285 std::cout
00286 << "Usage : " << std::endl
00287 << progName << " cmd [options for cmd]" << std::endl
00288 << " convsep machine" << std::endl
00289 << " recconvsep machine" << std::endl
00290 << " recconvsepcomplex machine" << std::endl
00291 ;
00292 }
00293
00294 int
00295 mainTiming(int argc, char* argv[])
00296 {
00297 if (argc < 2)
00298 {
00299 ShowUsage(argv[0]);
00300 return 1;
00301 }
00302
00303 String cmd = String(argv[1]);
00304 if (cmd == "convsep")
00305 DoConvSep(argc, argv);
00306 else if (cmd == "recconvsep")
00307 DoRecConvSep(argc, argv);
00308 else if (cmd == "recconvsepcomplex")
00309 DoRecConvSepComlex(argc, argv);
00310 else std::cout << "Unknown cmd : " << cmd << std::endl;
00311
00312 return 0;
00313 }
00314
00315 }
00316 }
00317 }
00318
00319 int
00320 main(int argc, char* argv[])
00321 {
00322 return Impala::Samples::Timing::mainTiming(argc, argv);
00323 }