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