diff --git a/Testing/Code/BasicFilters/CMakeLists.txt b/Testing/Code/BasicFilters/CMakeLists.txt index 64ebb75a8db7f735b16abf7cbdf716d5f5b81f98..0723a315b35228f9e021c0c1bbbc871c7b0d0610 100644 --- a/Testing/Code/BasicFilters/CMakeLists.txt +++ b/Testing/Code/BasicFilters/CMakeLists.txt @@ -2518,6 +2518,29 @@ ADD_TEST(bfTvVectorDataToLabelImageFilterSHP ${BASICFILTERS_TESTS15} ${TEMP}/bfTvVectorDataToLabelImageFilter_Output.tif ) +# --------------------- otbPolygonizationRasterizationTest --------------------- +# bijectivity tests +ADD_TEST(bfTvPolygonizationRasterization_UTM ${BASICFILTERS_TESTS15} + otbPolygonizationRasterizationTest + ${INPUTDATA}/QB_Toulouse_ortho_labelImage.tif +) + +ADD_TEST(bfTvPolygonizationRasterization_WGS84 ${BASICFILTERS_TESTS15} + otbPolygonizationRasterizationTest + ${INPUTDATA}/QB_Toulouse_ortho_labelImage_WGS84.tif +) +ADD_TEST(bfTvPolygonizationRasterization_SensorModel ${BASICFILTERS_TESTS15} + otbPolygonizationRasterizationTest + ${INPUTDATA}/QB_Toulouse_SensorModel_labelImage.tif +) + +ADD_TEST(bfTvPolygonizationRasterization_Index ${BASICFILTERS_TESTS15} + otbPolygonizationRasterizationTest + ${INPUTDATA}/QB_Toulouse_labelImage_Index.tif +) + + + # A enrichir SET(BasicFilters_SRCS1 @@ -2808,6 +2831,7 @@ otbClampVectorImageFilter.cxx otbClampImageFilter.cxx otbVectorDataRasterizeFilter.cxx otbVectorDataToLabelImageFilter.cxx +otbPolygonizationRasterizationTest.cxx ) OTB_ADD_EXECUTABLE(otbBasicFiltersTests1 "${BasicFilters_SRCS1}" "OTBBasicFilters;OTBIO;OTBTesting") diff --git a/Testing/Code/BasicFilters/otbBasicFiltersTests15.cxx b/Testing/Code/BasicFilters/otbBasicFiltersTests15.cxx index 4cea1f133bc2dc41f0aadf569b2322a5c8f2d475..9ab623d69f9272fd229af9b52628fe662b99dbe2 100644 --- a/Testing/Code/BasicFilters/otbBasicFiltersTests15.cxx +++ b/Testing/Code/BasicFilters/otbBasicFiltersTests15.cxx @@ -47,4 +47,5 @@ void RegisterTests() REGISTER_TEST(otbVectorDataRasterizeFilter); REGISTER_TEST(otbVectorDataToLabelImageFilterNew); REGISTER_TEST(otbVectorDataToLabelImageFilter); + REGISTER_TEST(otbPolygonizationRasterizationTest); } diff --git a/Testing/Code/BasicFilters/otbPolygonizationRasterizationTest.cxx b/Testing/Code/BasicFilters/otbPolygonizationRasterizationTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d68704b754b324b71ac755bcd5c716daae84a057 --- /dev/null +++ b/Testing/Code/BasicFilters/otbPolygonizationRasterizationTest.cxx @@ -0,0 +1,97 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + Copyright (c) Institut Telecom; Telecom Bretagne. All rights reserved. + See ITCopyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "otbImage.h" +#include "otbImageFileReader.h" + +#include "otbVectorData.h" +#include "otbVectorDataFileReader.h" + +#include "otbLabelImageToVectorDataFilter.h" +#include "otbVectorDataToLabelImageFilter.h" +#include "otbStandardOneLineFilterWatcher.h" + +#include "itkNumericTraits.h" +#include "itkImageRegionConstIterator.h" + +int otbPolygonizationRasterizationTest(int argc, char* argv[]) +{ + typedef otb::Image<unsigned int, 2> ImageType; + typedef otb::ImageFileReader<ImageType> ReaderType; + + typedef otb::VectorData<> VectorDataType; + typedef otb::VectorDataFileReader<VectorDataType> VDReaderType; + + typedef otb::LabelImageToVectorDataFilter<ImageType> LabelImageToVDFilterType; + typedef otb::VectorDataToLabelImageFilter<VectorDataType, + ImageType> RasterizationFilterType; + + // Read the label image + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(argv[1]); + + // Instanciate a LabelImageToVectorData filter + LabelImageToVDFilterType::Pointer polygonize = LabelImageToVDFilterType::New(); + polygonize->SetInput(reader->GetOutput()); + polygonize->Update(); + + // rasterize + RasterizationFilterType::Pointer rasterization = RasterizationFilterType::New(); + rasterization->AddVectorData(polygonize->GetOutput()); + rasterization->SetOutputParametersFromImage(reader->GetOutput()); + rasterization->SetBurnAttribute("DN"); + rasterization->Update(); + + // Compare the input label image and the output of the rasterization + // filter, they must be exactly similar + ImageType::PixelType status = itk::NumericTraits<ImageType::PixelType>::Zero; + unsigned long numberOfPixelsWithDifferences = 0; + + itk::ImageRegionConstIterator<ImageType> itRef(reader->GetOutput(), + reader->GetOutput()->GetLargestPossibleRegion()); + itk::ImageRegionConstIterator<ImageType> itTest(rasterization->GetOutput(), + rasterization->GetOutput()->GetLargestPossibleRegion()); + itRef.GoToBegin(); + itTest.GoToBegin(); + + while(!itRef.IsAtEnd() && !itTest.IsAtEnd()) + { + ImageType::PixelType diff = vcl_abs(itRef.Get() - itTest.Get()); + if( diff != itk::NumericTraits<ImageType::PixelType>::Zero) + { + status += diff; + numberOfPixelsWithDifferences++; + } + ++itRef; + ++itTest; + } + + if (status != itk::NumericTraits<ImageType::PixelType>::Zero || numberOfPixelsWithDifferences != 0) + { + std::cout <<"Total difference "<< status << "for ["<< numberOfPixelsWithDifferences <<"] pixel(s)" <<std::endl; + std::cout <<"Polygonization - rasterization bijectivity test failed." << std::endl; + return EXIT_FAILURE; + } + else + { + std::cout <<"Bijectivity Test exit with success" << std::endl; + } + + return EXIT_SUCCESS; +}