00001 #define TEAGN_ENABLE_STDOUT_LOG
00002
00003 #include <TePDIExamplesBase.hpp>
00004
00005 #include <TePDIMIMatching.hpp>
00006 #include <TePDIUtils.hpp>
00007
00008 #include <TeProgress.h>
00009 #include <TeStdIOProgress.h>
00010 #include <TeAgnostic.h>
00011
00012 #include <math.h>
00013
00014
00015 void raster2Tiff(
00016 const TePDITypes::TePDIRasterPtrType& input_raster_ptr,
00017 unsigned int raster_channel,
00018 const std::string& out_file_name,
00019 TeSharedPtr< TeCoordPairVect > out_tie_points_ptr,
00020 unsigned int tie_points_space )
00021 {
00022 TEAGN_TRUE_OR_THROW( ( ! out_file_name.empty() ),
00023 "Invalid file name" )
00024 TEAGN_TRUE_OR_THROW( ( input_raster_ptr->params().nlines_ > 0 ),
00025 "Invalid matrix lines" )
00026 TEAGN_TRUE_OR_THROW( ( input_raster_ptr->params().ncols_ > 0 ),
00027 "Invalid matrix cols" )
00028
00029 TeRasterParams params;
00030 params.setNLinesNColumns( input_raster_ptr->params().nlines_,
00031 input_raster_ptr->params().ncols_ );
00032 params.nBands( 1 );
00033 params.setDataType( TeUNSIGNEDCHAR, -1 );
00034 params.nBands( 1 );
00035 params.decoderIdentifier_ = "TIF";
00036 params.mode_ = 'c';
00037 params.fileName_ = out_file_name;
00038
00039 TeRaster out_raster( params );
00040 TEAGN_TRUE_OR_THROW( out_raster.init(), "Error init raster" );
00041 double value = 0;
00042
00043 for( int line = 0 ;
00044 line < input_raster_ptr->params().nlines_ ; ++line ) {
00045 for( int col = 0 ;
00046 col < input_raster_ptr->params().ncols_ ;
00047 ++col ) {
00048
00049 input_raster_ptr->getElement( col, line, value,
00050 raster_channel );
00051
00052
00053 TEAGN_TRUE_OR_THROW( out_raster.setElement( col, line,
00054 value, 0 ),
00055 "Error writing raster" )
00056 }
00057 }
00058
00059
00060
00061 if( out_tie_points_ptr.isActive() ) {
00062 TeCoordPairVect::iterator it = out_tie_points_ptr->begin();
00063 TeCoordPairVect::iterator it_end = out_tie_points_ptr->end();
00064
00065 while( it != it_end ) {
00066 int x = 0;
00067 int y = 0;
00068
00069 if( tie_points_space == 0 ) {
00070 x = TeRound( it->pt1.x() );
00071 y = TeRound( it->pt1.y() );
00072 } else {
00073 x = TeRound( it->pt2.x() );
00074 y = TeRound( it->pt2.y() );
00075 }
00076
00077 TEAGN_TRUE_OR_THROW( ( x < input_raster_ptr->params().ncols_ ),
00078 "Invalid maxima column" )
00079 TEAGN_TRUE_OR_THROW( ( x >= 0 ),
00080 "Invalid maxima column" )
00081 TEAGN_TRUE_OR_THROW( ( y < input_raster_ptr->params().nlines_ ),
00082 "Invalid maxima line" )
00083 TEAGN_TRUE_OR_THROW( ( y >= 0 ),
00084 "Invalid maxima line" )
00085
00086 TEAGN_TRUE_OR_THROW( out_raster.setElement( x, y,
00087 255.0, 0 ),
00088 "Error writing raster" )
00089
00090 ++it;
00091 }
00092
00093 }
00094 }
00095
00096 void sameImageTest()
00097 {
00098
00099
00100 TePDIParameters params;
00101
00102 TePDITypes::TePDIRasterPtrType input_image1_ptr( new TeRaster(
00103 std::string( TEPDIEXAMPLESRESPATH "cbers_rgb342_crop1.tif" ), 'r' ) );
00104 TEAGN_TRUE_OR_THROW( input_image1_ptr->init(),
00105 "Unable to init input_image1_ptr" );
00106 params.SetParameter( "input_image1_ptr" , input_image1_ptr );
00107
00108 params.SetParameter( "input_channel1" , (unsigned int)0 );
00109
00110 TePDITypes::TePDIRasterPtrType input_image2_ptr( new TeRaster(
00111 std::string( TEPDIEXAMPLESRESPATH "cbers_rgb342_crop1.tif" ), 'r' ) );
00112 TEAGN_TRUE_OR_THROW( input_image2_ptr->init(),
00113 "Unable to init input_image2_ptr" );
00114 params.SetParameter( "input_image2_ptr" , input_image2_ptr );
00115
00116 params.SetParameter( "input_channel2" , (unsigned int)0 );
00117
00118 TeSharedPtr< TeCoordPairVect > out_tie_points_ptr( new TeCoordPairVect );
00119 params.SetParameter( "out_tie_points_ptr" , out_tie_points_ptr );
00120
00121 TeBox input_box1( TeCoord2D( 142, 826 ) ,
00122 TeCoord2D( 542, 426 ) );
00123 params.SetParameter( "input_box1" , input_box1 );
00124
00125 TeBox input_box2( TeCoord2D( 238, 689 ) ,
00126 TeCoord2D( 391, 473 ) );
00127 params.SetParameter( "input_box2" , input_box2 );
00128
00129 params.SetParameter( "enable_multi_thread" , (int)1 );
00130
00131 params.SetParameter( "pixel_x_relation" , (double)1 );
00132 params.SetParameter( "pixel_y_relation" , (double)1 );
00133
00134 TePDIMIMatching match_instance;
00135 match_instance.ToggleProgInt( true );
00136 TEAGN_TRUE_OR_THROW( match_instance.Reset( params ),
00137 "Algorithm reset error" )
00138
00139 TEAGN_LOGMSG( "Algorithm started" )
00140
00141 time_t init_time = clock() / CLOCKS_PER_SEC;
00142
00143 TEAGN_TRUE_OR_THROW( match_instance.Apply(),
00144 "Algorithm apply error" )
00145
00146 time_t end_time = clock() / CLOCKS_PER_SEC;
00147
00148 TEAGN_LOGMSG( "Time elapsed (sameImageDifBoxesTest): " +
00149 TeAgnostic::to_string( (long int)( end_time - init_time ) ) +
00150 " seconds" );
00151
00152
00153 {
00154 TeCoordPairVect::iterator it = out_tie_points_ptr->begin();
00155 TeCoordPairVect::iterator it_end = out_tie_points_ptr->end();
00156
00157 while( it != it_end ) {
00158 std::cout << "[" + Te2String( it->pt1.x(),1 ) + " , " +
00159 Te2String( it->pt1.y(),1 ) + "] -> [" +
00160 Te2String( it->pt2.x(),1 ) + " , " +
00161 Te2String( it->pt2.y(),1 ) + "]" << std::endl;
00162
00163 ++it;
00164 }
00165 }
00166
00167
00168
00169 raster2Tiff( input_image1_ptr, 0, TEPDIEXAMPLESBINPATH
00170 "TeMIMatching_test_sameImageTest_input_image1.tif",
00171 out_tie_points_ptr, 0 );
00172 raster2Tiff( input_image2_ptr, 0, TEPDIEXAMPLESBINPATH
00173 "TeMIMatching_test_sameImageTest_input_image2.tif",
00174 out_tie_points_ptr, 1 );
00175
00176 TEAGN_WATCH( (unsigned int)out_tie_points_ptr->size() );
00177 TEAGN_CHECK_EPS( 4, out_tie_points_ptr->size(),
00178 0, "Invalid tie-points number" )
00179 }
00180
00181
00182 void sameImageTest2()
00183 {
00184
00185
00186 TePDIParameters params;
00187
00188 TePDITypes::TePDIRasterPtrType input_image1_ptr( new TeRaster(
00189 std::string( TEPDIEXAMPLESRESPATH "cbers_rgb342_crop1.tif" ), 'r' ) );
00190 TEAGN_TRUE_OR_THROW( input_image1_ptr->init(),
00191 "Unable to init input_image1_ptr" );
00192 params.SetParameter( "input_image1_ptr" , input_image1_ptr );
00193
00194 params.SetParameter( "input_channel1" , (unsigned int)0 );
00195
00196 TePDITypes::TePDIRasterPtrType input_image2_ptr( new TeRaster(
00197 std::string( TEPDIEXAMPLESRESPATH "cbers_rgb342_crop1.tif" ), 'r' ) );
00198 TEAGN_TRUE_OR_THROW( input_image2_ptr->init(),
00199 "Unable to init input_image2_ptr" );
00200 params.SetParameter( "input_image2_ptr" , input_image2_ptr );
00201
00202 params.SetParameter( "input_channel2" , (unsigned int)0 );
00203
00204 TeSharedPtr< TeCoordPairVect > out_tie_points_ptr( new TeCoordPairVect );
00205 params.SetParameter( "out_tie_points_ptr" , out_tie_points_ptr );
00206
00207 TeBox input_box2( TeCoord2D( 142, 826 ) ,
00208 TeCoord2D( 542, 426 ) );
00209 params.SetParameter( "input_box2" , input_box2 );
00210
00211 TeBox input_box1( TeCoord2D( 238, 689 ) ,
00212 TeCoord2D( 391, 473 ) );
00213 params.SetParameter( "input_box1" , input_box1 );
00214
00215 params.SetParameter( "enable_multi_thread" , (int)1 );
00216
00217 params.SetParameter( "pixel_x_relation" , (double)1 );
00218 params.SetParameter( "pixel_y_relation" , (double)1 );
00219
00220 TePDIMIMatching match_instance;
00221 match_instance.ToggleProgInt( true );
00222 TEAGN_TRUE_OR_THROW( match_instance.Reset( params ),
00223 "Algorithm reset error" )
00224
00225 TEAGN_LOGMSG( "Algorithm started" )
00226
00227 time_t init_time = clock() / CLOCKS_PER_SEC;
00228
00229 TEAGN_TRUE_OR_THROW( match_instance.Apply(),
00230 "Algorithm apply error" )
00231
00232 time_t end_time = clock() / CLOCKS_PER_SEC;
00233
00234 TEAGN_LOGMSG( "Time elapsed (sameImageDifBoxesTest): " +
00235 TeAgnostic::to_string( (long int)( end_time - init_time ) ) +
00236 " seconds" );
00237
00238
00239 {
00240 TeCoordPairVect::iterator it = out_tie_points_ptr->begin();
00241 TeCoordPairVect::iterator it_end = out_tie_points_ptr->end();
00242
00243 while( it != it_end ) {
00244 std::cout << "[" + Te2String( it->pt1.x(),1 ) + " , " +
00245 Te2String( it->pt1.y(),1 ) + "] -> [" +
00246 Te2String( it->pt2.x(),1 ) + " , " +
00247 Te2String( it->pt2.y(),1 ) + "]" << std::endl;
00248
00249 ++it;
00250 }
00251 }
00252
00253
00254
00255 raster2Tiff( input_image1_ptr, 0, TEPDIEXAMPLESBINPATH
00256 "TeMIMatching_test_sameImageTest2_input_image1.tif",
00257 out_tie_points_ptr, 0 );
00258 raster2Tiff( input_image2_ptr, 0, TEPDIEXAMPLESBINPATH
00259 "TeMIMatching_test_sameImageTest2_input_image2.tif",
00260 out_tie_points_ptr, 1 );
00261
00262 TEAGN_WATCH( (unsigned int)out_tie_points_ptr->size() );
00263 TEAGN_CHECK_EPS( 4, out_tie_points_ptr->size(),
00264 0, "Invalid tie-points number" )
00265 }
00266
00267
00268 void halfsampledImageTest()
00269 {
00270
00271
00272 TePDIParameters params;
00273
00274 TePDITypes::TePDIRasterPtrType input_image1_ptr( new TeRaster(
00275 std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00276 TEAGN_TRUE_OR_THROW( input_image1_ptr->init(),
00277 "Unable to init input_image1_ptr" );
00278 params.SetParameter( "input_image1_ptr" , input_image1_ptr );
00279
00280 params.SetParameter( "input_channel1" , (unsigned int)0 );
00281
00282 TePDITypes::TePDIRasterPtrType input_image2_ptr( new TeRaster(
00283 std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop_contraste_halfsampled.tif" ), 'r' ) );
00284 TEAGN_TRUE_OR_THROW( input_image2_ptr->init(),
00285 "Unable to init input_image2_ptr" );
00286 params.SetParameter( "input_image2_ptr" , input_image2_ptr );
00287
00288 params.SetParameter( "input_channel2" , (unsigned int)0 );
00289
00290 TeSharedPtr< TeCoordPairVect > out_tie_points_ptr( new TeCoordPairVect );
00291 params.SetParameter( "out_tie_points_ptr" , out_tie_points_ptr );
00292
00293 TeBox input_box1( TeCoord2D( 198, 486 ) ,
00294 TeCoord2D( 577, 186 ) );
00295 params.SetParameter( "input_box1" , input_box1 );
00296
00297 TeBox input_box2( TeCoord2D( 143, 180 ) ,
00298 TeCoord2D( 227, 113 ) );
00299 params.SetParameter( "input_box2" , input_box2 );
00300
00301 params.SetParameter( "enable_multi_thread" , (int)1 );
00302
00303 params.SetParameter( "pixel_x_relation" , (double)0.5 );
00304 params.SetParameter( "pixel_y_relation" , (double)0.5 );
00305
00306 TePDIMIMatching match_instance;
00307 match_instance.ToggleProgInt( true );
00308 TEAGN_TRUE_OR_THROW( match_instance.Reset( params ),
00309 "Algorithm reset error" )
00310
00311 TEAGN_LOGMSG( "Algorithm started" )
00312
00313 time_t init_time = clock() / CLOCKS_PER_SEC;
00314
00315 TEAGN_TRUE_OR_THROW( match_instance.Apply(),
00316 "Algorithm apply error" )
00317
00318 time_t end_time = clock() / CLOCKS_PER_SEC;
00319
00320 TEAGN_LOGMSG( "Time elapsed (sameImageDifBoxesTest): " +
00321 TeAgnostic::to_string( (long int)( end_time - init_time ) ) +
00322 " seconds" );
00323
00324
00325 {
00326 TeCoordPairVect::iterator it = out_tie_points_ptr->begin();
00327 TeCoordPairVect::iterator it_end = out_tie_points_ptr->end();
00328
00329 while( it != it_end ) {
00330 std::cout << "[" + Te2String( it->pt1.x(),1 ) + " , " +
00331 Te2String( it->pt1.y(),1 ) + "] -> [" +
00332 Te2String( it->pt2.x(),1 ) + " , " +
00333 Te2String( it->pt2.y(),1 ) + "]" << std::endl;
00334
00335 ++it;
00336 }
00337 }
00338
00339
00340
00341 raster2Tiff( input_image1_ptr, 0, TEPDIEXAMPLESBINPATH
00342 "TeMIMatching_test_halfsampledImageTest_input_image1.tif",
00343 out_tie_points_ptr, 0 );
00344 raster2Tiff( input_image2_ptr, 0, TEPDIEXAMPLESBINPATH
00345 "TeMIMatching_test_halfsampledImageTest_input_image2.tif",
00346 out_tie_points_ptr, 1 );
00347
00348 TEAGN_WATCH( (unsigned int)out_tie_points_ptr->size() );
00349 TEAGN_CHECK_EPS( 4, out_tie_points_ptr->size(),
00350 0, "Invalid tie-points number" )
00351 }
00352
00353
00354 void halfsampledImageTest2()
00355 {
00356
00357
00358 TePDIParameters params;
00359
00360 TePDITypes::TePDIRasterPtrType input_image1_ptr( new TeRaster(
00361 std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop_contraste_halfsampled.tif" ), 'r' ) );
00362 TEAGN_TRUE_OR_THROW( input_image1_ptr->init(),
00363 "Unable to init input_image1_ptr" );
00364 params.SetParameter( "input_image1_ptr" , input_image1_ptr );
00365
00366 params.SetParameter( "input_channel1" , (unsigned int)0 );
00367
00368 TePDITypes::TePDIRasterPtrType input_image2_ptr( new TeRaster(
00369 std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00370 TEAGN_TRUE_OR_THROW( input_image2_ptr->init(),
00371 "Unable to init input_image2_ptr" );
00372 params.SetParameter( "input_image2_ptr" , input_image2_ptr );
00373
00374 params.SetParameter( "input_channel2" , (unsigned int)0 );
00375
00376 TeSharedPtr< TeCoordPairVect > out_tie_points_ptr( new TeCoordPairVect );
00377 params.SetParameter( "out_tie_points_ptr" , out_tie_points_ptr );
00378
00379 TeBox input_box2( TeCoord2D( 198, 486 ) ,
00380 TeCoord2D( 577, 186 ) );
00381 params.SetParameter( "input_box2" , input_box2 );
00382
00383 TeBox input_box1( TeCoord2D( 143, 180 ) ,
00384 TeCoord2D( 227, 113 ) );
00385 params.SetParameter( "input_box1" , input_box1 );
00386
00387 params.SetParameter( "enable_multi_thread" , (int)1 );
00388
00389 params.SetParameter( "pixel_x_relation" , (double)2 );
00390 params.SetParameter( "pixel_y_relation" , (double)2 );
00391
00392 TePDIMIMatching match_instance;
00393 match_instance.ToggleProgInt( true );
00394 TEAGN_TRUE_OR_THROW( match_instance.Reset( params ),
00395 "Algorithm reset error" )
00396
00397 TEAGN_LOGMSG( "Algorithm started" )
00398
00399 time_t init_time = clock() / CLOCKS_PER_SEC;
00400
00401 TEAGN_TRUE_OR_THROW( match_instance.Apply(),
00402 "Algorithm apply error" )
00403
00404 time_t end_time = clock() / CLOCKS_PER_SEC;
00405
00406 TEAGN_LOGMSG( "Time elapsed (sameImageDifBoxesTest): " +
00407 TeAgnostic::to_string( (long int)( end_time - init_time ) ) +
00408 " seconds" );
00409
00410
00411 {
00412 TeCoordPairVect::iterator it = out_tie_points_ptr->begin();
00413 TeCoordPairVect::iterator it_end = out_tie_points_ptr->end();
00414
00415 while( it != it_end ) {
00416 std::cout << "[" + Te2String( it->pt1.x(),1 ) + " , " +
00417 Te2String( it->pt1.y(),1 ) + "] -> [" +
00418 Te2String( it->pt2.x(),1 ) + " , " +
00419 Te2String( it->pt2.y(),1 ) + "]" << std::endl;
00420
00421 ++it;
00422 }
00423 }
00424
00425
00426
00427 raster2Tiff( input_image1_ptr, 0, TEPDIEXAMPLESBINPATH
00428 "TeMIMatching_test_halfsampledImageTest2_input_image1.tif",
00429 out_tie_points_ptr, 0 );
00430 raster2Tiff( input_image2_ptr, 0, TEPDIEXAMPLESBINPATH
00431 "TeMIMatching_test_halfsampledImageTest2_input_image2.tif",
00432 out_tie_points_ptr, 1 );
00433
00434 TEAGN_WATCH( (unsigned int)out_tie_points_ptr->size() );
00435 TEAGN_CHECK_EPS( 4, out_tie_points_ptr->size(),
00436 0, "Invalid tie-points number" )
00437 }
00438
00439 void sameImageGreenXRedTest()
00440 {
00441
00442
00443 TePDIParameters params;
00444
00445 TePDITypes::TePDIRasterPtrType input_image1_ptr( new TeRaster(
00446 std::string( TEPDIEXAMPLESRESPATH "cbers_rgb342_crop1.tif" ), 'r' ) );
00447 TEAGN_TRUE_OR_THROW( input_image1_ptr->init(),
00448 "Unable to init input_image1_ptr" );
00449 params.SetParameter( "input_image1_ptr" , input_image1_ptr );
00450
00451 params.SetParameter( "input_channel1" , (unsigned int)0 );
00452
00453 TePDITypes::TePDIRasterPtrType input_image2_ptr( new TeRaster(
00454 std::string( TEPDIEXAMPLESRESPATH "cbers_rgb342_crop1.tif" ), 'r' ) );
00455 TEAGN_TRUE_OR_THROW( input_image2_ptr->init(),
00456 "Unable to init input_image2_ptr" );
00457 params.SetParameter( "input_image2_ptr" , input_image2_ptr );
00458
00459 params.SetParameter( "input_channel2" , (unsigned int)1 );
00460
00461 TeSharedPtr< TeCoordPairVect > out_tie_points_ptr( new TeCoordPairVect );
00462 params.SetParameter( "out_tie_points_ptr" , out_tie_points_ptr );
00463
00464 TeBox input_box1( TeCoord2D( 142, 826 ) ,
00465 TeCoord2D( 542, 426 ) );
00466 params.SetParameter( "input_box1" , input_box1 );
00467
00468 TeBox input_box2( TeCoord2D( 238, 689 ) ,
00469 TeCoord2D( 391, 473 ) );
00470 params.SetParameter( "input_box2" , input_box2 );
00471
00472 params.SetParameter( "enable_multi_thread" , (int)1 );
00473
00474 params.SetParameter( "pixel_x_relation" , (double)1 );
00475 params.SetParameter( "pixel_y_relation" , (double)1 );
00476
00477 TePDIMIMatching match_instance;
00478 match_instance.ToggleProgInt( true );
00479 TEAGN_TRUE_OR_THROW( match_instance.Reset( params ),
00480 "Algorithm reset error" )
00481
00482 TEAGN_LOGMSG( "Algorithm started" )
00483
00484 time_t init_time = clock() / CLOCKS_PER_SEC;
00485
00486 TEAGN_TRUE_OR_THROW( match_instance.Apply(),
00487 "Algorithm apply error" )
00488
00489 time_t end_time = clock() / CLOCKS_PER_SEC;
00490
00491 TEAGN_LOGMSG( "Time elapsed (sameImageDifBoxesTest): " +
00492 TeAgnostic::to_string( (long int)( end_time - init_time ) ) +
00493 " seconds" );
00494
00495
00496 {
00497 TeCoordPairVect::iterator it = out_tie_points_ptr->begin();
00498 TeCoordPairVect::iterator it_end = out_tie_points_ptr->end();
00499
00500 while( it != it_end ) {
00501 std::cout << "[" + Te2String( it->pt1.x(),1 ) + " , " +
00502 Te2String( it->pt1.y(),1 ) + "] -> [" +
00503 Te2String( it->pt2.x(),1 ) + " , " +
00504 Te2String( it->pt2.y(),1 ) + "]" << std::endl;
00505
00506 ++it;
00507 }
00508 }
00509
00510
00511
00512 raster2Tiff( input_image1_ptr, 0, TEPDIEXAMPLESBINPATH
00513 "TeMIMatching_test_sameImageGreenXRedTest_input_image1.tif",
00514 out_tie_points_ptr, 0 );
00515 raster2Tiff( input_image2_ptr, 1, TEPDIEXAMPLESBINPATH
00516 "TeMIMatching_test_sameImageGreenXRedTest_input_image2.tif",
00517 out_tie_points_ptr, 1 );
00518
00519 TEAGN_WATCH( (unsigned int)out_tie_points_ptr->size() );
00520 TEAGN_CHECK_EPS( 4, out_tie_points_ptr->size(),
00521 0, "Invalid tie-points number" )
00522 }
00523
00524 void sameImageGreenXBlueTest()
00525 {
00526
00527
00528 TePDIParameters params;
00529
00530 TePDITypes::TePDIRasterPtrType input_image1_ptr( new TeRaster(
00531 std::string( TEPDIEXAMPLESRESPATH "cbers_rgb342_crop1.tif" ), 'r' ) );
00532 TEAGN_TRUE_OR_THROW( input_image1_ptr->init(),
00533 "Unable to init input_image1_ptr" );
00534 params.SetParameter( "input_image1_ptr" , input_image1_ptr );
00535
00536 params.SetParameter( "input_channel1" , (unsigned int)1 );
00537
00538 TePDITypes::TePDIRasterPtrType input_image2_ptr( new TeRaster(
00539 std::string( TEPDIEXAMPLESRESPATH "cbers_rgb342_crop1.tif" ), 'r' ) );
00540 TEAGN_TRUE_OR_THROW( input_image2_ptr->init(),
00541 "Unable to init input_image2_ptr" );
00542 params.SetParameter( "input_image2_ptr" , input_image2_ptr );
00543
00544 params.SetParameter( "input_channel2" , (unsigned int)2 );
00545
00546 TeSharedPtr< TeCoordPairVect > out_tie_points_ptr( new TeCoordPairVect );
00547 params.SetParameter( "out_tie_points_ptr" , out_tie_points_ptr );
00548
00549 TeBox input_box1( TeCoord2D( 142, 826 ) ,
00550 TeCoord2D( 542, 426 ) );
00551 params.SetParameter( "input_box1" , input_box1 );
00552
00553 TeBox input_box2( TeCoord2D( 238, 689 ) ,
00554 TeCoord2D( 391, 473 ) );
00555 params.SetParameter( "input_box2" , input_box2 );
00556
00557 params.SetParameter( "enable_multi_thread" , (int)1 );
00558
00559 params.SetParameter( "pixel_x_relation" , (double)1 );
00560 params.SetParameter( "pixel_y_relation" , (double)1 );
00561
00562 TePDIMIMatching match_instance;
00563 match_instance.ToggleProgInt( true );
00564 TEAGN_TRUE_OR_THROW( match_instance.Reset( params ),
00565 "Algorithm reset error" )
00566
00567 TEAGN_LOGMSG( "Algorithm started" )
00568
00569 time_t init_time = clock() / CLOCKS_PER_SEC;
00570
00571 TEAGN_TRUE_OR_THROW( match_instance.Apply(),
00572 "Algorithm apply error" )
00573
00574 time_t end_time = clock() / CLOCKS_PER_SEC;
00575
00576 TEAGN_LOGMSG( "Time elapsed (sameImageDifBoxesTest): " +
00577 TeAgnostic::to_string( (long int)( end_time - init_time ) ) +
00578 " seconds" );
00579
00580
00581 {
00582 TeCoordPairVect::iterator it = out_tie_points_ptr->begin();
00583 TeCoordPairVect::iterator it_end = out_tie_points_ptr->end();
00584
00585 while( it != it_end ) {
00586 std::cout << "[" + Te2String( it->pt1.x(),1 ) + " , " +
00587 Te2String( it->pt1.y(),1 ) + "] -> [" +
00588 Te2String( it->pt2.x(),1 ) + " , " +
00589 Te2String( it->pt2.y(),1 ) + "]" << std::endl;
00590
00591 ++it;
00592 }
00593 }
00594
00595
00596
00597 raster2Tiff( input_image1_ptr, 1, TEPDIEXAMPLESBINPATH
00598 "TeMIMatching_test_sameImageGreenXBlueTest_input_image1.tif",
00599 out_tie_points_ptr, 0 );
00600 raster2Tiff( input_image2_ptr, 2, TEPDIEXAMPLESBINPATH
00601 "TeMIMatching_test_sameImageGreenXBlueTest_input_image2.tif",
00602 out_tie_points_ptr, 1 );
00603
00604 TEAGN_WATCH( (unsigned int)out_tie_points_ptr->size() );
00605 TEAGN_CHECK_EPS( 4, out_tie_points_ptr->size(),
00606 0, "Invalid tie-points number" )
00607 }
00608
00609 void sameInvertedImageTest()
00610 {
00611
00612
00613 TePDIParameters params;
00614
00615 TePDITypes::TePDIRasterPtrType input_image1_ptr( new TeRaster(
00616 std::string( TEPDIEXAMPLESRESPATH "cbers_rgb342_crop1.tif" ), 'r' ) );
00617 TEAGN_TRUE_OR_THROW( input_image1_ptr->init(),
00618 "Unable to init input_image1_ptr" );
00619 params.SetParameter( "input_image1_ptr" , input_image1_ptr );
00620
00621 params.SetParameter( "input_channel1" , (unsigned int)0 );
00622
00623 TePDITypes::TePDIRasterPtrType input_image2_ptr;
00624 {
00625 TePDITypes::TePDIRasterPtrType di2_ptr( new TeRaster(
00626 std::string( TEPDIEXAMPLESRESPATH "cbers_rgb342_crop1.tif" ), 'r' ) );
00627 TEAGN_TRUE_OR_THROW( di2_ptr->init(),
00628 "Unable to init input_image2_ptr" );
00629
00630 TeRasterParams input_image2_pars = di2_ptr->params();
00631 input_image2_pars.nBands( 1 );
00632
00633 TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( input_image2_ptr,
00634 input_image2_pars, false ), "Raster alloc error" )
00635
00636 double value = 0;
00637 for( int lin = 0 ; lin < input_image2_pars.nlines_ ; ++lin )
00638 for( int col = 0 ; col < input_image2_pars.ncols_ ; ++col )
00639 {
00640 di2_ptr->getElement( col, lin, value, 0 );
00641 input_image2_ptr->setElement( col, lin, 255.0 - value, 0 );
00642 }
00643 }
00644 params.SetParameter( "input_image2_ptr" , input_image2_ptr );
00645
00646 params.SetParameter( "input_channel2" , (unsigned int)0 );
00647
00648 TeSharedPtr< TeCoordPairVect > out_tie_points_ptr( new TeCoordPairVect );
00649 params.SetParameter( "out_tie_points_ptr" , out_tie_points_ptr );
00650
00651 TeBox input_box1( TeCoord2D( 142, 826 ) ,
00652 TeCoord2D( 542, 426 ) );
00653 params.SetParameter( "input_box1" , input_box1 );
00654
00655 TeBox input_box2( TeCoord2D( 238, 689 ) ,
00656 TeCoord2D( 391, 473 ) );
00657 params.SetParameter( "input_box2" , input_box2 );
00658
00659 params.SetParameter( "enable_multi_thread" , (int)1 );
00660
00661 params.SetParameter( "pixel_x_relation" , (double)1 );
00662 params.SetParameter( "pixel_y_relation" , (double)1 );
00663
00664 TePDIMIMatching match_instance;
00665 match_instance.ToggleProgInt( true );
00666 TEAGN_TRUE_OR_THROW( match_instance.Reset( params ),
00667 "Algorithm reset error" )
00668
00669 TEAGN_LOGMSG( "Algorithm started" )
00670
00671 time_t init_time = clock() / CLOCKS_PER_SEC;
00672
00673 TEAGN_TRUE_OR_THROW( match_instance.Apply(),
00674 "Algorithm apply error" )
00675
00676 time_t end_time = clock() / CLOCKS_PER_SEC;
00677
00678 TEAGN_LOGMSG( "Time elapsed (sameImageDifBoxesTest): " +
00679 TeAgnostic::to_string( (long int)( end_time - init_time ) ) +
00680 " seconds" );
00681
00682
00683 {
00684 TeCoordPairVect::iterator it = out_tie_points_ptr->begin();
00685 TeCoordPairVect::iterator it_end = out_tie_points_ptr->end();
00686
00687 while( it != it_end ) {
00688 std::cout << "[" + Te2String( it->pt1.x(),1 ) + " , " +
00689 Te2String( it->pt1.y(),1 ) + "] -> [" +
00690 Te2String( it->pt2.x(),1 ) + " , " +
00691 Te2String( it->pt2.y(),1 ) + "]" << std::endl;
00692
00693 ++it;
00694 }
00695 }
00696
00697
00698
00699 raster2Tiff( input_image1_ptr, 0, TEPDIEXAMPLESBINPATH
00700 "TeMIMatching_test_sameInvertedImageTest_input_image1.tif",
00701 out_tie_points_ptr, 0 );
00702 raster2Tiff( input_image2_ptr, 0, TEPDIEXAMPLESBINPATH
00703 "TeMIMatching_test_sameInvertedImageTest_input_image2.tif",
00704 out_tie_points_ptr, 0 );
00705
00706 TEAGN_WATCH( (unsigned int)out_tie_points_ptr->size() );
00707 TEAGN_CHECK_EPS( 4, out_tie_points_ptr->size(),
00708 0, "Invalid tie-points number" )
00709 }
00710
00711 int main()
00712 {
00713 TEAGN_LOGMSG( "Test started." );
00714
00715 try{
00716 TeStdIOProgress pi;
00717 TeProgress::setProgressInterf( dynamic_cast< TeProgressBase* >( &pi ) );
00718
00719 time_t init_time = clock() / CLOCKS_PER_SEC;
00720
00721 sameImageTest();
00722 sameImageTest2();
00723 halfsampledImageTest();
00724 halfsampledImageTest2();
00725 sameImageGreenXRedTest();
00726 sameImageGreenXBlueTest();
00727 sameInvertedImageTest();
00728
00729 time_t end_time = clock() / CLOCKS_PER_SEC;
00730
00731 TEAGN_LOGMSG( "Total elapsed time: " +
00732 TeAgnostic::to_string( (long int)( end_time - init_time ) ) +
00733 " seconds" );
00734 }
00735 catch( const TeException& e ){
00736 TEAGN_LOGERR( "Test Failed - " + e.message() );
00737 return EXIT_FAILURE;
00738 }
00739
00740 TEAGN_LOGMSG( "Test OK." );
00741 return EXIT_SUCCESS;
00742 }
00743