Skip to content
Snippets Groups Projects
Commit 92cecafe authored by Cyrille Valladeau's avatar Cyrille Valladeau
Browse files

Ajout des tests sur otbChangeLabelImageFilter.

parent d3801588
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@ SET(BASICFILTERS_TESTS5 ${CXX_TEST_PATH}/otbBasicFiltersTests5)
SET(BASICFILTERS_TESTS6 ${CXX_TEST_PATH}/otbBasicFiltersTests6)
SET(BASICFILTERS_TESTS7 ${CXX_TEST_PATH}/otbBasicFiltersTests7)
SET(BASICFILTERS_TESTS8 ${CXX_TEST_PATH}/otbBasicFiltersTests8)
SET(BASICFILTERS_TESTS9 ${CXX_TEST_PATH}/otbBasicFiltersTests9)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbBasicFiltersTests1 ~~~~~~~~~~~~~~~~~~~~~~~~~~
......@@ -846,6 +847,20 @@ ADD_TEST(bfTvEuclideanDistanceWithMissingValue ${BASICFILTERS_TESTS8}
${TEMP}/bfTvScalarToRainbowRGBPixelFunctor.png
)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbBasicFiltersTests9 ~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ADD_TEST(bfTuChangeLabelImageFilterNew ${BASICFILTERS_TESTS9}
otbChangeLabelImageFilterNew
)
ADD_TEST(bfTuChangeLabelImageFilter ${BASICFILTERS_TESTS9}
otbChangeLabelImageFilterTest
)
# A enrichir
SET(BasicFilters_SRCS1
otbLeeFilter.cxx
......@@ -968,6 +983,13 @@ otbScalarToRainbowRGBPixelFunctorNew.cxx
otbScalarToRainbowRGBPixelFunctor.cxx
)
# A enrichir
SET(BasicFilters_SRCS9
otbChangeLabelImageFilterNew.cxx
otbChangeLabelImageFilter.cxx
)
INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}")
ADD_EXECUTABLE(otbBasicFiltersTests1 otbBasicFiltersTests1.cxx ${BasicFilters_SRCS1})
......@@ -994,4 +1016,7 @@ TARGET_LINK_LIBRARIES(otbBasicFiltersTests7 OTBBasicFilters OTBCommon OTBIO gd
ADD_EXECUTABLE(otbBasicFiltersTests8 otbBasicFiltersTests8.cxx ${BasicFilters_SRCS8})
TARGET_LINK_LIBRARIES(otbBasicFiltersTests8 OTBBasicFilters OTBCommon OTBIO gdal ITKIO ITKCommon ITKBasicFilters)
ADD_EXECUTABLE(otbBasicFiltersTests9 otbBasicFiltersTests9.cxx ${BasicFilters_SRCS9})
TARGET_LINK_LIBRARIES(otbBasicFiltersTests9 OTBBasicFilters OTBCommon OTBIO gdal ITKIO ITKCommon ITKBasicFilters)
ENDIF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING )
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.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.
=========================================================================*/
// this file defines the otbCommonTest for the test driver
// and all it expects is that you have a function called RegisterTests
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include <iostream>
#include "otbTestMain.h"
void RegisterTests()
{
REGISTER_TEST(otbChangeLabelImageFilterNew);
REGISTER_TEST(otbChangeLabelImageFilterTest);
}
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.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 "itkExceptionObject.h"
#include "otbVectorImage.h"
#include "otbImage.h"
#include "itkRandomImageSource.h"
#include "otbChangeLabelImageFilter.h"
#include "itkImageRegionIteratorWithIndex.h"
int otbChangeLabelImageFilterTest(int argc, char * argv[])
{
const unsigned int ImageDimension = 3;
typedef otb::Image<unsigned short, ImageDimension> InputImageType;
typedef otb::VectorImage<unsigned char, ImageDimension> OutputImageType;
typedef InputImageType::PixelType InputPixelType;
typedef OutputImageType::PixelType OutputPixelType;
typedef itk::ImageRegionIteratorWithIndex<InputImageType> InputIteratorType;
typedef itk::ImageRegionIteratorWithIndex<OutputImageType> OutputIteratorType;
typedef itk::RandomImageSource<InputImageType> SourceType;
typedef otb::ChangeLabelImageFilter<InputImageType, OutputImageType> FilterType;
SourceType::Pointer source = SourceType::New();
FilterType::Pointer filter = FilterType::New();
InputImageType::Pointer vectImage = InputImageType::New();
unsigned long sizeArray[ImageDimension] = { 3,3,3 };
InputPixelType upper = 10;
source->SetMin( itk::NumericTraits<InputPixelType>::Zero );
source->SetMax( upper );
source->SetSize( sizeArray );
filter->SetNumberOfComponentsPerPixel(5);
// Eliminate most labels
OutputPixelType background;
background.SetSize( filter->GetNumberOfComponentsPerPixel() );
background.Fill(1);
InputPixelType maxRemainingLabel = 2;
for (InputPixelType i = maxRemainingLabel; i <= upper; i++)
{
filter->SetChange( i, background );
}
filter->Print( std::cout );
filter->SetInput( source->GetOutput() );
OutputImageType::Pointer outputImage = filter->GetOutput();
filter->Update();
filter->SetFunctor(filter->GetFunctor());
// Create an iterator for going through the image output
InputIteratorType it( source->GetOutput(), source->GetOutput()->GetRequestedRegion() );
OutputIteratorType ot(outputImage, outputImage->GetRequestedRegion());
bool pass = true;
// Check the content of the result image
std::cout << "Verification of the output " << std::endl;
ot.GoToBegin();
it.GoToBegin();
while( !ot.IsAtEnd() )
{
const InputPixelType input = it.Get();
const OutputPixelType output = ot.Get();
std::cout << (double) input<<": ";
for(unsigned int j=0; j<filter->GetNumberOfComponentsPerPixel(); j++)
{
std::cout<< " " << (double)output[j];
if( (double)output[j] > (double)maxRemainingLabel )
{
pass = false;
}
}
std::cout<<std::endl;
if ( !pass )
{
return EXIT_FAILURE;
}
++ot;
++it;
}
return EXIT_SUCCESS;
}
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.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 "itkExceptionObject.h"
#include "otbVectorImage.h"
#include "otbChangeLabelImageFilter.h"
#include "itkChangeLabelImageFilter.h"
#include "otbImage.h"
int otbChangeLabelImageFilterNew(int argc, char * argv[])
{
const unsigned int ImageDimension = 2;
typedef otb::Image<unsigned int, ImageDimension> InputImageType;
typedef otb::VectorImage<unsigned int, ImageDimension> OutputImageType;
typedef otb::ChangeLabelImageFilter<InputImageType, OutputImageType> FilterType;
FilterType::Pointer filter = FilterType::New();
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment