00001 #define TEAGN_ENABLE_STDOUT_LOG
00002
00003 #include <TePDIExamplesBase.hpp>
00004
00005 #include <TePDIContrast.hpp>
00006 #include <TePDIParameters.hpp>
00007 #include <TePDIUtils.hpp>
00008 #include <TePDIRgbPaletteFunctions.hpp>
00009
00010 #include <TeRaster.h>
00011 #include <TeDataTypes.h>
00012 #include <TeInitRasterDecoders.h>
00013 #include <TeProgress.h>
00014 #include <TeStdIOProgress.h>
00015 #include <TeTime.h>
00016
00017 #include <TeAgnostic.h>
00018
00019 #include <string>
00020
00021 void TePDIContrastMinMax_autolevels_test()
00022 {
00023 TePDIParameters params;
00024
00025 TePDIContrast::TePDIContrastType contrast_type =
00026 TePDIContrast::TePDIContrastMinMax;
00027 params.SetParameter( "contrast_type", contrast_type );
00028
00029 TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00030 std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00031 TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00032 params.SetParameter( "input_image", inRaster );
00033
00034 TePDITypes::TePDIRasterPtrType outRaster;
00035 TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00036 1, 1, 1, false, TeUNSIGNEDCHAR, 0 ), "RAM Raster Alloc error" );
00037 params.SetParameter( "output_image", outRaster );
00038
00039 params.SetParameter( "input_band", (int)0 );
00040 params.SetParameter( "output_band", (int)0 );
00041
00042 TePDITypes::TePDILutPtrType outlut( new TePDITypes::TePDILutType );
00043 params.SetParameter( "outlut", outlut );
00044
00045 TePDIContrast contra;
00046
00047 TEAGN_TRUE_OR_THROW( contra.Reset( params ),
00048 "Invalid Parameters" );
00049
00050 TEAGN_TRUE_OR_THROW( contra.Apply(),
00051 "Apply error" );
00052
00053 TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00054 TEPDIEXAMPLESBINPATH "TePDIContrastMinMax_autolevels_test.tif" ), "GeoTIF generation error" );
00055
00056
00057
00058 TEAGN_CHECK_EPS( outlut->size(), 256, 0, "Invalid lut size" );
00059 }
00060
00061
00062 void TePDIContrastMinMax_no_input_image_test()
00063 {
00064 TePDIParameters params;
00065
00066 TePDIContrast::TePDIContrastType contrast_type =
00067 TePDIContrast::TePDIContrastMinMax;
00068 params.SetParameter( "contrast_type", contrast_type );
00069
00070 TePDIHistogram::pointer input_histogram( new TePDIHistogram );
00071 {
00072 TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00073 std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00074 TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00075
00076 input_histogram->reset( inRaster, 0, 0, TeBoxPixelIn );
00077 params.SetParameter( "input_histogram", input_histogram );
00078 }
00079
00080 params.SetParameter( "output_channel_min_level", (double)0 );
00081 params.SetParameter( "output_channel_max_level", (double)255 );
00082
00083 TePDITypes::TePDILutPtrType outlut( new TePDITypes::TePDILutType );
00084 params.SetParameter( "outlut", outlut );
00085
00086 TePDIContrast contra;
00087 TEAGN_TRUE_OR_THROW( contra.Reset( params ),
00088 "Invalid Parameters" );
00089 TEAGN_TRUE_OR_THROW( contra.Apply(),
00090 "Apply error" );
00091
00092
00093
00094 TEAGN_CHECK_EPS( outlut->size(), 180, 0, "Invalid lut size" );
00095 }
00096
00097
00098 void TePDIContrastLinear_plus_histo_test()
00099 {
00100 TePDIParameters params;
00101
00102 TePDIContrast::TePDIContrastType contrast_type =
00103 TePDIContrast::TePDIContrastLinear;
00104 params.SetParameter( "contrast_type", contrast_type );
00105
00106 TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00107 std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00108 TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00109 params.SetParameter( "input_image", inRaster );
00110
00111
00112
00113 TePDIHistogram::pointer input_histogram( new TePDIHistogram );
00114 TEAGN_TRUE_OR_THROW( input_histogram->reset( inRaster, 0, 256,
00115 TeBoxPixelIn ),
00116 "Histogram building error" );
00117 params.SetParameter( "input_histogram", input_histogram );
00118
00119 TePDITypes::TePDIRasterPtrType outRaster;
00120 TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00121 1, 1, 1, false, TeUNSIGNEDCHAR, 0 ), "RAM Raster Alloc error" );
00122 params.SetParameter( "output_image", outRaster );
00123
00124 params.SetParameter( "input_band", (int)0 );
00125 params.SetParameter( "output_band", (int)0 );
00126
00127 params.SetParameter( "min_level", (double)46 );
00128 params.SetParameter( "max_level", (double)102 );
00129
00130 TePDITypes::TePDILutPtrType outlut( new TePDITypes::TePDILutType );
00131 params.SetParameter( "outlut", outlut );
00132
00133 TePDIContrast contra;
00134
00135 TEAGN_TRUE_OR_THROW( contra.Reset( params ),
00136 "Invalid Parameters" );
00137
00138 TEAGN_TRUE_OR_THROW( contra.Apply(),
00139 "Apply error" );
00140
00141 TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00142 TEPDIEXAMPLESBINPATH "TePDIContrastLinear_plus_histo_test.tif" ), "GeoTIF generation error" );
00143 }
00144
00145 void TePDIContrastSquareRoot_test()
00146 {
00147 TePDIParameters params;
00148
00149 TePDIContrast::TePDIContrastType contrast_type =
00150 TePDIContrast::TePDIContrastSquareRoot;
00151 params.SetParameter( "contrast_type", contrast_type );
00152
00153 TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00154 std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00155 TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00156 params.SetParameter( "input_image", inRaster );
00157
00158 TePDITypes::TePDIRasterPtrType outRaster;
00159 TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00160 1, 1, 1, false, TeUNSIGNEDCHAR, 0 ), "RAM Raster Alloc error" );
00161 params.SetParameter( "output_image", outRaster );
00162
00163 params.SetParameter( "input_band", (int)0 );
00164 params.SetParameter( "output_band", (int)0 );
00165
00166 params.SetParameter( "histo_levels", (int)256 );
00167
00168 params.SetParameter( "min_level", (double)46 );
00169 params.SetParameter( "max_level", (double)102 );
00170
00171 TePDITypes::TePDILutPtrType outlut( new TePDITypes::TePDILutType );
00172 params.SetParameter( "outlut", outlut );
00173
00174 TePDIContrast contra;
00175
00176 TEAGN_TRUE_OR_THROW( contra.Reset( params ),
00177 "Invalid Parameters" );
00178
00179 TEAGN_TRUE_OR_THROW( contra.Apply(),
00180 "Apply error" );
00181
00182 TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00183 TEPDIEXAMPLESBINPATH "TePDIContrastSquareRoot_test.tif" ), "GeoTIF generation error" );
00184
00185
00186
00187 TEAGN_TRUE_OR_THROW( ( outlut->size() == 256 ), "Invalid lut size" );
00188 }
00189
00190 void TePDIContrastSquare_test()
00191 {
00192 TePDIParameters params;
00193
00194 TePDIContrast::TePDIContrastType contrast_type =
00195 TePDIContrast::TePDIContrastSquare;
00196 params.SetParameter( "contrast_type", contrast_type );
00197
00198 TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00199 std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00200 TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00201 params.SetParameter( "input_image", inRaster );
00202
00203 TePDITypes::TePDIRasterPtrType outRaster;
00204 TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00205 1, 1, 1, false, TeUNSIGNEDCHAR, 0 ), "RAM Raster Alloc error" );
00206 params.SetParameter( "output_image", outRaster );
00207
00208 params.SetParameter( "input_band", (int)0 );
00209 params.SetParameter( "output_band", (int)0 );
00210
00211 params.SetParameter( "histo_levels", (int)256 );
00212
00213 params.SetParameter( "min_level", (double)46 );
00214 params.SetParameter( "max_level", (double)102 );
00215
00216 TePDITypes::TePDILutPtrType outlut( new TePDITypes::TePDILutType );
00217 params.SetParameter( "outlut", outlut );
00218
00219 TePDIContrast contra;
00220
00221 TEAGN_TRUE_OR_THROW( contra.Reset( params ),
00222 "Invalid Parameters" );
00223
00224 TEAGN_TRUE_OR_THROW( contra.Apply(),
00225 "Apply error" );
00226
00227 TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00228 TEPDIEXAMPLESBINPATH "TePDIContrastSquare_test.tif" ), "GeoTIF generation error" );
00229
00230
00231
00232 TEAGN_TRUE_OR_THROW( ( outlut->size() == 256 ), "Invalid lut size" );
00233 }
00234
00235 void TePDIContrastLog_test()
00236 {
00237 TePDIParameters params;
00238
00239 TePDIContrast::TePDIContrastType contrast_type =
00240 TePDIContrast::TePDIContrastLog;
00241 params.SetParameter( "contrast_type", contrast_type );
00242
00243 TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00244 std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00245 TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00246 params.SetParameter( "input_image", inRaster );
00247
00248 TePDITypes::TePDIRasterPtrType outRaster;
00249 TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00250 1, 1, 1, false, TeUNSIGNEDCHAR, 0 ), "RAM Raster Alloc error" );
00251 params.SetParameter( "output_image", outRaster );
00252
00253 params.SetParameter( "input_band", (int)0 );
00254 params.SetParameter( "output_band", (int)0 );
00255
00256 params.SetParameter( "histo_levels", (int)256 );
00257
00258 params.SetParameter( "min_level", (double)46 );
00259 params.SetParameter( "max_level", (double)102 );
00260
00261 TePDITypes::TePDILutPtrType outlut( new TePDITypes::TePDILutType );
00262 params.SetParameter( "outlut", outlut );
00263
00264 TePDIContrast contra;
00265
00266 TEAGN_TRUE_OR_THROW( contra.Reset( params ),
00267 "Invalid Parameters" );
00268
00269 TEAGN_TRUE_OR_THROW( contra.Apply(),
00270 "Apply error" );
00271
00272 TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00273 TEPDIEXAMPLESBINPATH "TePDIContrastLog_test.tif" ), "GeoTIF generation error" );
00274
00275
00276
00277 TEAGN_TRUE_OR_THROW( ( outlut->size() == 256 ), "Invalid lut size" );
00278 }
00279
00280
00281 void TePDIContrastLog_with_use_dummy_test()
00282 {
00283 TePDIParameters params;
00284
00285 TePDIContrast::TePDIContrastType contrast_type =
00286 TePDIContrast::TePDIContrastLog;
00287 params.SetParameter( "contrast_type", contrast_type );
00288
00289 TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00290 std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00291 TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00292 params.SetParameter( "input_image", inRaster );
00293
00294 TePDITypes::TePDIRasterPtrType outRaster;
00295 TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00296 1, 1, 1, false, TeUNSIGNEDCHAR, 0 ), "RAM Raster Alloc error" );
00297 params.SetParameter( "output_image", outRaster );
00298
00299 params.SetParameter( "input_band", (int)0 );
00300 params.SetParameter( "output_band", (int)0 );
00301
00302 params.SetParameter( "histo_levels", (int)256 );
00303
00304 params.SetParameter( "min_level", (double)46 );
00305 params.SetParameter( "max_level", (double)102 );
00306
00307 TePDITypes::TePDILutPtrType outlut( new TePDITypes::TePDILutType );
00308 params.SetParameter( "outlut", outlut );
00309
00310 params.SetParameter( "dummy_value", (double)0 );
00311
00312 TePDIContrast contra;
00313
00314 TEAGN_TRUE_OR_THROW( contra.Reset( params ),
00315 "Invalid Parameters" );
00316
00317 TEAGN_TRUE_OR_THROW( contra.Apply(),
00318 "Apply error" );
00319
00320 TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00321 TEPDIEXAMPLESBINPATH "TePDIContrastLog_with_use_dummy_test.tif" ), "GeoTIF generation error" );
00322
00323
00324
00325 TEAGN_TRUE_OR_THROW( ( outlut->size() == 256 ), "Invalid lut size" );
00326 }
00327
00328
00329 void TePDIContrastNegative_test()
00330 {
00331 TePDIParameters params;
00332
00333 TePDIContrast::TePDIContrastType contrast_type =
00334 TePDIContrast::TePDIContrastNegative;
00335 params.SetParameter( "contrast_type", contrast_type );
00336
00337 TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00338 std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00339 TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00340 params.SetParameter( "input_image", inRaster );
00341
00342 TePDITypes::TePDIRasterPtrType outRaster;
00343 TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00344 1, 1, 1, false, TeUNSIGNEDCHAR, 0 ), "RAM Raster Alloc error" );
00345 params.SetParameter( "output_image", outRaster );
00346
00347 params.SetParameter( "input_band", (int)0 );
00348 params.SetParameter( "output_band", (int)0 );
00349
00350 params.SetParameter( "histo_levels", (int)256 );
00351
00352 params.SetParameter( "min_level", (double)46 );
00353 params.SetParameter( "max_level", (double)102 );
00354
00355 TePDITypes::TePDILutPtrType outlut( new TePDITypes::TePDILutType );
00356 params.SetParameter( "outlut", outlut );
00357
00358 TePDIContrast contra;
00359
00360 TEAGN_TRUE_OR_THROW( contra.Reset( params ),
00361 "Invalid Parameters" );
00362
00363 TEAGN_TRUE_OR_THROW( contra.Apply(),
00364 "Apply error" );
00365
00366 TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00367 TEPDIEXAMPLESBINPATH "TePDIContrastNegative_test.tif" ), "GeoTIF generation error" );
00368
00369
00370
00371 TEAGN_TRUE_OR_THROW( ( outlut->size() == 256 ), "Invalid lut size" );
00372 }
00373
00374 void TePDIContrastHistEqualizer_test()
00375 {
00376 TePDIParameters params;
00377
00378 TePDIContrast::TePDIContrastType contrast_type =
00379 TePDIContrast::TePDIContrastHistEqualizer;
00380 params.SetParameter( "contrast_type", contrast_type );
00381
00382 TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00383 std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00384
00385 TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00386 params.SetParameter( "input_image", inRaster );
00387
00388 TePDITypes::TePDIRasterPtrType outRaster;
00389 TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00390 1, 1, 1, false, TeUNSIGNEDCHAR, 0 ), "RAM Raster Alloc error" );
00391 params.SetParameter( "output_image", outRaster );
00392
00393 params.SetParameter( "input_band", (int)0 );
00394 params.SetParameter( "output_band", (int)0 );
00395
00396 params.SetParameter( "histo_levels", (int)256 );
00397
00398 params.SetParameter( "min_level", (double)46 );
00399 params.SetParameter( "max_level", (double)102 );
00400
00401 TePDITypes::TePDILutPtrType outlut( new TePDITypes::TePDILutType );
00402 params.SetParameter( "outlut", outlut );
00403
00404 TePDIContrast contra;
00405
00406 TEAGN_TRUE_OR_THROW( contra.Reset( params ),
00407 "Invalid Parameters" );
00408
00409 TEAGN_TRUE_OR_THROW( contra.Apply(),
00410 "Apply error" );
00411
00412 TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00413 TEPDIEXAMPLESBINPATH "TePDIContrastHistEqualizer_test.tif" ), "GeoTIF generation error" );
00414
00415
00416
00417 TEAGN_CHECK_EPS( outlut->size(), 180, 0, "Invalid lut size" );
00418 }
00419
00420 void TePDIContrastSimpleSlicer_test()
00421 {
00422 TePDIParameters params;
00423
00424 TePDIContrast::TePDIContrastType contrast_type =
00425 TePDIContrast::TePDIContrastSimpleSlicer;
00426 params.SetParameter( "contrast_type", contrast_type );
00427
00428 TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00429 std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00430 TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00431 params.SetParameter( "input_image", inRaster );
00432
00433 TePDITypes::TePDIRasterPtrType outRaster;
00434 TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00435 1, 1, 1, false, TeUNSIGNEDCHAR, 0 ), "RAM Raster Alloc error" );
00436 params.SetParameter( "output_image", outRaster );
00437
00438 params.SetParameter( "input_band", (int)0 );
00439 params.SetParameter( "output_band", (int)0 );
00440
00441 params.SetParameter( "histo_levels", (int)( 102 - 47 + 1 ) );
00442
00443 params.SetParameter( "min_level", (double)47 );
00444 params.SetParameter( "max_level", (double)102 );
00445
00446 TePDITypes::TePDILutPtrType outlut( new TePDITypes::TePDILutType );
00447 params.SetParameter( "outlut", outlut );
00448
00449 TePDIRgbPalette::pointer pal =
00450 TePDIRgbPaletteFunctions::createLSBPalette( 20 );
00451 params.SetParameter( "rgb_palette", pal );
00452
00453 TePDIContrast contra;
00454
00455 TEAGN_TRUE_OR_THROW( contra.Reset( params ),
00456 "Invalid Parameters" );
00457
00458 TEAGN_TRUE_OR_THROW( contra.Apply(),
00459 "Apply error" );
00460
00461 TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00462 TEPDIEXAMPLESBINPATH "TePDIContrastSimpleSlicer_test.tif" ), "GeoTIF generation error" );
00463
00464
00465
00466 TEAGN_TRUE_OR_THROW( ( outlut->size() == 56 ), "Invalid lut size" );
00467 }
00468
00469
00470 void TePDIContrastStat_test()
00471 {
00472
00473 double target_mean = 121.809123;
00474 double target_variance = 1561.214764;
00475
00476
00477
00478 TePDIParameters params;
00479
00480 TePDIContrast::TePDIContrastType contrast_type =
00481 TePDIContrast::TePDIContrastStat;
00482 params.SetParameter( "contrast_type", contrast_type );
00483
00484 TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00485 std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00486 TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00487 params.SetParameter( "input_image", inRaster );
00488
00489 TePDITypes::TePDIRasterPtrType outRaster;
00490 TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00491 1, 1, 1, false, TeUNSIGNEDCHAR, 0 ), "RAM Raster Alloc error" );
00492 params.SetParameter( "output_image", outRaster );
00493
00494 params.SetParameter( "input_band", (int)0 );
00495 params.SetParameter( "output_band", (int)0 );
00496 params.SetParameter( "target_mean", target_mean );
00497 params.SetParameter( "target_variance", target_variance );
00498
00499 TePDIContrast contra;
00500
00501 TEAGN_TRUE_OR_THROW( contra.Reset( params ),
00502 "Invalid Parameters" );
00503
00504 TEAGN_TRUE_OR_THROW( contra.Apply(),
00505 "Apply error" );
00506
00507 TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00508 TEPDIEXAMPLESBINPATH "TePDIContrastStat_test.tif" ), "GeoTIF generation error" );
00509 }
00510
00511
00512 int main()
00513 {
00514 TEAGN_LOGMSG( "Test started." );
00515
00516 TeStdIOProgress pi;
00517 TeProgress::setProgressInterf( dynamic_cast< TeProgressBase* >( &pi ) );
00518
00519 TePDIContrastLinear_plus_histo_test();
00520 TePDIContrastStat_test();
00521 TePDIContrastMinMax_autolevels_test();
00522 TePDIContrastMinMax_no_input_image_test();
00523 TePDIContrastSquareRoot_test();
00524 TePDIContrastSquare_test();
00525 TePDIContrastLog_test();
00526 TePDIContrastLog_with_use_dummy_test();
00527 TePDIContrastNegative_test();
00528 TePDIContrastHistEqualizer_test();
00529 TePDIContrastSimpleSlicer_test();
00530
00531 TEAGN_LOGMSG( "Test OK." );
00532 return EXIT_SUCCESS;
00533 }