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