From 507d575e24c4cf85b8d9f2ea1039f92c8e766709 Mon Sep 17 00:00:00 2001 From: Jonathan Guinet <jonathan.guinet@c-s.fr> Date: Tue, 19 Jun 2012 17:59:33 +0200 Subject: [PATCH] TEST: add SubPixelDisparityMapFilter and DisparityMapMedianFilter tests. --- Testing/Code/DisparityMap/CMakeLists.txt | 69 +++++-- .../otbAdhesionCorrectionFilter.cxx | 7 +- .../otbDisparityMapMedianFilter.cxx | 56 +++++- .../DisparityMap/otbDisparityMapTests3.cxx | 3 - .../DisparityMap/otbDisparityMapTests4.cxx | 5 + .../otbSubPixelDisparityImageFilter.cxx | 181 +++++++++++++++++- 6 files changed, 287 insertions(+), 34 deletions(-) diff --git a/Testing/Code/DisparityMap/CMakeLists.txt b/Testing/Code/DisparityMap/CMakeLists.txt index 95defaf128..6b727535cc 100644 --- a/Testing/Code/DisparityMap/CMakeLists.txt +++ b/Testing/Code/DisparityMap/CMakeLists.txt @@ -437,11 +437,14 @@ ${TEMP}/feTvStereorectificationDeformationFieldSourceOutput2.tif 5 ) +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbDisparityMapTests4 ~~~~~~~~~~~~~~~~~~~~~~~~~~ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #--------- otb::HorizontalPixelWiseBlockMatchingImageFilter ----------------------------------------- -ADD_TEST(dmTuPixelWiseBlockMatchingImageFilterNew ${DISPARITYMAP_TESTS3} +ADD_TEST(dmTuPixelWiseBlockMatchingImageFilterNew ${DISPARITYMAP_TESTS4} otbPixelWiseBlockMatchingImageFilterNew) -ADD_TEST(dmTvPixelWiseBlockMatchingImageFilter ${DISPARITYMAP_TESTS3} +ADD_TEST(dmTvPixelWiseBlockMatchingImageFilter ${DISPARITYMAP_TESTS4} --compare-n-images ${NOTOL} 2 ${BASELINE}/dmTvPixelWiseBlockMatchingImageFilterOutputDisparity.tif ${TEMP}/dmTvPixelWiseBlockMatchingImageFilterOutputDisparity.tif @@ -455,8 +458,7 @@ ${TEMP}/dmTvPixelWiseBlockMatchingImageFilterOutputMetric.tif 2 -10 +10 ) - -ADD_TEST(dmTvPixelWiseBlockMatchingImageFilterNCC ${DISPARITYMAP_TESTS3} +ADD_TEST(dmTvPixelWiseBlockMatchingImageFilterNCC ${DISPARITYMAP_TESTS4} --compare-n-images ${NOTOL} 2 ${BASELINE}/dmTvPixelWiseBlockMatchingImageFilterNCCOutputDisparity.tif ${TEMP}/dmTvPixelWiseBlockMatchingImageFilterNCCOutputDisparity.tif @@ -472,20 +474,61 @@ ${TEMP}/dmTvPixelWiseBlockMatchingImageFilterNCCOutputMetric.tif ) -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbDisparityMapTests4 ~~~~~~~~~~~~~~~~~~~~~~~~~~ -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# ------- otb::AdhesionCorrectionFilter ---------- +# ------- otb::SubPixelDisparityImageFilterr ---------- +ADD_TEST(dmTuSubPixelDisparityImageFilterNew ${DISPARITYMAP_TESTS4} + otbSubPixelDisparityImageFilterNew) -ADD_TEST(dmTuAdhesionCorrectionFilterNew ${DISPARITYMAP_TESTS4} - otbAdhesionCorrectionFilterNew) + +ADD_TEST(dmTvSubPixelDisparityImageFilterNCC ${DISPARITYMAP_TESTS4} +--compare-n-images ${NOTOL} 3 +${BASELINE}/dmTvSubPixelWiseBlockMatchingImageFilterNCCOutputHDisparity.tif +${TEMP}/dmTvSubPixelWiseBlockMatchingImageFilterNCCOutputHDisparity.tif +${BASELINE}/dmTvSubPixelWiseBlockMatchingImageFilterNCCOutputVDisparity.tif +${TEMP}/dmTvSubPixelWiseBlockMatchingImageFilterNCCOutputVDisparity.tif +${BASELINE}/dmTvSubPixelWiseBlockMatchingImageFilterNCCOutputMetric.tif +${TEMP}/dmTvSubPixelWiseBlockMatchingImageFilterNCCOutputMetric.tif +otbSubPixelDisparityImageFilter +${EXAMPLEDATA}/StereoFixed.png +${EXAMPLEDATA}/StereoMoving.png +${TEMP}/dmTvPixelWiseBlockMatchingImageFilterNCCOutputDisparity.tif +${TEMP}/dmTvPixelWiseBlockMatchingImageFilterNCCOutputMetric.tif +${TEMP}/dmTvSubPixelWiseBlockMatchingImageFilterNCCOutputHDisparity.tif +${TEMP}/dmTvSubPixelWiseBlockMatchingImageFilterNCCOutputVDisparity.tif +${TEMP}/dmTvSubPixelWiseBlockMatchingImageFilterNCCOutputMetric.tif + +1 # NCC +1 # Parabolic +2 # radius +-3 +3 # hdisp treshold +-2 2 # vdisp treshold +) + +SET_TESTS_PROPERTIES(dmTvSubPixelDisparityImageFilterNCC PROPERTIES DEPENDS dmTvPixelWiseBlockMatchingImageFilterNCC) + + + +# ------- otb::DisparityMapMedianFilter ---------- ADD_TEST(dmTuDisparityMapMedianFilterNew ${DISPARITYMAP_TESTS4} otbDisparityMapMedianFilterNew) + +ADD_TEST(dmTvDisparityMapMedianFilter ${DISPARITYMAP_TESTS4} +--compare-image ${NOTOL} + ${BASELINE}/dmTvDisparityMapMedianFilterOutput.tif + ${TEMP}/dmTvDisparityMapMedianFilterOutput.tif + otbDisparityMapMedianFilter + ${TEMP}/dmTvSubPixelWiseBlockMatchingImageFilterNCCOutputHDisparity.tif + ${TEMP}/dmTvDisparityMapMedianFilterOutput.tif + 2 + 2.0 + ) + +SET_TESTS_PROPERTIES(dmTvDisparityMapMedianFilter PROPERTIES DEPENDS dmTvSubPixelDisparityImageFilterNCC) -ADD_TEST(dmTuSubPixelDisparityImageFilterrNew ${DISPARITYMAP_TESTS4} - otbSubPixelDisparityImageFilterNew) +# ------- otb::AdhesionCorrectionFilter ---------- +ADD_TEST(dmTuAdhesionCorrectionFilterNew ${DISPARITYMAP_TESTS4} + otbAdhesionCorrectionFilterNew) # ------- Fichiers sources CXX ----------------------------------- SET(BasicDisparityMap_SRCS1 @@ -523,13 +566,13 @@ otbFineRegistrationImageFilterNew.cxx otbFineRegistrationImageFilterTest.cxx otbStereoSensorModelToElevationMapFilter.cxx otbStereorectificationDeformationFieldSource.cxx -otbPixelWiseBlockMatchingImageFilter.cxx ) SET(BasicDisparityMap_SRCS4 otbDisparityMapTests4.cxx otbAdhesionCorrectionFilter.cxx otbDisparityMapMedianFilter.cxx +otbPixelWiseBlockMatchingImageFilter.cxx otbSubPixelDisparityImageFilter.cxx ) diff --git a/Testing/Code/DisparityMap/otbAdhesionCorrectionFilter.cxx b/Testing/Code/DisparityMap/otbAdhesionCorrectionFilter.cxx index 1332be245d..3f8cda433b 100644 --- a/Testing/Code/DisparityMap/otbAdhesionCorrectionFilter.cxx +++ b/Testing/Code/DisparityMap/otbAdhesionCorrectionFilter.cxx @@ -22,9 +22,9 @@ int otbAdhesionCorrectionFilterNew(int argc, char* argv[]) { const unsigned int Dimension = 2; typedef float PixelType; - typedef otb::Image<PixelType, Dimension> ImageType; - typedef unsigned char MaskPixelType; - typedef otb::Image<MaskPixelType, Dimension> MaskType; + typedef otb::Image<PixelType, Dimension> ImageType; + typedef unsigned char MaskPixelType; + typedef otb::Image<MaskPixelType, Dimension> MaskType; typedef otb::AdhesionCorrectionFilter<ImageType, MaskType> AdhesionCorrectionFilterType; @@ -36,6 +36,7 @@ int otbAdhesionCorrectionFilterNew(int argc, char* argv[]) int otbAdhesionCorrectionFilter(int argc, char* argv[]) { + return EXIT_SUCCESS; } diff --git a/Testing/Code/DisparityMap/otbDisparityMapMedianFilter.cxx b/Testing/Code/DisparityMap/otbDisparityMapMedianFilter.cxx index cf167627c1..ae429f1cef 100644 --- a/Testing/Code/DisparityMap/otbDisparityMapMedianFilter.cxx +++ b/Testing/Code/DisparityMap/otbDisparityMapMedianFilter.cxx @@ -17,18 +17,60 @@ =========================================================================*/ #include "otbDisparityMapMedianFilter.h" #include "otbImage.h" - +#include "otbImageFileReader.h" +#include "otbStreamingImageFileWriter.h" +#include "otbStandardWriterWatcher.h" + + const unsigned int Dimension = 2; + typedef float PixelType; + typedef otb::Image<PixelType, Dimension> FloatImageType; + typedef otb::ImageFileReader<FloatImageType> ReaderType; + typedef otb::StreamingImageFileWriter<FloatImageType> FloatWriterType; + + typedef otb::DisparityMapMedianFilter<FloatImageType,FloatImageType,FloatImageType> DisparityMapMedianFilterType; + + int otbDisparityMapMedianFilterNew(int argc, char* argv[]) { - const unsigned int Dimension = 2; - typedef float PixelType; - typedef otb::Image<PixelType, Dimension> FloatImageType; - - typedef otb::DisparityMapMedianFilter<FloatImageType,FloatImageType,FloatImageType> DisparityMapMedianFilterType; - // Instantiation + // Instantiation DisparityMapMedianFilterType::Pointer filter = DisparityMapMedianFilterType::New(); return EXIT_SUCCESS; } +int otbDisparityMapMedianFilter(int argc, char* argv[]) +{ + + if ((argc != 5) && (argc != 6)) + { + std::cerr << "Usage: " << argv[0] << " hdispinput_fname output_fname radius incoherencethres (maskinput_fname) "; + return EXIT_FAILURE; + } + + // Instantiation + DisparityMapMedianFilterType::Pointer filter = DisparityMapMedianFilterType::New(); + + ReaderType::Pointer imgReader = ReaderType::New(); + imgReader->SetFileName(argv[1]); + + filter->SetInput(imgReader->GetOutput()); + filter->SetRadius(atoi(argv[3])); + filter->SetIncoherenceThreshold(atof(argv[4])); + + ReaderType::Pointer maskReader = ReaderType::New(); + if (argc > 5) + { + maskReader->SetFileName(argv[5]); + filter->SetMaskInput(maskReader->GetOutput()); + } + + FloatWriterType::Pointer writer = FloatWriterType::New(); + writer->SetInput(filter->GetOutput()); + writer->SetFileName(argv[2]); + + otb::StandardWriterWatcher watcher1(writer, filter, "filtering"); + writer->Update(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/DisparityMap/otbDisparityMapTests3.cxx b/Testing/Code/DisparityMap/otbDisparityMapTests3.cxx index 5eb8586345..d974822ca8 100644 --- a/Testing/Code/DisparityMap/otbDisparityMapTests3.cxx +++ b/Testing/Code/DisparityMap/otbDisparityMapTests3.cxx @@ -32,7 +32,4 @@ void RegisterTests() REGISTER_TEST(otbStereoSensorModelToElevationMapFilter); REGISTER_TEST(otbStereorectificationDeformationFieldSourceNew); REGISTER_TEST(otbStereorectificationDeformationFieldSource); - REGISTER_TEST(otbPixelWiseBlockMatchingImageFilterNew); - REGISTER_TEST(otbPixelWiseBlockMatchingImageFilter); - REGISTER_TEST(otbPixelWiseBlockMatchingImageFilterNCC); } diff --git a/Testing/Code/DisparityMap/otbDisparityMapTests4.cxx b/Testing/Code/DisparityMap/otbDisparityMapTests4.cxx index 42535768ca..510317a53f 100644 --- a/Testing/Code/DisparityMap/otbDisparityMapTests4.cxx +++ b/Testing/Code/DisparityMap/otbDisparityMapTests4.cxx @@ -26,5 +26,10 @@ void RegisterTests() { REGISTER_TEST(otbAdhesionCorrectionFilterNew); REGISTER_TEST(otbDisparityMapMedianFilterNew); + REGISTER_TEST(otbDisparityMapMedianFilter); + REGISTER_TEST(otbPixelWiseBlockMatchingImageFilterNew); + REGISTER_TEST(otbPixelWiseBlockMatchingImageFilter); + REGISTER_TEST(otbPixelWiseBlockMatchingImageFilterNCC); + REGISTER_TEST(otbSubPixelDisparityImageFilter); REGISTER_TEST(otbSubPixelDisparityImageFilterNew); } diff --git a/Testing/Code/DisparityMap/otbSubPixelDisparityImageFilter.cxx b/Testing/Code/DisparityMap/otbSubPixelDisparityImageFilter.cxx index 4117017b53..628c2cf7f3 100644 --- a/Testing/Code/DisparityMap/otbSubPixelDisparityImageFilter.cxx +++ b/Testing/Code/DisparityMap/otbSubPixelDisparityImageFilter.cxx @@ -17,29 +17,194 @@ =========================================================================*/ #include "otbSubPixelDisparityImageFilter.h" #include "otbPixelWiseBlockMatchingImageFilter.h" +#include "otbImageFileReader.h" +#include "otbStreamingImageFileWriter.h" +#include "otbStandardWriterWatcher.h" #include "otbImage.h" -int otbSubPixelDisparityImageFilterNew(int argc, char* argv[]) -{ + const unsigned int Dimension = 2; typedef float PixelType; - typedef otb::Image<PixelType, Dimension> FloatImageType; - typedef unsigned char MaskPixelType; - typedef otb::Image<MaskPixelType, Dimension> MaskType; + typedef otb::Image<PixelType, Dimension> FloatImageType; + + + + typedef otb::Functor::NCCBlockMatching<FloatImageType,FloatImageType> NCCBlockMatchingFunctorType; + + typedef otb::SubPixelDisparityImageFilter<FloatImageType, + FloatImageType, + FloatImageType, + FloatImageType, + NCCBlockMatchingFunctorType> NCCSubPixelDisparityFilterType; typedef otb::Functor::SSDBlockMatching<FloatImageType,FloatImageType> SSDBlockMatchingFunctorType; + typedef otb::SubPixelDisparityImageFilter<FloatImageType, + FloatImageType, + FloatImageType, + FloatImageType, + SSDBlockMatchingFunctorType> SSDSubPixelDisparityFilterType; + typedef otb::Functor::LPBlockMatching<FloatImageType,FloatImageType> LPBlockMatchingFunctorType; + typedef otb::SubPixelDisparityImageFilter<FloatImageType, + FloatImageType, + FloatImageType, + FloatImageType, + LPBlockMatchingFunctorType> LPSubPixelDisparityFilterType; - typedef otb::SubPixelDisparityImageFilter<FloatImageType,FloatImageType,FloatImageType,FloatImageType, - SSDBlockMatchingFunctorType> SubPixelDisparityImageFilterType; + + typedef otb::ImageFileReader<FloatImageType> ReaderType; + typedef otb::StreamingImageFileWriter<FloatImageType> WriterType; + +int otbSubPixelDisparityImageFilterNew(int argc, char* argv[]) +{ // Instantiation - SubPixelDisparityImageFilterType::Pointer filter = SubPixelDisparityImageFilterType::New(); + SSDSubPixelDisparityFilterType::Pointer filter = SSDSubPixelDisparityFilterType::New(); return EXIT_SUCCESS; } +template<class TImage,class TFunctorType> int ProcessAndWriteOutput(otb::SubPixelDisparityImageFilter<TImage, + TImage,TImage,TImage,TFunctorType> * subPixFilter,int argc,char* argv[]) +{ + + ReaderType::Pointer leftReader = ReaderType::New(); + leftReader->SetFileName(argv[1]); + + ReaderType::Pointer rightReader = ReaderType::New(); + rightReader->SetFileName(argv[2]); + + ReaderType::Pointer bmhdispReader = ReaderType::New(); + bmhdispReader->SetFileName(argv[3]); + // ReaderType::Pointer bmvdispReader = ReaderType::New(); + // bmvdispReader->SetFileName(argv[3]); + + ReaderType::Pointer metricReader = ReaderType::New(); + metricReader->SetFileName(argv[4]); + + // subPixFilter->SetVerticalDisparityInput(bmvdispReader->GetVerticalDisparityOutput()); + + + subPixFilter->SetLeftInput(leftReader->GetOutput()); + subPixFilter->SetRightInput(rightReader->GetOutput()); + + subPixFilter->SetHorizontalDisparityInput(bmhdispReader->GetOutput()); + subPixFilter->SetRadius(atoi(argv[10])); + + subPixFilter->SetMinimumHorizontalDisparity(atoi(argv[11])); + subPixFilter->SetMaximumHorizontalDisparity(atoi(argv[12])); + + subPixFilter->SetMinimumVerticalDisparity(atoi(argv[13])); + subPixFilter->SetMaximumVerticalDisparity(atoi(argv[14])); + + subPixFilter->SetMetricInput(metricReader->GetOutput()); + + ReaderType::Pointer leftMaskReader = ReaderType::New(); + ReaderType::Pointer rightMaskReader = ReaderType::New(); + if (argc > 15) + { + leftMaskReader->SetFileName(argv[15]); + subPixFilter->SetLeftMaskInput(leftMaskReader->GetOutput()); + } + + if (argc > 16) + { + rightMaskReader->SetFileName(argv[16]); + subPixFilter->SetRightMaskInput(rightMaskReader->GetOutput()); + } + + switch (atoi(argv[9])) + { + case 1: + subPixFilter->SetRefineMethod(NCCSubPixelDisparityFilterType::PARABOLIC); + break; + case 2: + subPixFilter->SetRefineMethod(NCCSubPixelDisparityFilterType::TRIANGULAR); + break; + case 3: + subPixFilter->SetRefineMethod(NCCSubPixelDisparityFilterType::DICHOTOMY); + break; + default: + std::cout << "wrong pixel mode" << std::endl; + return EXIT_FAILURE; + break; + } + otb::StandardWriterWatcher watcher(subPixFilter, "Sub-pixel refinement"); + // writers + // horizontal disparity writer + WriterType::Pointer hdispWriter = WriterType::New(); + hdispWriter->SetInput(subPixFilter->GetHorizontalDisparityOutput()); + hdispWriter->SetFileName(argv[5]); + otb::StandardWriterWatcher watcher1(hdispWriter, subPixFilter, "Computing disparity "); + + hdispWriter->Update(); + + // vertical disparity writer + WriterType::Pointer vdispWriter = WriterType::New(); + vdispWriter->SetInput(subPixFilter->GetVerticalDisparityOutput()); + vdispWriter->SetFileName(argv[6]); + + vdispWriter->Update(); + + // metric writer + // vertical disparity writer + WriterType::Pointer metricWriter = WriterType::New(); + metricWriter->SetInput(subPixFilter->GetMetricOutput()); + metricWriter->SetFileName(argv[7]); + + metricWriter->Update(); + + return EXIT_SUCCESS; +} + + +int otbSubPixelDisparityImageFilter(int argc, char* argv[]) +{ + + if ((argc < 15) || (argc > 17)) + { + std::cerr << "Usage: " << argv[0] + << " leftinput_fname rightinput_fname blockmatchinginput_fname blockmatchingmetricinput_fname "; + std::cerr << "hdispoutput_fname vdispoutput_fname metricoutput_fname " << std::endl; + std::cerr << "metric (0=SSD, 1=NCC, 2=LP pseudo norm) "; + std::cerr << "subpixelmode (1=parabolic,2=triangular,3=dichotomy)" << std::endl; + std::cerr << "radius minhdisp maxhdisp minvdisp maxvdisp " << std::endl; + std::cerr << "(leftmaskinput_fname) (rightmaskinput_fname)" << std::endl; + return EXIT_FAILURE; + } + + SSDSubPixelDisparityFilterType::Pointer SSDSubPixFilter = SSDSubPixelDisparityFilterType::New(); + NCCSubPixelDisparityFilterType::Pointer NCCSubPixFilter = NCCSubPixelDisparityFilterType::New(); + LPSubPixelDisparityFilterType::Pointer LPSubPixFilter = LPSubPixelDisparityFilterType::New(); + + // Instantiation + switch (atoi(argv[8])) + { + case 0: + SSDSubPixFilter->MinimizeOn(); + return ProcessAndWriteOutput<FloatImageType, SSDBlockMatchingFunctorType> (SSDSubPixFilter, argc, argv); + break; + case 1: + NCCSubPixFilter->MinimizeOff(); + return ProcessAndWriteOutput<FloatImageType, NCCBlockMatchingFunctorType> (NCCSubPixFilter, argc, argv); + break; + case 2: + LPSubPixFilter->MinimizeOff(); + return ProcessAndWriteOutput<FloatImageType, LPBlockMatchingFunctorType> (LPSubPixFilter, argc, argv); + break; + default: + std::cout << "wrong norm type (0=SSD, 1=NCC, 2=LP pseudo norm)" << std::endl; + return EXIT_FAILURE; + break; + } + + return EXIT_FAILURE; +} + + + + -- GitLab