TePDIMorfFilter_test.cpp

Shows how to use this class.

00001 #define TEAGN_ENABLE_STDOUT_LOG
00002 
00003 #include <TePDIExamplesBase.hpp>
00004 #include <TePDIMorfFilter.hpp>
00005 #include <TePDIFilterMask.hpp>
00006 #include <TePDIParameters.hpp>
00007 #include <TeAgnostic.h>
00008 #include <TePDIUtils.hpp>
00009 #include <TeProgress.h>
00010 #include <TeStdIOProgress.h>
00011 
00012 void Dilation_1_iteration_test()
00013 {
00014   TePDIParameters params;
00015 
00016   TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00017     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00018   TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00019   params.SetParameter( "input_image", inRaster );
00020 
00021   TePDITypes::TePDIRasterPtrType outRaster;
00022   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00023     1, 1, 1, false, TeDOUBLE, 0 ), "RAM Raster Alloc error" );
00024   params.SetParameter( "output_image", outRaster );
00025 
00026   std::vector<int> channels;
00027   channels.push_back( 0 );
00028   params.SetParameter( "channels", channels );
00029 
00030   params.SetParameter( "filter_mask", TePDIFilterMask::create_MorfMtot() );
00031 
00032   params.SetParameter( "filter_type", TePDIMorfFilter::TePDIMDilationType );
00033 
00034   params.SetParameter( "iterations", (int)1 );
00035 
00036   TePDIMorfFilter filter;
00037 
00038   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00039     "Invalid Parameters" );
00040 
00041   TEAGN_TRUE_OR_THROW( filter.Apply(),
00042     "Apply error" );
00043     
00044   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00045     TEPDIEXAMPLESBINPATH "Dilation_test_1_iteration.tif" ), "GeoTIF generation error" );
00046 }
00047 
00048 
00049 void Dilation_2_iterations_test()
00050 {
00051   TePDIParameters params;
00052 
00053   TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00054     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00055   TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00056   params.SetParameter( "input_image", inRaster );
00057 
00058   TePDITypes::TePDIRasterPtrType outRaster;
00059   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00060     1, 1, 1, false, TeDOUBLE, 0 ), "RAM Raster Alloc error" );
00061   params.SetParameter( "output_image", outRaster );
00062 
00063   std::vector<int> channels;
00064   channels.push_back( 0 );
00065   params.SetParameter( "channels", channels );
00066 
00067   params.SetParameter( "filter_mask", TePDIFilterMask::create_MorfMtot() );
00068 
00069   params.SetParameter( "filter_type", TePDIMorfFilter::TePDIMDilationType );
00070 
00071   params.SetParameter( "iterations", (int)2 );
00072 
00073   TePDIMorfFilter filter;
00074 
00075   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00076     "Invalid Parameters" );
00077 
00078   TEAGN_TRUE_OR_THROW( filter.Apply(),
00079     "Apply error" );
00080     
00081   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00082     TEPDIEXAMPLESBINPATH "Dilation_test_2_iterations.tif" ), "GeoTIF generation error" );
00083 }
00084 
00085 
00086 void Dilation_3_iterations_test()
00087 {
00088   TePDIParameters params;
00089 
00090   TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00091     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00092   TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00093   params.SetParameter( "input_image", inRaster );
00094 
00095   TePDITypes::TePDIRasterPtrType outRaster;
00096   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00097     1, 1, 1, false, TeDOUBLE, 0 ), "RAM Raster Alloc error" );
00098   params.SetParameter( "output_image", outRaster );
00099 
00100   std::vector<int> channels;
00101   channels.push_back( 0 );
00102   params.SetParameter( "channels", channels );
00103 
00104   params.SetParameter( "filter_mask", TePDIFilterMask::create_MorfMtot() );
00105 
00106   params.SetParameter( "filter_type", TePDIMorfFilter::TePDIMDilationType );
00107 
00108   params.SetParameter( "iterations", (int)3 );
00109 
00110   TePDIMorfFilter filter;
00111 
00112   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00113     "Invalid Parameters" );
00114 
00115   TEAGN_TRUE_OR_THROW( filter.Apply(),
00116     "Apply error" );
00117     
00118   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00119     TEPDIEXAMPLESBINPATH "Dilation_test_3_iterations.tif" ), "GeoTIF generation error" );
00120 }
00121 
00122 
00123 void Dilation_4_iterations_test()
00124 {
00125   TePDIParameters params;
00126 
00127   TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00128     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00129   TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00130   params.SetParameter( "input_image", inRaster );
00131 
00132   TePDITypes::TePDIRasterPtrType outRaster;
00133   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00134     1, 1, 1, false, TeDOUBLE, 0 ), "RAM Raster Alloc error" );
00135   params.SetParameter( "output_image", outRaster );
00136 
00137   std::vector<int> channels;
00138   channels.push_back( 0 );
00139   params.SetParameter( "channels", channels );
00140 
00141   params.SetParameter( "filter_mask", TePDIFilterMask::create_MorfMtot() );
00142 
00143   params.SetParameter( "filter_type", TePDIMorfFilter::TePDIMDilationType );
00144 
00145   params.SetParameter( "iterations", (int)4 );
00146 
00147   TePDIMorfFilter filter;
00148 
00149   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00150     "Invalid Parameters" );
00151 
00152   TEAGN_TRUE_OR_THROW( filter.Apply(),
00153     "Apply error" );
00154     
00155   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00156     TEPDIEXAMPLESBINPATH "Dilation_test_4_iterations.tif" ), "GeoTIF generation error" );
00157 }
00158 
00159 
00160 void Dilation_with_dummy_test()
00161 {
00162   TePDIParameters params;
00163 
00164   TePDITypes::TePDIRasterPtrType diskRaster( new TeRaster(
00165     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00166   TEAGN_TRUE_OR_THROW( diskRaster->init(), "Unable to init diskRaster" );
00167   
00168   TePDITypes::TePDIRasterPtrType inRaster;
00169   TeRasterParams inRaster_params = diskRaster->params();
00170   inRaster_params.nBands( 3 );
00171   inRaster_params.setDummy( 0, -1 );
00172   inRaster_params.setPhotometric( TeRasterParams::TeMultiBand, -1 );
00173   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( inRaster,
00174     inRaster_params, TePDIUtils::TePDIUtilsAutoMemPol ), 
00175     "Unable to alloc RAM Raster" );
00176   TEAGN_TRUE_OR_THROW( TePDIUtils::TeCopyRasterPixels( diskRaster, 0,
00177     inRaster, 0, false, false ), "Unable to copy raster pixels" );
00178   TEAGN_TRUE_OR_THROW( TePDIUtils::TeCopyRasterPixels( diskRaster, 0,
00179     inRaster, 1, false, false ), "Unable to copy raster pixels" );
00180   TEAGN_TRUE_OR_THROW( TePDIUtils::TeCopyRasterPixels( diskRaster, 0,
00181     inRaster, 2, false, false ), "Unable to copy raster pixels" );
00182   params.SetParameter( "input_image", inRaster );  
00183 
00184   TePDITypes::TePDIRasterPtrType outRaster;
00185   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00186     1, 1, 1, false, TeDOUBLE, 0 ), "RAM Raster Alloc error" );
00187   params.SetParameter( "output_image", outRaster );
00188 
00189   std::vector<int> channels;
00190   channels.push_back( 0 );
00191   channels.push_back( 1 );
00192   channels.push_back( 2 );
00193   params.SetParameter( "channels", channels );
00194 
00195   params.SetParameter( "filter_mask", TePDIFilterMask::create_MorfMtot() );
00196 
00197   params.SetParameter( "filter_type", TePDIMorfFilter::TePDIMDilationType );
00198 
00199   params.SetParameter( "iterations", (int)3 );
00200 
00201   TePDIMorfFilter filter;
00202 
00203   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00204     "Invalid Parameters" );
00205 
00206   TEAGN_TRUE_OR_THROW( filter.Apply(),
00207     "Apply error" );
00208 
00209   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00210     TEPDIEXAMPLESBINPATH "Dilation_with_dummy_test.tif" ), "GeoTIF generation error" );
00211 }
00212 
00213 
00214 void Erosion_1_iteration_test()
00215 {
00216   TePDIParameters params;
00217 
00218   TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00219     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00220   TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00221   params.SetParameter( "input_image", inRaster );
00222 
00223   TePDITypes::TePDIRasterPtrType outRaster;
00224   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00225     1, 1, 1, false, TeDOUBLE, 0 ), "RAM Raster Alloc error" );
00226   params.SetParameter( "output_image", outRaster );
00227 
00228   std::vector<int> channels;
00229   channels.push_back( 0 );
00230   params.SetParameter( "channels", channels );
00231 
00232   params.SetParameter( "filter_mask", TePDIFilterMask::create_MorfMtot() );
00233 
00234   params.SetParameter( "filter_type", TePDIMorfFilter::TePDIMErosionType );
00235 
00236   params.SetParameter( "iterations", (int)1 );
00237 
00238   TePDIMorfFilter filter;
00239 
00240   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00241     "Invalid Parameters" );
00242 
00243   TEAGN_TRUE_OR_THROW( filter.Apply(),
00244     "Apply error" );
00245 
00246   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00247     TEPDIEXAMPLESBINPATH "Erosion_1_iteration_test.tif" ), "GeoTIF generation error" );
00248 }
00249 
00250 
00251 void Erosion_2_iterations_test()
00252 {
00253   TePDIParameters params;
00254 
00255   TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00256     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00257   TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00258   params.SetParameter( "input_image", inRaster );
00259 
00260   TePDITypes::TePDIRasterPtrType outRaster;
00261   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00262     1, 1, 1, false, TeDOUBLE, 0 ), "RAM Raster Alloc error" );
00263   params.SetParameter( "output_image", outRaster );
00264 
00265   std::vector<int> channels;
00266   channels.push_back( 0 );
00267   params.SetParameter( "channels", channels );
00268 
00269   params.SetParameter( "filter_mask", TePDIFilterMask::create_MorfMtot() );
00270 
00271   params.SetParameter( "filter_type", TePDIMorfFilter::TePDIMErosionType );
00272 
00273   params.SetParameter( "iterations", (int)2 );
00274 
00275   TePDIMorfFilter filter;
00276 
00277   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00278     "Invalid Parameters" );
00279 
00280   TEAGN_TRUE_OR_THROW( filter.Apply(),
00281     "Apply error" );
00282 
00283   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00284     TEPDIEXAMPLESBINPATH "Erosion_2_iterations_test.tif" ), "GeoTIF generation error" );
00285 }
00286 
00287 
00288 void Erosion_3_iterations_test()
00289 {
00290   TePDIParameters params;
00291 
00292   TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00293     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00294   TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00295   params.SetParameter( "input_image", inRaster );
00296 
00297   TePDITypes::TePDIRasterPtrType outRaster;
00298   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00299     1, 1, 1, false, TeDOUBLE, 0 ), "RAM Raster Alloc error" );
00300   params.SetParameter( "output_image", outRaster );
00301 
00302   std::vector<int> channels;
00303   channels.push_back( 0 );
00304   params.SetParameter( "channels", channels );
00305 
00306   params.SetParameter( "filter_mask", TePDIFilterMask::create_MorfMtot() );
00307 
00308   params.SetParameter( "filter_type", TePDIMorfFilter::TePDIMErosionType );
00309 
00310   params.SetParameter( "iterations", (int)3 );
00311 
00312   TePDIMorfFilter filter;
00313 
00314   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00315     "Invalid Parameters" );
00316 
00317   TEAGN_TRUE_OR_THROW( filter.Apply(),
00318     "Apply error" );
00319 
00320   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00321     TEPDIEXAMPLESBINPATH "Erosion_3_iteration_test.tif" ), "GeoTIF generation error" );
00322 }
00323 
00324 
00325 void Erosion_4_iterations_test()
00326 {
00327   TePDIParameters params;
00328 
00329   TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00330     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00331   TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00332   params.SetParameter( "input_image", inRaster );
00333 
00334   TePDITypes::TePDIRasterPtrType outRaster;
00335   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00336     1, 1, 1, false, TeDOUBLE, 0 ), "RAM Raster Alloc error" );
00337   params.SetParameter( "output_image", outRaster );
00338 
00339   std::vector<int> channels;
00340   channels.push_back( 0 );
00341   params.SetParameter( "channels", channels );
00342 
00343   params.SetParameter( "filter_mask", TePDIFilterMask::create_MorfMtot() );
00344 
00345   params.SetParameter( "filter_type", TePDIMorfFilter::TePDIMErosionType );
00346 
00347   params.SetParameter( "iterations", (int)4 );
00348 
00349   TePDIMorfFilter filter;
00350 
00351   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00352     "Invalid Parameters" );
00353 
00354   TEAGN_TRUE_OR_THROW( filter.Apply(),
00355     "Apply error" );
00356 
00357   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00358     TEPDIEXAMPLESBINPATH "Erosion_4_iteration_test.tif" ), "GeoTIF generation error" );
00359 }
00360 
00361 
00362 void Erosion_with_dummy_test()
00363 {
00364   TePDIParameters params;
00365 
00366   TePDITypes::TePDIRasterPtrType diskRaster( new TeRaster(
00367     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00368   TEAGN_TRUE_OR_THROW( diskRaster->init(), "Unable to init diskRaster" );
00369   
00370   TePDITypes::TePDIRasterPtrType inRaster;
00371   TeRasterParams inRaster_params = diskRaster->params();
00372   inRaster_params.nBands( 3 );
00373   inRaster_params.setDummy( 0, -1 );
00374   inRaster_params.setPhotometric( TeRasterParams::TeMultiBand, -1 );
00375   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( inRaster,
00376     inRaster_params, TePDIUtils::TePDIUtilsAutoMemPol ), 
00377     "Unable to alloc RAM Raster" );
00378   TEAGN_TRUE_OR_THROW( TePDIUtils::TeCopyRasterPixels( diskRaster, 0,
00379     inRaster, 0, false, false ), "Unable to copy raster pixels" );
00380   TEAGN_TRUE_OR_THROW( TePDIUtils::TeCopyRasterPixels( diskRaster, 0,
00381     inRaster, 1, false, false ), "Unable to copy raster pixels" );
00382   TEAGN_TRUE_OR_THROW( TePDIUtils::TeCopyRasterPixels( diskRaster, 0,
00383     inRaster, 2, false, false ), "Unable to copy raster pixels" );
00384   params.SetParameter( "input_image", inRaster );  
00385 
00386   TePDITypes::TePDIRasterPtrType outRaster;
00387   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00388     1, 1, 1, false, TeDOUBLE, 0 ), "RAM Raster Alloc error" );
00389   params.SetParameter( "output_image", outRaster );
00390 
00391   std::vector<int> channels;
00392   channels.push_back( 0 );
00393   channels.push_back( 1 );
00394   channels.push_back( 2 );
00395   params.SetParameter( "channels", channels );
00396 
00397   params.SetParameter( "filter_mask", TePDIFilterMask::create_MorfMtot() );
00398 
00399   params.SetParameter( "filter_type", TePDIMorfFilter::TePDIMErosionType );
00400 
00401   params.SetParameter( "iterations", (int)3 );
00402 
00403   TePDIMorfFilter filter;
00404 
00405   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00406     "Invalid Parameters" );
00407 
00408   TEAGN_TRUE_OR_THROW( filter.Apply(),
00409     "Apply error" );
00410 
00411   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00412     TEPDIEXAMPLESBINPATH "Erosion_with_dummy_test.tif" ), "GeoTIF generation error" );
00413 }
00414 
00415 
00416 void Median_1_iteration_test()
00417 {
00418   TePDIParameters params;
00419 
00420   TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00421     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00422   TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00423   params.SetParameter( "input_image", inRaster );
00424 
00425   TePDITypes::TePDIRasterPtrType outRaster;
00426   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00427     1, 1, 1, false, TeDOUBLE, 0 ), "RAM Raster Alloc error" );
00428   params.SetParameter( "output_image", outRaster );
00429 
00430   std::vector<int> channels;
00431   channels.push_back( 0 );
00432   params.SetParameter( "channels", channels );
00433 
00434   params.SetParameter( "filter_mask", TePDIFilterMask::create_MorfMtot() );
00435 
00436   params.SetParameter( "filter_type", TePDIMorfFilter::TePDIMMedianType );
00437 
00438   params.SetParameter( "iterations", (int)1 );
00439 
00440   TePDIMorfFilter filter;
00441 
00442   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00443     "Invalid Parameters" );
00444 
00445   TEAGN_TRUE_OR_THROW( filter.Apply(),
00446     "Apply error" );
00447 
00448   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00449     TEPDIEXAMPLESBINPATH "Median_1_iteration_test.tif" ), "GeoTIF generation error" );
00450 }
00451 
00452 
00453 void Median_2_iterations_test()
00454 {
00455   TePDIParameters params;
00456 
00457   TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00458     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00459   TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00460   params.SetParameter( "input_image", inRaster );
00461 
00462   TePDITypes::TePDIRasterPtrType outRaster;
00463   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00464     1, 1, 1, false, TeDOUBLE, 0 ), "RAM Raster Alloc error" );
00465   params.SetParameter( "output_image", outRaster );
00466 
00467   std::vector<int> channels;
00468   channels.push_back( 0 );
00469   params.SetParameter( "channels", channels );
00470 
00471   params.SetParameter( "filter_mask", TePDIFilterMask::create_MorfMtot() );
00472 
00473   params.SetParameter( "filter_type", TePDIMorfFilter::TePDIMMedianType );
00474 
00475   params.SetParameter( "iterations", (int)2 );
00476 
00477   TePDIMorfFilter filter;
00478 
00479   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00480     "Invalid Parameters" );
00481 
00482   TEAGN_TRUE_OR_THROW( filter.Apply(),
00483     "Apply error" );
00484 
00485   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00486     TEPDIEXAMPLESBINPATH "Median_2_iterations_test.tif" ), "GeoTIF generation error" );
00487 }
00488 
00489 
00490 void Median_3_iterations_test()
00491 {
00492   TePDIParameters params;
00493 
00494   TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00495     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00496   TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00497   params.SetParameter( "input_image", inRaster );
00498 
00499   TePDITypes::TePDIRasterPtrType outRaster;
00500   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00501     1, 1, 1, false, TeDOUBLE, 0 ), "RAM Raster Alloc error" );
00502   params.SetParameter( "output_image", outRaster );
00503 
00504   std::vector<int> channels;
00505   channels.push_back( 0 );
00506   params.SetParameter( "channels", channels );
00507 
00508   params.SetParameter( "filter_mask", TePDIFilterMask::create_MorfMtot() );
00509 
00510   params.SetParameter( "filter_type", TePDIMorfFilter::TePDIMMedianType );
00511 
00512   params.SetParameter( "iterations", (int)3 );
00513 
00514   TePDIMorfFilter filter;
00515 
00516   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00517     "Invalid Parameters" );
00518 
00519   TEAGN_TRUE_OR_THROW( filter.Apply(),
00520     "Apply error" );
00521 
00522   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00523     TEPDIEXAMPLESBINPATH "Median_3_iterations_test.tif" ), "GeoTIF generation error" );
00524 }
00525 
00526 
00527 void Median_4_iterations_test()
00528 {
00529   TePDIParameters params;
00530 
00531   TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00532     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00533   TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00534   params.SetParameter( "input_image", inRaster );
00535 
00536   TePDITypes::TePDIRasterPtrType outRaster;
00537   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00538     1, 1, 1, false, TeDOUBLE, 0 ), "RAM Raster Alloc error" );
00539   params.SetParameter( "output_image", outRaster );
00540 
00541   std::vector<int> channels;
00542   channels.push_back( 0 );
00543   params.SetParameter( "channels", channels );
00544 
00545   params.SetParameter( "filter_mask", TePDIFilterMask::create_MorfMtot() );
00546 
00547   params.SetParameter( "filter_type", TePDIMorfFilter::TePDIMMedianType );
00548 
00549   params.SetParameter( "iterations", (int)4 );
00550 
00551   TePDIMorfFilter filter;
00552 
00553   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00554     "Invalid Parameters" );
00555 
00556   TEAGN_TRUE_OR_THROW( filter.Apply(),
00557     "Apply error" );
00558 
00559   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00560     TEPDIEXAMPLESBINPATH "Median_4_iterations_test.tif" ), "GeoTIF generation error" );
00561 }
00562 
00563 
00564 void Median_with_dummy_test()
00565 {
00566   TePDIParameters params;
00567 
00568   TePDITypes::TePDIRasterPtrType diskRaster( new TeRaster(
00569     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00570   TEAGN_TRUE_OR_THROW( diskRaster->init(), "Unable to init diskRaster" );
00571   
00572   TePDITypes::TePDIRasterPtrType inRaster;
00573   TeRasterParams inRaster_params = diskRaster->params();
00574   inRaster_params.nBands( 3 );
00575   inRaster_params.setDummy( 0, -1 );
00576   inRaster_params.setPhotometric( TeRasterParams::TeMultiBand, -1 );
00577   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( inRaster,
00578     inRaster_params, TePDIUtils::TePDIUtilsAutoMemPol ), 
00579     "Unable to alloc RAM Raster" );
00580   TEAGN_TRUE_OR_THROW( TePDIUtils::TeCopyRasterPixels( diskRaster, 0,
00581     inRaster, 0, false, false ), "Unable to copy raster pixels" );
00582   TEAGN_TRUE_OR_THROW( TePDIUtils::TeCopyRasterPixels( diskRaster, 0,
00583     inRaster, 1, false, false ), "Unable to copy raster pixels" );
00584   TEAGN_TRUE_OR_THROW( TePDIUtils::TeCopyRasterPixels( diskRaster, 0,
00585     inRaster, 2, false, false ), "Unable to copy raster pixels" );
00586   params.SetParameter( "input_image", inRaster );   
00587 
00588   TePDITypes::TePDIRasterPtrType outRaster;
00589   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00590     1, 1, 1, false, TeDOUBLE, 0 ), "RAM Raster Alloc error" );
00591   params.SetParameter( "output_image", outRaster );
00592 
00593   std::vector<int> channels;
00594   channels.push_back( 0 );
00595   channels.push_back( 1 );
00596   channels.push_back( 2 );
00597   params.SetParameter( "channels", channels );
00598 
00599   params.SetParameter( "filter_mask", TePDIFilterMask::create_MorfMtot() );
00600 
00601   params.SetParameter( "filter_type", TePDIMorfFilter::TePDIMMedianType );
00602 
00603   params.SetParameter( "iterations", (int)3 );
00604 
00605   TePDIMorfFilter filter;
00606 
00607   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00608     "Invalid Parameters" );
00609 
00610   TEAGN_TRUE_OR_THROW( filter.Apply(),
00611     "Apply error" );
00612 
00613   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00614     TEPDIEXAMPLESBINPATH "Median_with_dummy_test.tif" ), "GeoTIF generation error" );
00615 }
00616 
00617 
00618 void Mode_1_iteration_test()
00619 {
00620   TePDIParameters params;
00621 
00622   TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00623     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00624   TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00625   params.SetParameter( "input_image", inRaster );
00626 
00627   TePDITypes::TePDIRasterPtrType outRaster;
00628   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00629     1, 1, 1, false, TeDOUBLE, 0 ), "RAM Raster Alloc error" );
00630   params.SetParameter( "output_image", outRaster );
00631 
00632   std::vector<int> channels;
00633   channels.push_back( 0 );
00634   params.SetParameter( "channels", channels );
00635 
00636   params.SetParameter( "filter_mask", 
00637     TePDIFilterMask::create_MorfMtot() );
00638 
00639   params.SetParameter( "filter_type", 
00640     TePDIMorfFilter::TePDIMModeType );
00641 
00642   params.SetParameter( "iterations", (int)1 );
00643 
00644   TePDIMorfFilter filter;
00645 
00646   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00647     "Invalid Parameters" );
00648 
00649   TEAGN_TRUE_OR_THROW( filter.Apply(),
00650     "Apply error" );
00651 
00652   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00653     TEPDIEXAMPLESBINPATH "Mode_1_iteration_test.tif" ), 
00654     "GeoTIF generation error" );
00655 }
00656 
00657 void Mode_2_iteration_test()
00658 {
00659   TePDIParameters params;
00660 
00661   TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00662     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00663   TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00664   params.SetParameter( "input_image", inRaster );
00665 
00666   TePDITypes::TePDIRasterPtrType outRaster;
00667   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00668     1, 1, 1, false, TeDOUBLE, 0 ), "RAM Raster Alloc error" );
00669   params.SetParameter( "output_image", outRaster );
00670 
00671   std::vector<int> channels;
00672   channels.push_back( 0 );
00673   params.SetParameter( "channels", channels );
00674 
00675   params.SetParameter( "filter_mask", 
00676     TePDIFilterMask::create_MorfMtot() );
00677 
00678   params.SetParameter( "filter_type", 
00679     TePDIMorfFilter::TePDIMModeType );
00680 
00681   params.SetParameter( "iterations", (int)2 );
00682 
00683   TePDIMorfFilter filter;
00684 
00685   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00686     "Invalid Parameters" );
00687 
00688   TEAGN_TRUE_OR_THROW( filter.Apply(),
00689     "Apply error" );
00690 
00691   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00692     TEPDIEXAMPLESBINPATH "Mode_2_iteration_test.tif" ), 
00693     "GeoTIF generation error" );
00694 }
00695 
00696 void Mode_3_iteration_test()
00697 {
00698   TePDIParameters params;
00699 
00700   TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00701     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00702   TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00703   params.SetParameter( "input_image", inRaster );
00704 
00705   TePDITypes::TePDIRasterPtrType outRaster;
00706   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00707     1, 1, 1, false, TeDOUBLE, 0 ), "RAM Raster Alloc error" );
00708   params.SetParameter( "output_image", outRaster );
00709 
00710   std::vector<int> channels;
00711   channels.push_back( 0 );
00712   params.SetParameter( "channels", channels );
00713 
00714   params.SetParameter( "filter_mask", 
00715     TePDIFilterMask::create_MorfMtot() );
00716 
00717   params.SetParameter( "filter_type", 
00718     TePDIMorfFilter::TePDIMModeType );
00719 
00720   params.SetParameter( "iterations", (int)3 );
00721 
00722   TePDIMorfFilter filter;
00723 
00724   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00725     "Invalid Parameters" );
00726 
00727   TEAGN_TRUE_OR_THROW( filter.Apply(),
00728     "Apply error" );
00729 
00730   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00731     TEPDIEXAMPLESBINPATH "Mode_3_iteration_test.tif" ), 
00732     "GeoTIF generation error" );
00733 }
00734 
00735 int main()
00736 {
00737   TEAGN_LOGMSG( "Test started." );
00738 
00739   try{
00740     TeStdIOProgress pi;
00741     TeProgress::setProgressInterf( dynamic_cast< TeProgressBase* >( &pi ) );
00742 
00743     Mode_1_iteration_test();
00744     Mode_2_iteration_test();
00745     Mode_3_iteration_test();
00746     Dilation_1_iteration_test();
00747     Dilation_2_iterations_test();
00748     Dilation_3_iterations_test();
00749     Dilation_4_iterations_test();
00750     Dilation_with_dummy_test();
00751     Erosion_1_iteration_test();
00752     Erosion_2_iterations_test();
00753     Erosion_3_iterations_test();
00754     Erosion_4_iterations_test();
00755     Erosion_with_dummy_test();
00756     Median_1_iteration_test();
00757     Median_2_iterations_test();
00758     Median_3_iterations_test();
00759     Median_4_iterations_test();
00760     Median_with_dummy_test();
00761   }
00762   catch( const TeException& e ){
00763     TEAGN_LOGERR( "Test Failed - " + e.message() );
00764     return EXIT_FAILURE;
00765   } 
00766 
00767   TEAGN_LOGMSG( "Test OK." );
00768   return EXIT_SUCCESS;
00769 }

Generated on Sun Jul 29 04:01:03 2012 for TerraLib - Development Source by  doxygen 1.5.3