Home || Visual Search || Applications || Architecture || Important Messages || OGL || Src

mainIm.cpp

Go to the documentation of this file.
00001 #include "Core/Array/AniGauss.h"
00002 #include "Core/Feature/Weibull.h"
00003 #include "Core/Array/ColorSegmentation.h"
00004 #include "Core/Array/ArrayListDelete.h"
00005 #include "Core/Array/Rotate.h"
00006 #include "Core/Array/WatershedMarkers2.h"
00007 #include "Core/Array/WatershedMarkers.h"
00008 #include "Core/Array/Watershed.h"
00009 #include "Core/Array/Norm2.h"
00010 #include "Core/Array/RecGabor.h"
00011 #include "Core/Array/TestEqual.h"
00012 #include "Core/Array/RecGauss.h"
00013 #include "Core/Array/RGB2Intensity.h"
00014 #include "Core/Array/GaussDerivative.h"
00015 #include "Core/Array/ReadFile.h"
00016 #include "Core/Array/WriteRaw.h"
00017 #include "Core/Array/WritePng.h"
00018 #include "Core/Array/ReadFile.h"
00019 #include "Core/Array/Arrays.h"
00020 #include "Core/Array/PrintData.h"
00021 #include "Core/Array/Set.h"
00022 #include "Core/Matrix/MatrixTem.h"
00023 #include "Core/Matrix/MatKMeans.h"
00024 #include "Core/Matrix/MatKLM.h"
00025 #include "Core/Matrix/MatTranspose.h"
00026 #include "Persistency/RepositoryInFileSystem.h"
00027 
00028 namespace Impala
00029 {
00030 namespace Application
00031 {
00032 namespace Im
00033 {
00034 
00035 using namespace Impala::Core::Array;
00036 
00037 void
00038 DoDump()
00039 {
00040     ILOG_VAR(Impala.Application.Im.DoDump);
00041     CmdOptions& options = CmdOptions::GetInstance();
00042     if (options.GetNrArg() < 2)
00043     {
00044         ILOG_ERROR("Need more arguments");
00045         return;
00046     }
00047     Util::Database* db = &Util::Database::GetInstance();
00048 
00049     String fileName = options.GetArg(1);
00050     bool doGenesis = false;
00051     if (options.GetNrArg() >= 3)
00052         doGenesis = true;
00053 
00054     // todo : -rect arg
00055 
00056     ArrayType aType = ReadRawArrayType(fileName, db);
00057     switch (aType)
00058     {
00059         case ARRAY2DSCALARUINT8: {
00060             Array2dScalarUInt8* a = 0;
00061             ReadRaw(a, fileName, db);
00062             PrintData(a, false, 0, 0, 10, 10);
00063             delete a;
00064             break;
00065         }
00066         case ARRAY2DSCALARREAL64: {
00067             Array2dScalarReal64* a = 0;
00068             ReadRaw(a, fileName, db);
00069             PrintData(a, false);
00070             if (doGenesis)
00071                 WriteRaw(a, "real64_b.raw", db, 1);
00072             //
00073             Array2dScalarInt32* b = 0;
00074             Set(b, a);
00075             PrintData(b, false);
00076             if (doGenesis)
00077                 WriteRaw(b, "int32.raw", db, 0);
00078 
00079             Array2dVec3UInt8* c = 0;
00080             Set(c, b);
00081             PrintData(c, false);
00082             if (doGenesis)
00083                 WriteRaw(c, "vec3uint8.raw", db, 0);
00084 
00085             Array2dComplex64* d = 0;
00086             Set(d, a);
00087             PrintData(d, false);
00088             if (doGenesis)
00089                 WriteRaw(d, "complex64.raw", db, 0);
00090             //
00091             delete a;
00092             break;
00093         }
00094         case ARRAY2DVEC3UINT8: {
00095             Array2dVec3UInt8* a = 0;
00096             ReadRaw(a, fileName, db);
00097             PrintData(a, false);
00098             if (doGenesis)
00099                 WriteRaw(a, "vec3uint8_b.raw", db, 1);
00100             delete a;
00101             break;
00102         }
00103         case ARRAY2DVEC2REAL64: { // we assume this to be complex
00104             Array2dComplex64* a = 0;
00105             ReadRaw(a, fileName, db);
00106             PrintData(a, false);
00107             if (doGenesis)
00108                 WriteRaw(a, "complex64_b.raw", db, 1);
00109             delete a;
00110             break;
00111         }
00112         default:
00113             ILOG_ERROR("Unknown ArrayType");
00114     }
00115 }
00116 
00117 void
00118 DoDumpCorners()
00119 {
00120     ILOG_VAR(Impala.Application.Im.DoDumpCorners);
00121     CmdOptions& options = CmdOptions::GetInstance();
00122     if (options.GetNrArg() < 4)
00123     {
00124         ILOG_ERROR("Need more arguments");
00125         return;
00126     }
00127 
00128     String fileName = options.GetArg(1);
00129     int cornerWidth = atol(options.GetArg(2));
00130     int cornerHeight = atol(options.GetArg(3));
00131 
00132     Persistency::FileLocator loc(fileName);
00133     typedef Persistency::RepositoryInFileSystem FS;
00134     Persistency::File file = FS::GetInstance().GetFile(loc, false, false);
00135     ArrayType aType = ReadRawArrayType(file);
00136     switch (aType)
00137     {
00138         case ARRAY2DSCALARUINT8: {
00139             Array2dScalarUInt8* a = 0;
00140             ReadRaw(a, file);
00141             PrintDataCorners(a, cornerWidth, cornerHeight);
00142             delete a;
00143             break;
00144         }
00145         case ARRAY2DSCALARREAL64: {
00146             Array2dScalarReal64* a = 0;
00147             ReadRaw(a, file);
00148             PrintDataCorners(a, cornerWidth, cornerHeight);
00149             delete a;
00150             break;
00151         }
00152         case ARRAY2DVEC3UINT8: {
00153             Array2dVec3UInt8* a = 0;
00154             ReadRaw(a, file);
00155             PrintDataCorners(a, cornerWidth, cornerHeight);
00156             delete a;
00157             break;
00158         }
00159         default:
00160             ILOG_ERROR("Unknown ArrayType");
00161     }
00162 }
00163 
00164 void
00165 DoJpg2Raw()
00166 {
00167     ILOG_VAR(Impala.Application.Im.DoJpg2Raw);
00168     CmdOptions& options = CmdOptions::GetInstance();
00169     if (options.GetNrArg() < 3)
00170     {
00171         ILOG_ERROR("Need more arguments");
00172         return;
00173     }
00174     Util::Database* db = &Util::Database::GetInstance();
00175 
00176     String jpgName = options.GetArg(1);
00177     String rawName = options.GetArg(2);
00178     int binary = 1;
00179     if (options.GetNrArg() >= 5)
00180         binary = atol(options.GetArg(4));
00181     Array2dVec3UInt8* data = 0;
00182     ReadJpg(data, jpgName, db);
00183     WriteRaw(data, rawName, db, binary);
00184     delete data;
00185 }
00186 
00187 void
00188 DoPng2Raw()
00189 {
00190     ILOG_VAR(Impala.Application.Im.DoPng2Raw);
00191     CmdOptions& options = CmdOptions::GetInstance();
00192     if (options.GetNrArg() < 3)
00193     {
00194         ILOG_ERROR("Need more arguments");
00195         return;
00196     }
00197     Util::Database* db = &Util::Database::GetInstance();
00198 
00199     String pngName = options.GetArg(1);
00200     String rawName = options.GetArg(2);
00201     int binary = 1;
00202     if (options.GetNrArg() >= 5)
00203         binary = atol(options.GetArg(4));
00204     Array2dVec3UInt8* data = 0;
00205     ReadPng(data, pngName, db);
00206     WriteRaw(data, rawName, db, binary);
00207     delete data;
00208 }
00209 
00210 template<class ArrayT>
00211 void
00212 DoTestEqualTem(ArrayT dummy, String name1, String name2, double eps)
00213 {
00214     ILOG_VAR(Impala.Application.Im.DoTestEqualTem);
00215     Util::Database* db = &Util::Database::GetInstance();
00216     std::vector<ArrayT*> src1;
00217     std::vector<ArrayT*> src2;
00218     ReadRawListVar(src1, name1, db);
00219     ReadRawListVar(src2, name2, db);
00220     
00221     if (src1.size() != src1.size())
00222     {
00223         ILOG_INFO("Number of array's differs");
00224     }
00225     else
00226     {
00227         if (src1.size() == 0)
00228             ILOG_INFO("List is empty");
00229         for (size_t i=0 ; i<src1.size() ; i++)
00230         {
00231             Array2dScalarReal64* res = 0;
00232             if (! TestEqual(res, src1[i], src2[i], eps))
00233                 ILOG_INFO("Arrays " << i << " differ");
00234             delete res;
00235         }
00236     }
00237     ArrayListDelete(&src1);
00238     ArrayListDelete(&src2);
00239 }
00240 
00241 void
00242 DoTestEqual()
00243 {
00244     ILOG_VAR(Impala.Application.Im.DoTestEqual);
00245     CmdOptions& options = CmdOptions::GetInstance();
00246     if (options.GetNrArg() < 3)
00247     {
00248         ILOG_ERROR("Need more arguments");
00249         return;
00250     }
00251     Util::Database* db = &Util::Database::GetInstance();
00252 
00253     String name1 = options.GetArg(1);
00254     String name2 = options.GetArg(2);
00255     double eps = 0.00001;
00256     if (options.GetNrArg() >= 5)
00257         eps = atof(options.GetArg(4));
00258 
00259     ArrayType type1 = ReadRawArrayType(name1, db);
00260     ArrayType type2 = ReadRawArrayType(name2, db);
00261     if (type1 != type2)
00262     {
00263         ILOG_INFO("ArrayType's differ");
00264         return;
00265     }
00266 
00267     switch (type1)
00268     {
00269     case ARRAY2DSCALARUINT8:
00270         DoTestEqualTem(Array2dScalarUInt8(), name1, name2, eps);
00271         break;
00272     case ARRAY2DSCALARINT32:
00273         DoTestEqualTem(Array2dScalarInt32(), name1, name2, eps);
00274         break;
00275     case ARRAY2DSCALARREAL64:
00276         DoTestEqualTem(Array2dScalarReal64(), name1, name2, eps);
00277         break;
00278     case ARRAY2DVEC3UINT8:
00279         DoTestEqualTem(Array2dVec3UInt8(), name1, name2, eps);
00280         break;
00281     default:
00282         ILOG_INFO("unknown array type");
00283     }
00284 }
00285 
00286 void
00287 DoNJetVec3UInt8()
00288 {
00289     ILOG_VAR(Impala.Application.Im.DoNJetVec3UInt8);
00290     CmdOptions& options = CmdOptions::GetInstance();
00291     if (options.GetNrArg() < 5)
00292     {
00293         ILOG_ERROR("Need more arguments");
00294         return;
00295     }
00296     Util::Database* db = &Util::Database::GetInstance();
00297 
00298     String dstName = options.GetArg(1);
00299     String srcName = options.GetArg(2);
00300     double sigma = atof(options.GetArg(3));
00301     double precision = atof(options.GetArg(4));
00302 
00303     Array2dVec3UInt8* srcData = 0;
00304     ReadRaw(srcData, srcName, db);
00305     Array2dScalarReal64* rData = 0;
00306     RGB2Intensity(rData, srcData);
00307     std::vector<Array2dScalarReal64*> resList;
00308     Timer timer(1);
00309 
00310     Array2dScalarReal64* res = 0;
00311     GaussDerivative(res, rData, sigma, 0, 0, precision);
00312     resList.push_back(res);
00313 
00314     res = 0;
00315     GaussDerivative(res, rData, sigma, 1, 0, precision);
00316     resList.push_back(res);
00317 
00318     res = 0;
00319     GaussDerivative(res, rData, sigma, 0, 1, precision);
00320     resList.push_back(res);
00321 
00322     res = 0;
00323     GaussDerivative(res, rData, sigma, 2, 0, precision);
00324     resList.push_back(res);
00325 
00326     res = 0;
00327     GaussDerivative(res, rData, sigma, 1, 1, precision);
00328     resList.push_back(res);
00329 
00330     res = 0;
00331     GaussDerivative(res, rData, sigma, 0, 2, precision);
00332     resList.push_back(res);
00333 
00334     ILOG_INFO("time: " << timer.SplitTime());
00335     WriteRawList(resList, dstName, db, true);
00336     delete srcData;
00337     delete rData;
00338     //delete res;
00339     ArrayListDelete(&resList);
00340 }
00341 
00342 void
00343 DoGaussVec3UInt8()
00344 {
00345     ILOG_VAR(Impala.Application.Im.DoGaussVec3UInt8);
00346     CmdOptions& options = CmdOptions::GetInstance();
00347     if (options.GetNrArg() < 7)
00348     {
00349         ILOG_ERROR("Need more arguments");
00350         return;
00351     }
00352     Util::Database* db = &Util::Database::GetInstance();
00353 
00354     String dstName = options.GetArg(1);
00355     String srcName = options.GetArg(2);
00356     double sigma = atof(options.GetArg(3));
00357     int derX = atol(options.GetArg(4));
00358     int derY = atol(options.GetArg(5));
00359     double precision = atof(options.GetArg(6));
00360 
00361     Array2dVec3UInt8* srcData = 0;
00362     ReadRaw(srcData, srcName, db);
00363     //Array2dScalarReal64* rData = 0;
00364     //RGB2Intensity(rData, srcData);
00365     Array2dVec3Real64* rData = 0;
00366     Set(rData, srcData);
00367     Timer timer(1);
00368     //Array2dScalarReal64* res = 0;
00369     Array2dVec3Real64* res = 0;
00370     //GaussDerivative(res, rData, sigma, derX, derY, precision);
00371     GaussDerivativeVec3(res, rData, sigma, derX, derY, precision);
00372     ILOG_INFO("time: " << timer.SplitTime());
00373     WriteRaw(res, dstName, db, 0);
00374     delete srcData;
00375     delete rData;
00376     delete res;
00377 }
00378 
00379 void
00380 DoRecGaussVec3UInt8()
00381 {
00382     ILOG_VAR(Impala.Application.Im.DoRecGaussVec3UInt8);
00383     CmdOptions& options = CmdOptions::GetInstance();
00384     if (options.GetNrArg() < 8)
00385     {
00386         ILOG_ERROR("Need more arguments");
00387         return;
00388     }
00389     Util::Database* db = &Util::Database::GetInstance();
00390 
00391     String dstName = options.GetArg(1);
00392     String srcName = options.GetArg(2);
00393     double sigmaX = atof(options.GetArg(3));
00394     double sigmaY = atof(options.GetArg(4));
00395     int derX = atol(options.GetArg(5));
00396     int derY = atol(options.GetArg(6));
00397     int recOrder = atof(options.GetArg(7));
00398 
00399     Array2dVec3UInt8* srcData = 0;
00400     ReadRaw(srcData, srcName, db);
00401     Array2dScalarReal64* rData = 0;
00402     RGB2Intensity(rData, srcData);
00403     Array2dScalarReal64* res = 0;
00404     RecGauss(res, rData, sigmaX, sigmaY, derX, derY, recOrder);
00405     WriteRaw(res, dstName, db, 1);
00406     delete srcData;
00407     delete rData;
00408     delete res;
00409 }
00410 
00411 void
00412 DoAniGaussVec3UInt8()
00413 {
00414     ILOG_VAR(Impala.Application.Im.DoAniGaussVec3UInt8);
00415     CmdOptions& options = CmdOptions::GetInstance();
00416     if (options.GetNrArg() < 8)
00417     {
00418         ILOG_ERROR("Need more arguments");
00419         return;
00420     }
00421     Util::Database* db = &Util::Database::GetInstance();
00422 
00423     String dstName = options.GetArg(1);
00424     String srcName = options.GetArg(2);
00425     Real64 sigmaV = atof(options.GetArg(3));
00426     Real64 sigmaU = atof(options.GetArg(4));
00427     Real64 phi = atof(options.GetArg(5));
00428     int derV = atol(options.GetArg(6));
00429     int derU = atol(options.GetArg(7));
00430 
00431     Array2dVec3UInt8* srcData = 0;
00432     ReadFile(srcData, srcName, db);
00433     Array2dScalarReal64* rData = 0;
00434     RGB2Intensity(rData, srcData);
00435     Array2dScalarReal64* res = 0;
00436     AniGauss(res, rData, sigmaV, sigmaU, phi, derV, derU);
00437     WriteRaw(res, dstName, db, 1);
00438     delete srcData;
00439     delete rData;
00440     delete res;
00441 }
00442 
00443 void
00444 DoRecGaborVec3UInt8()
00445 {
00446     ILOG_VAR(Impala.Application.Im.DoRecGaborVec3UInt8);
00447     CmdOptions& options = CmdOptions::GetInstance();
00448     if (options.GetNrArg() < 6)
00449     {
00450         ILOG_ERROR("Need more arguments");
00451         return;
00452     }
00453     Util::Database* db = &Util::Database::GetInstance();
00454 
00455     String dstName = options.GetArg(1);
00456     String srcName = options.GetArg(2);
00457     double s = atof(options.GetArg(3));
00458     double omega0 = atof(options.GetArg(4));
00459     double theta = atof(options.GetArg(5));
00460 
00461     Array2dVec3UInt8* srcData = 0;
00462     ReadRaw(srcData, srcName, db);
00463     Array2dScalarReal64* rData = 0;
00464     RGB2Intensity(rData, srcData);
00465     Array2dComplex64* comData = 0;
00466     Set(comData, rData);
00467     Array2dComplex64* res = 0;
00468     RecGabor(res, comData, s, omega0, theta);
00469     WriteRaw(res, dstName, db, 1);
00470     /*
00471     Array2dScalarReal64* norm = 0;
00472     norm = Norm2(norm, res);
00473     WriteRaw(norm, dstName+String("2"), db, 0);
00474     */
00475     delete srcData;
00476     delete rData;
00477     delete res;
00478 }
00479 
00480 void
00481 DoWatershedVec3UInt8()
00482 {
00483     ILOG_VAR(Impala.Application.Im.DoWatershedVec3UInt8);
00484     CmdOptions& options = CmdOptions::GetInstance();
00485     if (options.GetNrArg() < 4)
00486     {
00487         ILOG_ERROR("Need more arguments");
00488         return;
00489     }
00490     Util::Database* db = &Util::Database::GetInstance();
00491 
00492     String dstName = options.GetArg(1);
00493     String srcName = options.GetArg(2);
00494     int conn = atol(options.GetArg(3));
00495 
00496     Array2dVec3UInt8* srcData = 0;
00497     ReadRaw(srcData, srcName, db);
00498     Array2dScalarReal64* rData = 0;
00499     RGB2Intensity(rData, srcData);
00500     Array2dScalarInt32* intData = 0;
00501     Set(intData, rData);
00502     Array2dScalarInt32* res = 0;
00503     Watershed(res, intData, conn);
00504     WriteRaw(res, dstName, db, 1);
00505     delete srcData;
00506     delete rData;
00507     delete res;
00508 }
00509 
00510 void
00511 DoWatershedMarkersVec3UInt8()
00512 {
00513     ILOG_VAR(Impala.Application.Im.DoWatershedMarkersVec3UInt8);
00514     CmdOptions& options = CmdOptions::GetInstance();
00515     if (options.GetNrArg() < 6)
00516     {
00517         ILOG_ERROR("Need more arguments");
00518         return;
00519     }
00520     Util::Database* db = &Util::Database::GetInstance();
00521 
00522     String dstName = options.GetArg(1);
00523     String srcName = options.GetArg(2);
00524     String maskName = options.GetArg(3);
00525     int conn = atol(options.GetArg(4));
00526     int doLabel = atol(options.GetArg(5));
00527 
00528     Array2dVec3UInt8* srcData = 0;
00529     ReadRaw(srcData, srcName, db);
00530     Array2dScalarReal64* rData = 0;
00531     RGB2Intensity(rData, srcData);
00532     Array2dScalarInt32* intData = 0;
00533     Set(intData, rData);
00534 
00535     ReadRaw(srcData, maskName, db);
00536     RGB2Intensity(rData, srcData);
00537     Array2dScalarInt32* mIntData = 0;
00538     Set(mIntData, rData);
00539 
00540     Array2dScalarInt32* res = 0;
00541     WatershedMarkers(res, intData, mIntData, conn, doLabel != 0);
00542     WriteRaw(res, dstName, db, 1);
00543     delete srcData;
00544     delete rData;
00545     delete res;
00546 }
00547 
00548 void
00549 DoWatershedMarkers2Vec3UInt8()
00550 {
00551     ILOG_VAR(Impala.Application.Im.DoWatershedMarkers2Vec3UInt8);
00552     CmdOptions& options = CmdOptions::GetInstance();
00553     if (options.GetNrArg() < 7)
00554     {
00555         ILOG_ERROR("Need more arguments");
00556         return;
00557     }
00558     Util::Database* db = &Util::Database::GetInstance();
00559 
00560     String dstName = options.GetArg(1);
00561     String srcName = options.GetArg(2);
00562     String maskName = options.GetArg(3);
00563     int conn = atol(options.GetArg(4));
00564     int doLabel = atol(options.GetArg(5));
00565     int costMethod = atol(options.GetArg(6));
00566 
00567     Array2dVec3UInt8* srcData = 0;
00568     ReadRaw(srcData, srcName, db);
00569     Array2dScalarReal64* rData = 0;
00570     RGB2Intensity(rData, srcData);
00571     Array2dScalarInt32* intData = 0;
00572     Set(intData, rData);
00573 
00574     ReadRaw(srcData, maskName, db);
00575     RGB2Intensity(rData, srcData);
00576     Array2dScalarInt32* mIntData = 0;
00577     Set(mIntData, rData);
00578 
00579     Array2dScalarInt32* res = 0;
00580     WatershedMarkers2(res, intData, mIntData, conn, doLabel != 0, costMethod);
00581     WriteRaw(res, dstName, db, 1);
00582     delete srcData;
00583     delete rData;
00584     delete res;
00585 }
00586 
00587 void
00588 DoRotateVec3UInt8()
00589 {
00590     ILOG_VAR(Impala.Application.Im.DoRotateVec3UInt8);
00591     CmdOptions& options = CmdOptions::GetInstance();
00592     if (options.GetNrArg() < 7)
00593     {
00594         ILOG_ERROR("Need more arguments");
00595         return;
00596     }
00597     Util::Database* db = &Util::Database::GetInstance();
00598 
00599     String dstName = options.GetArg(1);
00600     String srcName = options.GetArg(2);
00601     double alpha = atof(options.GetArg(3));
00602     int geoInt = atol(options.GetArg(4));
00603     int adjustSize = atol(options.GetArg(5));
00604     int background = atol(options.GetArg(6));
00605 
00606     Array2dVec3UInt8* srcData = 0;
00607     ReadRaw(srcData, srcName, db);
00608     Array2dScalarReal64* rData = 0;
00609     RGB2Intensity(rData, srcData);
00610     Array2dScalarInt32* intData = 0;
00611     Set(intData, rData);
00612 
00613     Array2dVec3UInt8* res = 0;
00614     //Array2dVec3Real64* res = 0;
00615     Rotate(res, srcData, alpha,
00616            geoInt ? Core::Geometry::LINEAR : Core::Geometry::NEAREST,
00617            adjustSize != 0, E1Cast(background, Vec3Int32()));
00618 
00619     //Array2dScalarInt32* res = 0;
00620     //Array2dScalarReal64* res = 0;
00621     //Rotate(res, rData, alpha, geoInt ? LINEAR : NEAREST,
00622     //             adjustSize != 0, E1Cast(background, Real64()));
00623 
00624 
00625     WriteRaw(res, dstName, db, 0);
00626     delete srcData;
00627     delete rData;
00628     delete intData;
00629     delete res;
00630 }
00631 
00632 void
00633 DoWeibullW()
00634 {
00635     ILOG_VAR(Impala.Application.Im.DoWeibullW);
00636     CmdOptions& options = CmdOptions::GetInstance();
00637     if (options.GetNrArg() < 3)
00638     {
00639         ILOG_ERROR("Need more arguments");
00640         return;
00641     }
00642     Util::Database* db = &Util::Database::GetInstance();
00643 
00644     String imName = options.GetArg(1);
00645     double sigma = atof(options.GetArg(2));
00646 
00647     Array2dVec3UInt8* im = 0;
00648     ReadFile(im, imName, db);
00649     Core::Vector::VectorSet<Array2dScalarReal64>* vs = 0;
00650     vs = Core::Feature::Weibull(im, sigma);
00651     //vs->Dump();
00652     for (int i=0 ; i<vs->Size() ; i++)
00653     {
00654         Core::Vector::VectorTem<Real64> v = vs->GetVector(i, true);
00655         for (int j=0 ; j<v.Size() ; j++)
00656             std::cout << v[j] << " ";
00657     }
00658     std::cout << std::endl;
00659     delete im;
00660     delete vs;
00661 }
00662 
00663 void
00664 DoWeibullIRGB()
00665 {
00666     ILOG_VAR(Impala.Application.Im.DoWeibullIRGB);
00667     CmdOptions& options = CmdOptions::GetInstance();
00668     if (options.GetNrArg() < 3)
00669     {
00670         ILOG_ERROR("Need more arguments");
00671         return;
00672     }
00673     Util::Database* db = &Util::Database::GetInstance();
00674 
00675     String imName = options.GetArg(1);
00676     double sigma = atof(options.GetArg(2));
00677     bool doMu = false;
00678     if (options.GetNrArg() >= 4)
00679         doMu = (atol(options.GetArg(3)) != 0);
00680     bool doAnderson = false;
00681     if (options.GetNrArg() >= 5)
00682         doAnderson = (atol(options.GetArg(4)) != 0);
00683     bool doArjan = false;
00684     if (options.GetNrArg() >= 6)
00685         doArjan = (atol(options.GetArg(5)) != 0);
00686 
00687     Array2dVec3UInt8* im = 0;
00688     ReadFile(im, imName, db);
00689     Core::Vector::VectorSet<Array2dScalarReal64>* vs = 0;
00690     vs = Core::Feature::WeibullIRGB(im, sigma, doMu, doAnderson, doArjan);
00691     //vs->Dump();
00692     for (int i=0 ; i<vs->Size() ; i++)
00693     {
00694         Core::Vector::VectorTem<Real64> v = vs->GetVector(i, true);
00695         for (int j=0 ; j<v.Size() ; j++)
00696             std::cout << v[j] << " ";
00697     }
00698     std::cout << std::endl;
00699     delete im;
00700     delete vs;
00701 }
00702 
00703 void
00704 DoColorSegmentation()
00705 {
00706     ILOG_VAR(Impala.Application.Im.DoColorSegmentation);
00707     CmdOptions& options = CmdOptions::GetInstance();
00708     if (options.GetNrArg() < 3)
00709     {
00710         ILOG_ERROR("Need more arguments");
00711         return;
00712     }
00713     Util::Database* db = &Util::Database::GetInstance();
00714 
00715     String dstName = options.GetArg(1);
00716     String srcName = options.GetArg(2);
00717     double minRegionFraction = 0.01;
00718     if (options.GetNrArg() >= 4)
00719         minRegionFraction = atof(options.GetArg(3));
00720     double threshold = 6.0;
00721     if (options.GetNrArg() >= 5)
00722         threshold = atof(options.GetArg(4));
00723     ILOG_INFO("minRegionFraction = " << minRegionFraction
00724               << ", threshold = " << threshold);
00725 
00726     ColorSegmentationAlgorithm segAlg = TextureAddZero;
00727     ColorSegmentationInvariant invariantType = C;
00728 
00729     Array2dVec3UInt8* srcIm = 0;
00730     ReadFile(srcIm, srcName, db);
00731     Array2dVec3Real64* srcV3R64 =
00732         ArrayCreate<Array2dVec3Real64>(srcIm->CW(), srcIm->CH(), 15, 15);
00733     //MakeFromData2<Array2dVec3Real64,Array2dVec3UInt8>(srcV3R64,
00734     //                                                  srcIm->DataPtr());
00735     Set(srcV3R64, srcIm);
00736     Array2dVec3UInt8* dst = 0;
00737     ColorSegmentation(dst, srcV3R64, segAlg, invariantType, minRegionFraction,
00738                       threshold, false, 0);
00739     WritePng(dst, dstName, db);
00740     delete dst;
00741     delete srcV3R64;
00742     delete srcIm;
00743 }
00744 
00745 
00746 typedef Impala::Core::Matrix::MatrixTem<double> MatrixDouble;
00747 using namespace Impala::Core::Matrix;
00748 
00749 void
00750 PrMatrix(MatrixDouble m)
00751 {
00752     for (int r=0 ; r<m.nRow() ; r++)
00753     {
00754         for (int c=0 ; c<m.nCol() ; c++)
00755         {
00756             std::cout << "m[" << r << "][" << c << "] = " << m[r][c] << ", ";
00757         }
00758         std::cout << std::endl;
00759     }
00760 }
00761 
00762 void
00763 DoMatrix()
00764 {
00765     ILOG_VAR(Impala.Application.Im.DoMatrix);
00766     CmdOptions& options = CmdOptions::GetInstance();
00767     if (options.GetNrArg() < 3)
00768     {
00769         ILOG_ERROR("Need more arguments");
00770         return;
00771     }
00772     Util::Database* db = &Util::Database::GetInstance();
00773 
00774     String fileName = options.GetArg(1);
00775     int version = atol(options.GetArg(2));
00776 
00777     typedef Array2dScalarReal64 Mat;
00778     //typedef VecScalarReal64 Vec;
00779 
00780     Mat* m1 = 0;
00781     ReadRaw(m1, fileName, db);
00782     Mat* m2 = MatTranspose(m1);
00783     delete m1;
00784     MatrixDouble m(m2->mCH, m2->mCW, m2->mData);
00785     Timer timer(1);
00786     if (version == 1)
00787     {
00788         ILOG_INFO("time: " << timer.SplitTime() << " Array based ");
00789         //m1 = MatKLM(m2, 4);
00790         m1 = MatCovariance(m2, (Mat*) 0);
00791     }
00792     else
00793     {
00794         ILOG_INFO("time: " << timer.SplitTime() << " Matrix based ");
00795         //m = m.klm(4);
00796         VectorTem<double> v;
00797         m = m.covariance(v);
00798     }
00799 ILOG_INFO("time: " << timer.SplitTime());
00800 }
00801 
00802 void
00803 DoTest()
00804 {
00805     ILOG_VAR(Impala.Application.Im.DoTest);
00806     int i;
00807     double* ptr = new double[12];
00808     for (i=0 ; i<12 ; i++)
00809         ptr[i] = i;
00810     MatrixDouble m(3, 4, ptr);
00811     PrMatrix(m);
00812     m = m.t();
00813     PrMatrix(m);
00814 
00815     ILOG_INFO("========== New version =============");
00816     typedef Array2dScalarReal64 Mat;
00817 
00818     double* ptr2 = new double[12];
00819     for (i=0 ; i<12 ; i++)
00820         ptr2[i] = i;
00821     Mat* mm = Core::Matrix::MatCreate<Mat>(3, 4, ptr2); 
00822     PrintData(mm, false);
00823     Mat* mm2 = MatTranspose(mm);
00824     PrintData(mm2, false);
00825 }
00826 
00827 int
00828 mainIm(int argc, char* argv[])
00829 {
00830     CmdOptions& options = CmdOptions::GetInstance();
00831     options.Initialise(false, false, true);
00832     String usageStr = "cmd = \n\n";
00833     usageStr += "  dump rawFile [-genesis]\n";
00834     usageStr += "  dumpcorners rawFile cornerWidth cornerHeight\n";
00835     usageStr += "  jpg2raw jpgFile rawFile [-binary {0|1}]\n";
00836     usageStr += "  png2raw pngFile rawFile [-binary {0|1}]\n";
00837     usageStr += "  testequal im1File im2File [-eps value]\n";
00838     usageStr += "  njetvec3uint8 dstFile srcFile sigma precision\n";
00839     usageStr += "  gaussvec3uint8 dstFile srcFile sigma derX derY precision\n";
00840     usageStr += "  recgaussvec3uint8 dstFile srcFile sigmaX sigmaY derX derY order\n";
00841     usageStr += "  anigaussvec3uint8 dstFile srcFile sigmaV sigmaU phi derV derU\n";
00842     usageStr += "  recgaborvec3uint8 dstFile srcFile s omega0 theta\n";
00843     usageStr += "  watershedvec3uint8 dstFile srcFile conn\n";
00844     usageStr += "  watershedmarkersvec3uint8 dstFile srcFile maskFile conn doLabel\n";
00845     usageStr += "  rotate dstFile srcFile alpha geoInt adjustSize background\n";
00846     usageStr += "  weibullW imFile sigma\n";
00847     usageStr += "  weibullIRGB imFile sigma [doMu=0] [doAnderson=0] [doArjan=0]\n";
00848     usageStr += "  segment dstFile srcFile [minRegionFraction=0.01] [threshold=6.0]\n";
00849     usageStr += "  matrix srcFile version\n";
00850     if (! options.ParseArgs(argc, argv, usageStr, 1))
00851         return 1;
00852 
00853     ILOG_VAR(Impala.Application.Util.mainIm);
00854 
00855     int verbose = options.GetInt("verb");
00856     ArraySystem& aSys = ArraySystem::Instance();
00857     aSys.MarkMemoryUsage(verbose > 0);
00858 
00859     String cmd = options.GetArg(0);
00860     if (cmd == "dump")
00861         DoDump();
00862     else if (cmd == "dumpcorners")
00863         DoDumpCorners();
00864     else if (cmd == "jpg2raw")
00865         DoJpg2Raw();
00866     else if (cmd == "png2raw")
00867         DoPng2Raw();
00868     else if (cmd == "testequal")
00869         DoTestEqual();
00870     else if (cmd == "njetvec3uint8")
00871         DoNJetVec3UInt8();
00872     else if (cmd == "gaussvec3uint8")
00873         DoGaussVec3UInt8();
00874     else if (cmd == "recgaussvec3uint8")
00875         DoRecGaussVec3UInt8();
00876     else if (cmd == "anigaussvec3uint8")
00877         DoAniGaussVec3UInt8();
00878     else if (cmd == "recgaborvec3uint8")
00879         DoRecGaborVec3UInt8();
00880     else if (cmd == "watershedvec3uint8")
00881         DoWatershedVec3UInt8();
00882     else if (cmd == "watershedmarkersvec3uint8")
00883         DoWatershedMarkersVec3UInt8();
00884     else if (cmd == "watershedmarkers2vec3uint8")
00885         DoWatershedMarkers2Vec3UInt8();
00886     else if (cmd == "rotate")
00887         DoRotateVec3UInt8();
00888     else if (cmd == "weibullW")
00889         DoWeibullW();
00890     else if (cmd == "weibullIRGB")
00891         DoWeibullIRGB();
00892     else if (cmd == "segment")
00893         DoColorSegmentation();
00894     else if (cmd == "matrix")
00895         DoMatrix();
00896     else if (cmd == "test")
00897         DoTest();
00898     else ILOG_ERROR("Unknown cmd : " << cmd);
00899 
00900     aSys.CheckMemoryUsageSinceMark(verbose > 0);
00901 
00902     return 0;
00903 }
00904 
00905 } // namespace Im
00906 } // namespace Application
00907 } // namespace Impala
00908 
00909 int
00910 main(int argc, char* argv[])
00911 {
00912     return Impala::Application::Im::mainIm(argc, argv);
00913 }

Generated on Thu Jan 13 09:03:43 2011 for ImpalaSrc by  doxygen 1.5.1