00001 #define TEAGN_ENABLE_STDOUT_LOG
00002
00003 #include <TePDIExamplesBase.hpp>
00004
00005 #include <TePDIMMIOMatching.hpp>
00006 #include <TePDIUtils.hpp>
00007
00008 #include <TeGTParams.h>
00009 #include <TeProgress.h>
00010 #include <TeStdIOProgress.h>
00011 #include <TeAgnostic.h>
00012 #include <TeDefines.h>
00013
00014 #include <math.h>
00015
00016 #ifndef M_PI
00017 #define M_PI 3.14159265358979323846
00018 #endif
00019 #ifndef M_PI_2
00020 #define M_PI_2 1.57079632679489661923
00021 #endif
00022 #ifndef M_PI_4
00023 #define M_PI_4 0.785398163397448309616
00024 #endif
00025
00026 void raster2Tiff(
00027 const TePDITypes::TePDIRasterPtrType& input_raster_ptr,
00028 unsigned int raster_channel,
00029 const std::string& out_file_name,
00030 TeSharedPtr< TeCoordPairVect > out_tie_points_ptr,
00031 unsigned int tie_points_space )
00032 {
00033 TEAGN_TRUE_OR_THROW( ( ! out_file_name.empty() ),
00034 "Invalid file name" )
00035 TEAGN_TRUE_OR_THROW( ( input_raster_ptr->params().nlines_ > 0 ),
00036 "Invalid matrix lines" )
00037 TEAGN_TRUE_OR_THROW( ( input_raster_ptr->params().ncols_ > 0 ),
00038 "Invalid matrix cols" )
00039
00040 TeRasterParams params;
00041 params.setNLinesNColumns( input_raster_ptr->params().nlines_,
00042 input_raster_ptr->params().ncols_ );
00043 params.nBands( 3 );
00044 params.setDataType( TeUNSIGNEDCHAR, -1 );
00045 params.setPhotometric( TeRasterParams::TeRGB );
00046 params.decoderIdentifier_ = "TIF";
00047 params.mode_ = 'c';
00048 params.fileName_ = out_file_name;
00049
00050 TeRaster out_raster( params );
00051 TEAGN_TRUE_OR_THROW( out_raster.init(), "Error init raster" );
00052 double value = 0;
00053
00054 for( int line = 0 ;
00055 line < input_raster_ptr->params().nlines_ ; ++line ) {
00056 for( int col = 0 ;
00057 col < input_raster_ptr->params().ncols_ ;
00058 ++col ) {
00059
00060 input_raster_ptr->getElement( col, line, value,
00061 raster_channel );
00062
00063 TEAGN_TRUE_OR_THROW( out_raster.setElement( col, line,
00064 MIN( 254.0, value ), 0 ),
00065 "Error writing raster" )
00066 TEAGN_TRUE_OR_THROW( out_raster.setElement( col, line,
00067 MIN( 254.0, value ), 1 ),
00068 "Error writing raster" )
00069 TEAGN_TRUE_OR_THROW( out_raster.setElement( col, line,
00070 MIN( 254.0, value ), 2 ),
00071 "Error writing raster" )
00072 }
00073 }
00074
00075
00076
00077 if( out_tie_points_ptr.isActive() ) {
00078 TeCoordPairVect::iterator it = out_tie_points_ptr->begin();
00079 TeCoordPairVect::iterator it_end = out_tie_points_ptr->end();
00080
00081 while( it != it_end ) {
00082 int x = 0;
00083 int y = 0;
00084
00085 if( tie_points_space == 0 ) {
00086 x = TeRound( it->pt1.x() );
00087 y = TeRound( it->pt1.y() );
00088 } else {
00089 x = TeRound( it->pt2.x() );
00090 y = TeRound( it->pt2.y() );
00091 }
00092
00093 TEAGN_TRUE_OR_THROW( ( x < input_raster_ptr->params().ncols_ ),
00094 "Invalid maxima column" )
00095 TEAGN_TRUE_OR_THROW( ( x >= 0 ),
00096 "Invalid maxima column" )
00097 TEAGN_TRUE_OR_THROW( ( y < input_raster_ptr->params().nlines_ ),
00098 "Invalid maxima line" )
00099 TEAGN_TRUE_OR_THROW( ( y >= 0 ),
00100 "Invalid maxima line" )
00101
00102 TEAGN_TRUE_OR_THROW( out_raster.setElement( x, y,
00103 0, 0 ),
00104 "Error writing raster" )
00105 TEAGN_TRUE_OR_THROW( out_raster.setElement( x, y,
00106 255, 1 ),
00107 "Error writing raster" )
00108 TEAGN_TRUE_OR_THROW( out_raster.setElement( x, y,
00109 0, 2 ),
00110 "Error writing raster" )
00111
00112 ++it;
00113 }
00114
00115 }
00116 }
00117
00118
00119 void rotateRasterClockWize(
00120 const TePDITypes::TePDIRasterPtrType& input_raster_ptr,
00121 const TePDITypes::TePDIRasterPtrType& output_raster_ptr,
00122 double angle )
00123 {
00124 TEAGN_TRUE_OR_THROW( input_raster_ptr.isActive(),
00125 "Invalid input pointer" );
00126 TEAGN_TRUE_OR_THROW( output_raster_ptr.isActive(),
00127 "Invalid output pointer" );
00128
00129 const double input_raster_lines =
00130 (double)input_raster_ptr->params().nlines_;
00131 const double input_raster_cols =
00132 (double)input_raster_ptr->params().ncols_;
00133 const unsigned int input_raster_channels =
00134 (unsigned int)input_raster_ptr->nBands();
00135
00136 const double last_x_idx = input_raster_cols - 1.0;
00137 const double last_y_idx = input_raster_lines - 1.0;
00138
00139 const double angle_cos = cos( angle );
00140 const double angle_sin = sin( angle );
00141
00142
00143
00144 double min_x = MIN( 0.0, ( angle_cos * last_x_idx ) -
00145 ( angle_sin * last_y_idx ) );
00146 min_x = MIN( min_x, ( angle_cos * last_x_idx ) );
00147 min_x = MIN( min_x, ( -1.0 * angle_sin * last_y_idx ) );
00148
00149 double max_x = MAX( 0.0, ( angle_cos * last_x_idx ) -
00150 ( angle_sin * last_y_idx ) );
00151 max_x = MAX( max_x, ( angle_cos * last_x_idx ) );
00152 max_x = MAX( max_x, ( -1.0 * angle_sin * last_y_idx ) );
00153
00154 double min_y = MIN( 0.0, ( angle_sin * last_x_idx ) +
00155 ( angle_cos * last_y_idx ) );
00156 min_y = MIN( min_y, ( angle_sin * last_x_idx ) );
00157 min_y = MIN( min_y, ( angle_cos * last_y_idx ) );
00158
00159 double max_y = MAX( 0.0, ( angle_sin * last_x_idx ) +
00160 ( angle_cos * last_y_idx ) );
00161 max_y = MAX( max_y, ( angle_sin * last_x_idx ) );
00162 max_y = MAX( max_y, ( angle_cos * last_y_idx ) );
00163
00164 const unsigned int out_lines = (unsigned int) ceil(
00165 max_y - min_y );
00166 const unsigned int out_cols = (unsigned int) ceil(
00167 max_x - min_x );
00168
00169
00170
00171 TeCoord2D ll_point_input_ref_indexed( min_x,
00172 max_y );
00173 TeCoord2D ur_point_input_ref_indexed( max_x,
00174 min_y );
00175
00176 TeCoord2D ll_point_input_ref =
00177 input_raster_ptr->index2Coord( ll_point_input_ref_indexed );
00178 TeCoord2D ur_point_input_ref =
00179 input_raster_ptr->index2Coord( ur_point_input_ref_indexed );
00180
00181 TeRasterParams new_out_params = output_raster_ptr->params();
00182
00183 new_out_params.boundingBoxLinesColumns(
00184 ll_point_input_ref.x(), ll_point_input_ref.y(),
00185 ur_point_input_ref.x(), ur_point_input_ref.y(),
00186 out_lines, out_cols );
00187
00188 TEAGN_TRUE_OR_THROW( output_raster_ptr->init( new_out_params ),
00189 "Error reseting output raster" )
00190
00191
00192
00193 unsigned int curr_out_x = 0;
00194 unsigned int curr_out_y = 0;
00195 double value = 0;
00196 unsigned int curr_in_x = 0;
00197 unsigned int curr_in_y = 0;
00198 unsigned int curr_channel = 0;
00199
00200 for( curr_channel = 0 ; curr_channel < input_raster_channels ;
00201 ++curr_channel ) {
00202 for( curr_out_y = 0 ; curr_out_y < out_lines ; ++curr_out_y ) {
00203 for( curr_out_x = 0 ; curr_out_x < out_cols ; ++curr_out_x ) {
00204 curr_in_x =
00205 TeRound(
00206 ( angle_cos * ( curr_out_x + min_x ) ) +
00207 ( angle_sin * ( curr_out_y + min_y ) )
00208 );
00209 curr_in_y =
00210 TeRound(
00211 ( -1.0 * angle_sin * ( curr_out_x + min_x ) ) +
00212 ( angle_cos * ( curr_out_y + min_y ) )
00213 );
00214
00215 if( input_raster_ptr->getElement( curr_in_x, curr_in_y,
00216 value, curr_channel ) ) {
00217
00218 output_raster_ptr->setElement( curr_out_x, curr_out_y,
00219 value, curr_channel );
00220 } else {
00221 output_raster_ptr->setElement( curr_out_x, curr_out_y,
00222 0, curr_channel );
00223 }
00224 }
00225 }
00226 }
00227
00228 return;
00229 }
00230
00231
00232 void sameImageAndBoxesTest()
00233 {
00234
00235
00236 TePDIParameters params;
00237
00238 TePDITypes::TePDIRasterPtrType input_image1_ptr;
00239 TEAGN_TRUE_OR_THROW( TePDIUtils::loadRaster(
00240 std::string( TEPDIEXAMPLESRESPATH "cbers_rgb342_crop1.tif" ),
00241 input_image1_ptr, true ), "Error loading raster" );
00242 params.SetParameter( "input_image1_ptr" , input_image1_ptr );
00243
00244 params.SetParameter( "input_channel1" , (unsigned int)0 );
00245
00246 TePDITypes::TePDIRasterPtrType input_image2_ptr;
00247 TEAGN_TRUE_OR_THROW( TePDIUtils::loadRaster(
00248 std::string( TEPDIEXAMPLESRESPATH "cbers_rgb342_crop1.tif" ),
00249 input_image2_ptr, true ), "Error loading raster" );
00250 params.SetParameter( "input_image2_ptr" , input_image2_ptr );
00251
00252 params.SetParameter( "input_channel2" , (unsigned int)0 );
00253
00254 TeSharedPtr< TeCoordPairVect > out_tie_points_ptr( new TeCoordPairVect );
00255 params.SetParameter( "out_tie_points_ptr" , out_tie_points_ptr );
00256
00257 params.SetParameter( "matching_method",
00258 TePDIMMIOMatching::NormCrossCorrMethod );
00259
00260
00261
00262 TeGTParams gt_params;
00263 gt_params.transformation_name_ = "affine";
00264 gt_params.out_rem_strat_ = TeGTParams::LWOutRemotion;
00265 gt_params.max_dmap_error_ = 2.0;
00266 gt_params.max_imap_error_ = 2.0;
00267 params.SetParameter( "gt_params" , gt_params );
00268
00269 TeBox input_box1_proj = input_image1_ptr->params().box();
00270 TeBox input_box1;
00271 TePDIUtils::MapCoords2RasterIndexes( input_box1_proj,
00272 input_image1_ptr, input_box1 );
00273 params.SetParameter( "input_box1" , input_box1 );
00274
00275 params.SetParameter( "input_box2" , input_box1 );
00276
00277 params.SetParameter( "enable_multi_thread" , (int)1 );
00278
00279
00280
00281 params.SetParameter( "skip_geom_filter" , (int)1 );
00282
00283 params.SetParameter( "pixel_x_relation" , (double)1 );
00284 params.SetParameter( "pixel_y_relation" , (double)1 );
00285
00286 params.SetParameter( "max_tie_points" , (unsigned int)1000 );
00287 params.SetParameter( "corr_window_width" , (unsigned int)21 );
00288 params.SetParameter( "moravec_window_width" , (unsigned int)11 );
00289
00290 TeGTParams::pointer out_gt_params_ptr( new TeGTParams );
00291 params.SetParameter( "out_gt_params_ptr" , out_gt_params_ptr );
00292
00293 TePDIMMIOMatching match_instance;
00294
00295 TEAGN_TRUE_OR_THROW( match_instance.Reset( params ),
00296 "Algorithm reset error" )
00297
00298 TEAGN_LOGMSG( "Algorithm started" )
00299
00300 time_t init_time = clock() / CLOCKS_PER_SEC ;
00301
00302 TEAGN_TRUE_OR_THROW( match_instance.Apply(),
00303 "Algorithm apply error" )
00304
00305 time_t end_time = clock() / CLOCKS_PER_SEC;
00306
00307 TEAGN_LOGMSG( "Time elapsed (sameImageAndBoxesTest): " +
00308 TeAgnostic::to_string( (long int)( end_time - init_time ) ) +
00309 " seconds" );
00310
00311
00312 {
00313 TeCoordPairVect::iterator it = out_tie_points_ptr->begin();
00314 TeCoordPairVect::iterator it_end = out_tie_points_ptr->end();
00315
00316 while( it != it_end ) {
00317 std::cout << "[" + Te2String( it->pt1.x(),1 ) + " , " +
00318 Te2String( it->pt1.y(),1 ) + "] -> [" +
00319 Te2String( it->pt2.x(),1 ) + " , " +
00320 Te2String( it->pt2.y(),1 ) + "]" << std::endl;
00321
00322 ++it;
00323 }
00324 }
00325
00326
00327
00328 raster2Tiff( input_image1_ptr, 0, TEPDIEXAMPLESBINPATH
00329 "TePDIMMIOMatching_test_sameImageAndBoxesTest_input_image1.tif",
00330 out_tie_points_ptr, 0 );
00331 raster2Tiff( input_image2_ptr, 0, TEPDIEXAMPLESBINPATH
00332 "TePDIMMIOMatching_test_sameImageAndBoxesTest_input_image2.tif",
00333 out_tie_points_ptr, 1 );
00334
00335
00336
00337 {
00338 TeCoordPairVect::iterator it = out_tie_points_ptr->begin();
00339 TeCoordPairVect::iterator it_end = out_tie_points_ptr->end();
00340
00341 while( it != it_end ) {
00342 TEAGN_CHECK_EPS( it->pt1.x(), it->pt2.x(), 0,
00343 "Invalid tie-point" )
00344 TEAGN_CHECK_EPS( it->pt1.y(), it->pt2.y(), 0,
00345 "Invalid tie-point" )
00346
00347 ++it;
00348 }
00349 }
00350
00351 TEAGN_CHECK_EPS( 769, out_tie_points_ptr->size(),
00352 0, "Invalid tie-points number" )
00353 }
00354
00355 void sameImageAndBoxesWithMaskTest()
00356 {
00357
00358
00359 TePDIParameters params;
00360
00361 TePDITypes::TePDIRasterPtrType input_image1_ptr;
00362 TEAGN_TRUE_OR_THROW( TePDIUtils::loadRaster(
00363 std::string( TEPDIEXAMPLESRESPATH "cbers_rgb342_crop1.tif" ),
00364 input_image1_ptr, true ), "Error loading raster" );
00365 params.SetParameter( "input_image1_ptr" , input_image1_ptr );
00366
00367 params.SetParameter( "input_channel1" , (unsigned int)0 );
00368
00369 TePDITypes::TePDIRasterPtrType input_image2_ptr;
00370 TEAGN_TRUE_OR_THROW( TePDIUtils::loadRaster(
00371 std::string( TEPDIEXAMPLESRESPATH "cbers_rgb342_crop1.tif" ),
00372 input_image2_ptr, true ), "Error loading raster" );
00373 params.SetParameter( "input_image2_ptr" , input_image2_ptr );
00374
00375 params.SetParameter( "input_channel2" , (unsigned int)0 );
00376
00377
00378
00379 TeRasterParams mask1Params = input_image1_ptr->params();
00380 mask1Params.nBands( 1 );
00381 mask1Params.setDataType( TeUNSIGNEDCHAR, -1 );
00382
00383 TePDITypes::TePDIRasterPtrType mask_image1_ptr;
00384 TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( mask1Params,
00385 mask_image1_ptr ), "Mask alloc error" );
00386
00387 {
00388 for( int line = 0 ; line < mask_image1_ptr->params().nlines_ ;
00389 ++line )
00390 {
00391 for( int col = 0 ; col < mask_image1_ptr->params().ncols_ ;
00392 ++col )
00393 {
00394 TEAGN_TRUE_OR_THROW( mask_image1_ptr->setElement( col, line, 1, 0 ),
00395 "Error writing mask" );
00396 }
00397 }
00398 }
00399
00400 params.SetParameter( "mask_image1_ptr" , mask_image1_ptr );
00401
00402
00403
00404 TeRasterParams mask2Params = input_image2_ptr->params();
00405 mask2Params.nBands( 1 );
00406 mask2Params.setDataType( TeUNSIGNEDCHAR, -1 );
00407
00408 TePDITypes::TePDIRasterPtrType mask_image2_ptr;
00409 TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( mask2Params,
00410 mask_image2_ptr ), "Mask alloc error" );
00411
00412 {
00413 for( int line = 0 ; line < mask_image2_ptr->params().nlines_ ;
00414 ++line )
00415 {
00416 for( int col = 0 ; col < mask_image2_ptr->params().ncols_ ;
00417 ++col )
00418 {
00419 TEAGN_TRUE_OR_THROW( mask_image2_ptr->setElement( col, line, 1, 0 ),
00420 "Error writing mask" );
00421 }
00422 }
00423 }
00424
00425 params.SetParameter( "mask_image2_ptr" , mask_image2_ptr );
00426
00427
00428
00429 TeSharedPtr< TeCoordPairVect > out_tie_points_ptr( new TeCoordPairVect );
00430 params.SetParameter( "out_tie_points_ptr" , out_tie_points_ptr );
00431
00432 params.SetParameter( "matching_method",
00433 TePDIMMIOMatching::NormCrossCorrMethod );
00434
00435
00436
00437 TeGTParams gt_params;
00438 gt_params.transformation_name_ = "affine";
00439 gt_params.out_rem_strat_ = TeGTParams::LWOutRemotion;
00440 gt_params.max_dmap_error_ = 2.0;
00441 gt_params.max_imap_error_ = 2.0;
00442 params.SetParameter( "gt_params" , gt_params );
00443
00444 TeBox input_box1_proj = input_image1_ptr->params().box();
00445 TeBox input_box1;
00446 TePDIUtils::MapCoords2RasterIndexes( input_box1_proj,
00447 input_image1_ptr, input_box1 );
00448 params.SetParameter( "input_box1" , input_box1 );
00449
00450 params.SetParameter( "input_box2" , input_box1 );
00451
00452 params.SetParameter( "enable_multi_thread" , (int)1 );
00453
00454
00455
00456 params.SetParameter( "skip_geom_filter" , (int)1 );
00457
00458 params.SetParameter( "pixel_x_relation" , (double)1 );
00459 params.SetParameter( "pixel_y_relation" , (double)1 );
00460
00461 params.SetParameter( "max_tie_points" , (unsigned int)1000 );
00462 params.SetParameter( "corr_window_width" , (unsigned int)21 );
00463 params.SetParameter( "moravec_window_width" , (unsigned int)11 );
00464
00465 TeGTParams::pointer out_gt_params_ptr( new TeGTParams );
00466 params.SetParameter( "out_gt_params_ptr" , out_gt_params_ptr );
00467
00468 TePDIMMIOMatching match_instance;
00469
00470 TEAGN_TRUE_OR_THROW( match_instance.Reset( params ),
00471 "Algorithm reset error" )
00472
00473 TEAGN_LOGMSG( "Algorithm started" )
00474
00475 time_t init_time = clock() / CLOCKS_PER_SEC ;
00476
00477 TEAGN_TRUE_OR_THROW( match_instance.Apply(),
00478 "Algorithm apply error" )
00479
00480 time_t end_time = clock() / CLOCKS_PER_SEC;
00481
00482 TEAGN_LOGMSG( "Time elapsed (sameImageAndBoxesWithMaskTest): " +
00483 TeAgnostic::to_string( (long int)( end_time - init_time ) ) +
00484 " seconds" );
00485
00486
00487 {
00488 TeCoordPairVect::iterator it = out_tie_points_ptr->begin();
00489 TeCoordPairVect::iterator it_end = out_tie_points_ptr->end();
00490
00491 while( it != it_end ) {
00492 std::cout << "[" + Te2String( it->pt1.x(),1 ) + " , " +
00493 Te2String( it->pt1.y(),1 ) + "] -> [" +
00494 Te2String( it->pt2.x(),1 ) + " , " +
00495 Te2String( it->pt2.y(),1 ) + "]" << std::endl;
00496
00497 ++it;
00498 }
00499 }
00500
00501
00502
00503 raster2Tiff( input_image1_ptr, 0, TEPDIEXAMPLESBINPATH
00504 "TePDIMMIOMatching_test_sameImageAndBoxesWithMaskTest_input_image1.tif",
00505 out_tie_points_ptr, 0 );
00506 raster2Tiff( input_image2_ptr, 0, TEPDIEXAMPLESBINPATH
00507 "TePDIMMIOMatching_test_sameImageAndBoxesWithMaskTest_input_image2.tif",
00508 out_tie_points_ptr, 1 );
00509
00510
00511
00512 {
00513 TeCoordPairVect::iterator it = out_tie_points_ptr->begin();
00514 TeCoordPairVect::iterator it_end = out_tie_points_ptr->end();
00515
00516 while( it != it_end ) {
00517 TEAGN_CHECK_EPS( it->pt1.x(), it->pt2.x(), 0,
00518 "Invalid tie-point" )
00519 TEAGN_CHECK_EPS( it->pt1.y(), it->pt2.y(), 0,
00520 "Invalid tie-point" )
00521
00522 ++it;
00523 }
00524 }
00525
00526 TEAGN_CHECK_EPS( 769, out_tie_points_ptr->size(),
00527 0, "Invalid tie-points number" )
00528 }
00529
00530 void sameImageDifBoxesTest()
00531 {
00532
00533
00534 TePDIParameters params;
00535
00536
00537 TePDITypes::TePDIRasterPtrType input_image1_ptr;
00538 TEAGN_TRUE_OR_THROW( TePDIUtils::loadRaster(
00539 std::string( TEPDIEXAMPLESRESPATH "cbers_rgb342_crop1.tif" ),
00540 input_image1_ptr, true ), "Error loading raster" );
00541 params.SetParameter( "input_image1_ptr" , input_image1_ptr );
00542
00543 params.SetParameter( "input_channel1" , (unsigned int)0 );
00544
00545 TePDITypes::TePDIRasterPtrType input_image2_ptr;
00546 TEAGN_TRUE_OR_THROW( TePDIUtils::loadRaster(
00547 std::string( TEPDIEXAMPLESRESPATH "cbers_rgb342_crop1.tif" ),
00548 input_image2_ptr, true ), "Error loading raster" );
00549 params.SetParameter( "input_image2_ptr" , input_image2_ptr );
00550
00551 params.SetParameter( "input_channel2" , (unsigned int)0 );
00552
00553 TeSharedPtr< TeCoordPairVect > out_tie_points_ptr( new TeCoordPairVect );
00554 params.SetParameter( "out_tie_points_ptr" , out_tie_points_ptr );
00555
00556 params.SetParameter( "matching_method", TePDIMMIOMatching::NormCrossCorrMethod );
00557
00558
00559
00560 TeGTParams gt_params;
00561 gt_params.transformation_name_ = "affine";
00562 gt_params.out_rem_strat_ = TeGTParams::LWOutRemotion;
00563 gt_params.max_dmap_error_ = 0.5;
00564 gt_params.max_imap_error_ = 0.5;
00565 params.SetParameter( "gt_params" , gt_params );
00566
00567 TeBox input_box1( TeCoord2D( 0, 760 ) , TeCoord2D( 680, 0 ) );
00568 params.SetParameter( "input_box1" , input_box1 );
00569
00570 TeBox input_box2(
00571 TeCoord2D( 190, input_image1_ptr->params().nlines_ - 1 ) ,
00572 TeCoord2D( input_image1_ptr->params().ncols_ - 1, 227 ) );
00573 params.SetParameter( "input_box2" , input_box2 );
00574
00575
00576
00577 params.SetParameter( "pixel_x_relation" , (double)1 );
00578 params.SetParameter( "pixel_y_relation" , (double)1 );
00579
00580 params.SetParameter( "enable_multi_thread" , (int)1 );
00581
00582 params.SetParameter( "max_tie_points" , (unsigned int)1000 );
00583 params.SetParameter( "corr_window_width" , (unsigned int)21 );
00584 params.SetParameter( "moravec_window_width" , (unsigned int)11 );
00585
00586 TePDIMMIOMatching match_instance;
00587
00588 TEAGN_TRUE_OR_THROW( match_instance.Reset( params ),
00589 "Algorithm reset error" )
00590
00591 TEAGN_LOGMSG( "Algorithm started" )
00592
00593 time_t init_time = clock() / CLOCKS_PER_SEC;
00594
00595 TEAGN_TRUE_OR_THROW( match_instance.Apply(),
00596 "Algorithm apply error" )
00597
00598 time_t end_time = clock() / CLOCKS_PER_SEC;
00599
00600 TEAGN_LOGMSG( "Time elapsed (sameImageDifBoxesTest): " +
00601 TeAgnostic::to_string( (long int)( end_time - init_time ) ) +
00602 " seconds" );
00603
00604
00605 {
00606 TeCoordPairVect::iterator it = out_tie_points_ptr->begin();
00607 TeCoordPairVect::iterator it_end = out_tie_points_ptr->end();
00608
00609 while( it != it_end ) {
00610 std::cout << "[" + Te2String( it->pt1.x(),1 ) + " , " +
00611 Te2String( it->pt1.y(),1 ) + "] -> [" +
00612 Te2String( it->pt2.x(),1 ) + " , " +
00613 Te2String( it->pt2.y(),1 ) + "]" << std::endl;
00614
00615 ++it;
00616 }
00617 }
00618
00619
00620
00621 raster2Tiff( input_image1_ptr, 0, TEPDIEXAMPLESBINPATH
00622 "TePDIMMIOMatching_test_sameImageDifBoxesTest_input_image1.tif",
00623 out_tie_points_ptr, 0 );
00624 raster2Tiff( input_image2_ptr, 0, TEPDIEXAMPLESBINPATH
00625 "TePDIMMIOMatching_test_sameImageDifBoxesTest_input_image2.tif",
00626 out_tie_points_ptr, 1 );
00627
00628
00629
00630
00631 TEAGN_CHECK_EPS( 234, out_tie_points_ptr->size(),
00632 0, "Invalid tie-points number" )
00633
00634 {
00635 TeCoordPairVect::iterator it = out_tie_points_ptr->begin();
00636 TeCoordPairVect::iterator it_end = out_tie_points_ptr->end();
00637
00638 while( it != it_end ) {
00639 TEAGN_CHECK_EPS( it->pt1.x(), it->pt2.x(), 0,
00640 "Invalid tie-point" )
00641 TEAGN_CHECK_EPS( it->pt1.y(), it->pt2.y(), 0,
00642 "Invalid tie-point" )
00643
00644 ++it;
00645 }
00646 }
00647 }
00648
00649
00650 void halfsampledImageTest()
00651 {
00652
00653
00654 TePDIParameters params;
00655
00656 TePDITypes::TePDIRasterPtrType input_image1_ptr;
00657 TEAGN_TRUE_OR_THROW( TePDIUtils::loadRaster(
00658 std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ),
00659 input_image1_ptr, true ), "Error loading raster" );
00660 params.SetParameter( "input_image1_ptr" , input_image1_ptr );
00661
00662 params.SetParameter( "input_channel1" , (unsigned int)0 );
00663
00664 TePDITypes::TePDIRasterPtrType input_image2_ptr;
00665 TEAGN_TRUE_OR_THROW( TePDIUtils::loadRaster(
00666 std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop_contraste_halfsampled.tif" ),
00667 input_image2_ptr, true ), "Error loading raster" );
00668 params.SetParameter( "input_image2_ptr" , input_image2_ptr );
00669
00670 params.SetParameter( "input_channel2" , (unsigned int)0 );
00671
00672 TeSharedPtr< TeCoordPairVect > out_tie_points_ptr( new TeCoordPairVect );
00673 params.SetParameter( "out_tie_points_ptr" , out_tie_points_ptr );
00674
00675 params.SetParameter( "matching_method", TePDIMMIOMatching::NormCrossCorrMethod );
00676
00677
00678
00679 TeGTParams gt_params;
00680 gt_params.transformation_name_ = "affine";
00681 gt_params.out_rem_strat_ = TeGTParams::LWOutRemotion;
00682 gt_params.max_dmap_error_ = 2.0;
00683 gt_params.max_imap_error_ = 2.0;
00684 params.SetParameter( "gt_params" , gt_params );
00685
00686 TeBox input_box1( TeCoord2D( 122.0, 698.0 ),
00687 TeCoord2D( 730.0, 138.0 ) );
00688 params.SetParameter( "input_box1" , input_box1 );
00689
00690 TeBox input_box2( TeCoord2D( 110.0, 305.0 ),
00691 TeCoord2D( 385.0, 50.0 ) );
00692 params.SetParameter( "input_box2" , input_box2 );
00693
00694 params.SetParameter( "enable_multi_thread" , (int)1 );
00695
00696 params.SetParameter( "corr_window_width" , (unsigned int)21 );
00697 params.SetParameter( "moravec_window_width" , (unsigned int)11 );
00698
00699 params.SetParameter( "pixel_x_relation" , (double)0.5 );
00700 params.SetParameter( "pixel_y_relation" , (double)0.5 );
00701
00702 params.SetParameter( "max_tie_points" , (unsigned int)1000 );
00703
00704 TePDIMMIOMatching match_instance;
00705
00706 TEAGN_TRUE_OR_THROW( match_instance.Reset( params ),
00707 "Algorithm reset error" )
00708
00709 TEAGN_LOGMSG( "Algorithm started" )
00710
00711 time_t init_time = clock() / CLOCKS_PER_SEC;
00712
00713 TEAGN_TRUE_OR_THROW( match_instance.Apply(),
00714 "Algorithm apply error" )
00715
00716 time_t end_time = clock() / CLOCKS_PER_SEC;
00717
00718 TEAGN_LOGMSG( "Time elapsed (halfsampledImageTest): " +
00719 TeAgnostic::to_string( (long int)( end_time - init_time ) ) +
00720 " seconds" );
00721
00722
00723
00724 TeCoordPairVect::iterator it = out_tie_points_ptr->begin();
00725 TeCoordPairVect::iterator it_end = out_tie_points_ptr->end();
00726
00727 while( it != it_end ) {
00728 std::cout << "[" + Te2String( it->pt1.x(),1 ) + " , " +
00729 Te2String( it->pt1.y(),1 ) + "] -> [" +
00730 Te2String( it->pt2.x(),1 ) + " , " +
00731 Te2String( it->pt2.y(),1 ) + "]" << std::endl;
00732
00733 ++it;
00734 }
00735
00736
00737
00738 raster2Tiff( input_image1_ptr, 0, TEPDIEXAMPLESBINPATH
00739 "TePDIMMIOMatching_test_halfsampledImageTest_input_image1.tif",
00740 out_tie_points_ptr, 0 );
00741 raster2Tiff( input_image2_ptr, 0, TEPDIEXAMPLESBINPATH
00742 "TePDIMMIOMatching_test_halfsampledImageTest_input_image2.tif",
00743 out_tie_points_ptr, 1 );
00744
00745 TEAGN_WATCH( (unsigned int)out_tie_points_ptr->size() );
00746 TEAGN_CHECK_EPS( 56, out_tie_points_ptr->size(),
00747 0, "Invalid tie-points number" )
00748 }
00749
00750
00751 void halfsampledImageTest2()
00752 {
00753
00754
00755 TePDIParameters params;
00756
00757 TePDITypes::TePDIRasterPtrType input_image1_ptr;
00758 TEAGN_TRUE_OR_THROW( TePDIUtils::loadRaster(
00759 std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop_contraste_halfsampled.tif" ),
00760 input_image1_ptr, true ), "Error loading raster" );
00761 params.SetParameter( "input_image1_ptr" , input_image1_ptr );
00762
00763 params.SetParameter( "input_channel1" , (unsigned int)0 );
00764
00765 TePDITypes::TePDIRasterPtrType input_image2_ptr;
00766 TEAGN_TRUE_OR_THROW( TePDIUtils::loadRaster(
00767 std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ),
00768 input_image2_ptr, true ), "Error loading raster" );
00769 params.SetParameter( "input_image2_ptr" , input_image2_ptr );
00770
00771 params.SetParameter( "input_channel2" , (unsigned int)0 );
00772
00773 TeSharedPtr< TeCoordPairVect > out_tie_points_ptr( new TeCoordPairVect );
00774 params.SetParameter( "out_tie_points_ptr" , out_tie_points_ptr );
00775
00776 params.SetParameter( "matching_method", TePDIMMIOMatching::NormCrossCorrMethod );
00777
00778
00779
00780 TeGTParams gt_params;
00781 gt_params.transformation_name_ = "affine";
00782 gt_params.out_rem_strat_ = TeGTParams::LWOutRemotion;
00783 gt_params.max_dmap_error_ = 2.0;
00784 gt_params.max_imap_error_ = 2.0;
00785 params.SetParameter( "gt_params" , gt_params );
00786
00787 TeBox input_box1( TeCoord2D( 110.0, 305.0 ),
00788 TeCoord2D( 385.0, 50.0 ) );
00789 params.SetParameter( "input_box1" , input_box1 );
00790
00791 TeBox input_box2( TeCoord2D( 122.0, 698.0 ),
00792 TeCoord2D( 730.0, 138.0 ) );
00793 params.SetParameter( "input_box2" , input_box2 );
00794
00795 params.SetParameter( "enable_multi_thread" , (int)1 );
00796
00797
00798 params.SetParameter( "pixel_x_relation" , (double)2 );
00799 params.SetParameter( "pixel_y_relation" , (double)2 );
00800
00801 params.SetParameter( "max_tie_points" , (unsigned int)1000 );
00802 params.SetParameter( "corr_window_width" , (unsigned int)21 );
00803 params.SetParameter( "moravec_window_width" , (unsigned int)11 );
00804
00805 TePDIMMIOMatching match_instance;
00806
00807 TEAGN_TRUE_OR_THROW( match_instance.Reset( params ),
00808 "Algorithm reset error" )
00809
00810 TEAGN_LOGMSG( "Algorithm started" )
00811
00812 time_t init_time = clock() / CLOCKS_PER_SEC;
00813
00814 TEAGN_TRUE_OR_THROW( match_instance.Apply(),
00815 "Algorithm apply error" )
00816
00817 time_t end_time = clock() / CLOCKS_PER_SEC;
00818
00819 TEAGN_LOGMSG( "Time elapsed (halfsampledImageTest2): " +
00820 TeAgnostic::to_string( (long int)( end_time - init_time ) ) +
00821 " seconds" );
00822
00823
00824
00825 TeCoordPairVect::iterator it = out_tie_points_ptr->begin();
00826 TeCoordPairVect::iterator it_end = out_tie_points_ptr->end();
00827
00828 while( it != it_end ) {
00829 std::cout << "[" + Te2String( it->pt1.x(),1 ) + " , " +
00830 Te2String( it->pt1.y(),1 ) + "] -> [" +
00831 Te2String( it->pt2.x(),1 ) + " , " +
00832 Te2String( it->pt2.y(),1 ) + "]" << std::endl;
00833
00834 ++it;
00835 }
00836
00837
00838
00839 raster2Tiff( input_image1_ptr, 0, TEPDIEXAMPLESBINPATH
00840 "TePDIMMIOMatching_test_halfsampledImageTest2_input_image1.tif",
00841 out_tie_points_ptr, 0 );
00842 raster2Tiff( input_image2_ptr, 0, TEPDIEXAMPLESBINPATH
00843 "TePDIMMIOMatching_test_halfsampledImageTest2_input_image2.tif",
00844 out_tie_points_ptr, 1 );
00845
00846 TEAGN_WATCH( (unsigned int)out_tie_points_ptr->size() );
00847 TEAGN_CHECK_EPS( 56, out_tie_points_ptr->size(),
00848 0, "Invalid tie-points number" )
00849 }
00850
00851
00852 void halfsampledRotadedImageTest()
00853 {
00854
00855
00856 TePDIParameters params;
00857
00858 TePDITypes::TePDIRasterPtrType input_image1_ptr;
00859 TEAGN_TRUE_OR_THROW( TePDIUtils::loadRaster(
00860 std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ),
00861 input_image1_ptr, true ), "Error loading raster" );
00862 params.SetParameter( "input_image1_ptr" , input_image1_ptr );
00863
00864 params.SetParameter( "input_channel1" , (unsigned int)0 );
00865
00866
00867
00868 TePDITypes::TePDIRasterPtrType input_disk_image2_ptr( new TeRaster(
00869 std::string(
00870 TEPDIEXAMPLESRESPATH "cbers_b2_crop_contraste_halfsampled.tif" ),
00871 'r' ) );
00872 TEAGN_TRUE_OR_THROW( input_disk_image2_ptr->init(),
00873 "Unable to init input_image2_ptr" );
00874
00875 TePDITypes::TePDIRasterPtrType input_image2_ptr;
00876 TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster(
00877 input_image2_ptr, input_disk_image2_ptr->params(),
00878 TePDIUtils::TePDIUtilsAutoMemPol ),
00879 "Error allocating raster memory" );
00880
00881 rotateRasterClockWize( input_disk_image2_ptr, input_image2_ptr, M_PI_4 );
00882 TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( input_image2_ptr,
00883 TEPDIEXAMPLESBINPATH "TePDIMMIOMatching_test_rotatedimage.tif",
00884 TeUNSIGNEDCHAR ),
00885 "Error saving rotated image" );
00886
00887 params.SetParameter( "input_image2_ptr" , input_image2_ptr );
00888
00889
00890
00891 params.SetParameter( "input_channel2" , (unsigned int)0 );
00892
00893 TeSharedPtr< TeCoordPairVect > out_tie_points_ptr( new TeCoordPairVect );
00894 params.SetParameter( "out_tie_points_ptr" , out_tie_points_ptr );
00895
00896 params.SetParameter( "matching_method",
00897 TePDIMMIOMatching::NormCrossCorrMethod );
00898
00899 TeBox input_box1( TeCoord2D( 122.0, 698.0 ),
00900 TeCoord2D( 730.0, 138.0 ) );
00901 params.SetParameter( "input_box1" , input_box1 );
00902
00903 TeBox input_box2( TeCoord2D( 173.0, 447.0 ),
00904 TeCoord2D( 434.0, 153.0 ) );
00905 params.SetParameter( "input_box2" , input_box2 );
00906
00907 params.SetParameter( "enable_multi_thread" , (int)1 );
00908
00909 params.SetParameter( "corr_window_width" , (unsigned int)21 );
00910 params.SetParameter( "moravec_window_width" , (unsigned int)11 );
00911
00912 params.SetParameter( "pixel_x_relation" , (double)0.5 );
00913 params.SetParameter( "pixel_y_relation" , (double)0.5 );
00914
00915
00916 TePDITypes::TePDIRasterPtrType out_maximas_image1_ptr;
00917 TePDITypes::TePDIRasterPtrType out_maximas_image2_ptr;
00918 TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster(
00919 out_maximas_image1_ptr, 1, 1, 1, false, TeUNSIGNEDCHAR, 0 ),
00920 "Raster allocation error" )
00921 TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster(
00922 out_maximas_image2_ptr, 1, 1, 1, false, TeUNSIGNEDCHAR, 0 ),
00923 "Raster allocation error" )
00924 params.SetParameter( "out_maximas_image1_ptr" , out_maximas_image1_ptr );
00925 params.SetParameter( "out_maximas_image2_ptr" , out_maximas_image2_ptr );
00926
00927 TePDIMMIOMatching match_instance;
00928
00929 TEAGN_TRUE_OR_THROW( match_instance.Reset( params ),
00930 "Algorithm reset error" )
00931
00932 TEAGN_LOGMSG( "Algorithm started" )
00933
00934 time_t init_time = clock() / CLOCKS_PER_SEC;
00935
00936 TEAGN_TRUE_OR_THROW( match_instance.Apply(),
00937 "Algorithm apply error" )
00938
00939 time_t end_time = clock() / CLOCKS_PER_SEC;
00940
00941 TEAGN_LOGMSG( "Time elapsed (halfsampledRotadedImageTest): " +
00942 TeAgnostic::to_string( (long int)( end_time - init_time ) ) +
00943 " seconds" );
00944
00945
00946
00947 TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( out_maximas_image1_ptr,
00948 TEPDIEXAMPLESBINPATH "TePDIMMIOMatching_halfsampledRotadedImageTest_maximas_image1.tif",
00949 true ), "Error generating TIF" )
00950 TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( out_maximas_image2_ptr,
00951 TEPDIEXAMPLESBINPATH "TePDIMMIOMatching_halfsampledRotadedImageTest_maximas_image2.tif",
00952 true ), "Error generating TIF" )
00953
00954
00955
00956 TeCoordPairVect::iterator it = out_tie_points_ptr->begin();
00957 TeCoordPairVect::iterator it_end = out_tie_points_ptr->end();
00958
00959 while( it != it_end ) {
00960 std::cout << "[" + Te2String( it->pt1.x(),1 ) + " , " +
00961 Te2String( it->pt1.y(),1 ) + "] -> [" +
00962 Te2String( it->pt2.x(),1 ) + " , " +
00963 Te2String( it->pt2.y(),1 ) + "]" << std::endl;
00964
00965 ++it;
00966 }
00967
00968
00969
00970 raster2Tiff( input_image1_ptr, 0, TEPDIEXAMPLESBINPATH
00971 "TePDIMMIOMatching_test_halfsampledRotadedImageTest_input_image1.tif",
00972 out_tie_points_ptr, 0 );
00973 raster2Tiff( input_image2_ptr, 0, TEPDIEXAMPLESBINPATH
00974 "TePDIMMIOMatching_test_halfsampledRotadedImageTest_input_image2.tif",
00975 out_tie_points_ptr, 1 );
00976
00977 TEAGN_WATCH( (unsigned int)out_tie_points_ptr->size() );
00978 TEAGN_CHECK_EPS( 25, out_tie_points_ptr->size(),
00979 0, "Invalid tie-points number" )
00980 }
00981
00982
00983 void HRCxCCDTest()
00984 {
00985
00986
00987 TePDIParameters params;
00988
00989 TePDITypes::TePDIRasterPtrType input_image1_ptr;
00990 TEAGN_TRUE_OR_THROW( TePDIUtils::loadRaster(
00991 std::string( TEPDIEXAMPLESRESPATH "cbers2b_hrc_crop.tif" ),
00992 input_image1_ptr, true ), "Error loading raster" );
00993 params.SetParameter( "input_image1_ptr" , input_image1_ptr );
00994
00995 params.SetParameter( "input_channel1" , (unsigned int)0 );
00996
00997 TePDITypes::TePDIRasterPtrType input_image2_ptr;
00998 TEAGN_TRUE_OR_THROW( TePDIUtils::loadRaster(
00999 std::string( TEPDIEXAMPLESRESPATH "cbers2b_rgb342_crop.tif" ),
01000 input_image2_ptr, true ), "Error loading raster" );
01001 params.SetParameter( "input_image2_ptr" , input_image2_ptr );
01002
01003 params.SetParameter( "input_channel2" , (unsigned int)2 );
01004
01005 TeSharedPtr< TeCoordPairVect > out_tie_points_ptr( new TeCoordPairVect );
01006 params.SetParameter( "out_tie_points_ptr" , out_tie_points_ptr );
01007
01008 params.SetParameter( "matching_method", TePDIMMIOMatching::NormCrossCorrMethod );
01009
01010
01011
01012 TeGTParams gt_params;
01013 gt_params.transformation_name_ = "affine";
01014 gt_params.out_rem_strat_ = TeGTParams::LWOutRemotion;
01015 gt_params.max_dmap_error_ = 2;
01016 gt_params.max_imap_error_ = 16;
01017 params.SetParameter( "gt_params" , gt_params );
01018
01019 params.SetParameter( "pixel_x_relation" , input_image1_ptr->params().resx_ /
01020 input_image2_ptr->params().resx_ );
01021 params.SetParameter( "pixel_y_relation" , input_image1_ptr->params().resy_ /
01022 input_image2_ptr->params().resy_ );
01023
01024 params.SetParameter( "enable_multi_thread" , (int)1 );
01025
01026 params.SetParameter( "max_tie_points" , (unsigned int)1000 );
01027
01028 TePDIMMIOMatching match_instance;
01029
01030 TEAGN_TRUE_OR_THROW( match_instance.Reset( params ),
01031 "Algorithm reset error" )
01032
01033 TEAGN_LOGMSG( "Algorithm started" )
01034
01035 time_t init_time = clock() / CLOCKS_PER_SEC;
01036
01037 TEAGN_TRUE_OR_THROW( match_instance.Apply(),
01038 "Algorithm apply error" )
01039
01040 time_t end_time = clock() / CLOCKS_PER_SEC;
01041
01042 TEAGN_LOGMSG( "Time elapsed (sameImageDifBoxesTest): " +
01043 TeAgnostic::to_string( (long int)( end_time - init_time ) ) +
01044 " seconds" );
01045
01046
01047 {
01048 TeCoordPairVect::iterator it = out_tie_points_ptr->begin();
01049 TeCoordPairVect::iterator it_end = out_tie_points_ptr->end();
01050
01051 while( it != it_end ) {
01052 std::cout << "[" + Te2String( it->pt1.x(),1 ) + " , " +
01053 Te2String( it->pt1.y(),1 ) + "] -> [" +
01054 Te2String( it->pt2.x(),1 ) + " , " +
01055 Te2String( it->pt2.y(),1 ) + "]" << std::endl;
01056
01057 ++it;
01058 }
01059 }
01060
01061
01062
01063 raster2Tiff( input_image1_ptr, 0, TEPDIEXAMPLESBINPATH
01064 "TePDIMMIOMatching_HRCxCCDTest_input_image1.tif",
01065 out_tie_points_ptr, 0 );
01066 raster2Tiff( input_image2_ptr, 0, TEPDIEXAMPLESBINPATH
01067 "TePDIMMIOMatching_HRCxCCDTest_input_image2.tif",
01068 out_tie_points_ptr, 1 );
01069
01070
01071
01072
01073 TEAGN_CHECK_EPS( 22, out_tie_points_ptr->size(),
01074 0, "Invalid tie-points number" )
01075 }
01076
01077 int main()
01078 {
01079 TEAGN_LOGMSG( "Test started." );
01080
01081 TeStdIOProgress pi;
01082 TeProgress::setProgressInterf( dynamic_cast< TeProgressBase* >( &pi ) );
01083
01084 time_t init_time = clock() / CLOCKS_PER_SEC;
01085
01086 sameImageAndBoxesTest();
01087 sameImageAndBoxesWithMaskTest();
01088 sameImageDifBoxesTest();
01089 halfsampledImageTest();
01090 halfsampledImageTest2();
01091 halfsampledRotadedImageTest();
01092 HRCxCCDTest();
01093
01094 time_t end_time = clock() / CLOCKS_PER_SEC;
01095
01096 TEAGN_LOGMSG( "Total elapsed time: " +
01097 TeAgnostic::to_string( (long int)( end_time - init_time ) ) +
01098 " seconds" );
01099
01100 TEAGN_LOGMSG( "Test OK." );
01101 return EXIT_SUCCESS;
01102 }
01103