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

ENH : add test for ROIdataConversion

parent 9a1bbe52
Branches
Tags
No related merge requests found
......@@ -22,8 +22,10 @@
#define __otbROIdataConversion_h
#include <vector>
#include <otbImage.h>
#include <itkImageToImageFilter.h>
#include "otbImage.h"
#include "itkImageToImageFilter.h"
namespace otb
{
......
......@@ -25,6 +25,9 @@
#include <itkVector.h>
#include "otbROIdataConversion.h"
#include "itkImageRegionConstIterator.h"
#include "itkImageRegionIterator.h"
namespace otb
{
......@@ -35,20 +38,22 @@ ROIdataConversion< TInputImage, TInputROIImage >
{
this->SetNumberOfInputs(2);
this->SetNumberOfRequiredInputs(2);
// this->SetNumberOfOutputs(1);
}
template < class TInputImage, class TInputROIImage >
void
ROIdataConversion< TInputImage, TInputROIImage >
::GenerateOutputInformation(void)
{
typename OutputImageType::Pointer outputPtr = this->GetOutput();
typename OutputImageType::SizeType outputSize
= outputPtr->GetRequestedRegion().GetSize();
typename OutputImageType::SizeType outputSize = outputPtr->GetRequestedRegion().GetSize();
outputSize[0] = GetNumberOfSample();
outputPtr->SetRegions( outputSize );
}
template < class TInputImage, class TInputROIImage >
void
ROIdataConversion< TInputImage, TInputROIImage >
......@@ -58,7 +63,6 @@ ROIdataConversion< TInputImage, TInputROIImage >
typename InputROIImageType::Pointer inputROIPtr = this->GetROIImage();
inputImagePtr->SetRequestedRegion(inputImagePtr->GetLargestPossibleRegion());
inputROIPtr->SetRequestedRegion(inputROIPtr->GetLargestPossibleRegion());
}
template <class TInputImage, class TInputROIImage >
......@@ -66,12 +70,16 @@ void
ROIdataConversion< TInputImage, TInputROIImage >
::GenerateData ()
{
typename InputImageType::Pointer inputImagePtr = const_cast<InputImageType *>(this->GetInputImage());
typename InputROIImageType::ConstPointer inputROIPtr = this->GetROIImage();
typename OutputImageType::Pointer outputPtr = this->GetOutput();
outputPtr->Allocate();
outputPtr->FillBuffer(0);
typename InputImageType::PixelType defaultPix;
defaultPix.SetSize(inputImagePtr->GetNumberOfComponentsPerPixel());
defaultPix.Fill(0);
outputPtr->FillBuffer(defaultPix);
typename InputImageType::Pointer inputImagePtr = const_cast<InputImageType *>(this->GetInputImage());
typename InputROIImageType::ConstPointer inputROIPtr = this->GetROIImage();
itk::ImageRegionConstIterator< InputImageType > inputIter
( inputImagePtr, inputImagePtr->GetRequestedRegion() );
......@@ -95,7 +103,6 @@ ROIdataConversion< TInputImage, TInputROIImage >
++inputIter;
++trainingIter;
}
}
template < class TInputImage, class TInputROIImage >
......@@ -104,11 +111,10 @@ ROIdataConversion< TInputImage, TInputROIImage >
::GetNumberOfSample ()
{
InputROIImagePointerType inputROIPtr = GetROIImage();
itk::ImageRegionConstIterator< InputROIImageType > trainingIter
( inputROIPtr, inputROIPtr->GetRequestedRegion() );
itk::ImageRegionConstIterator< InputROIImageType > trainingIter( inputROIPtr, inputROIPtr->GetRequestedRegion() );
trainingIter.GoToBegin();
SizeValueType count = 0L;
while ( !trainingIter.IsAtEnd() )
{
......
......@@ -4,6 +4,7 @@ IF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING )
SET(BASELINE ${OTB_DATA_ROOT}/Baseline/OTB/Images)
SET(BASELINE_FILES ${OTB_DATA_ROOT}/Baseline/OTB/Files)
SET(INPUTDATA ${OTB_DATA_ROOT}/Input)
SET(EXAMPLESDATA ${OTB_DATA_ROOT}/Examples)
SET(TEMP ${OTBTesting_BINARY_DIR}/Temporary)
......@@ -19,6 +20,7 @@ SET(EPSILON_10e4 0.0001)
SET(LEARNING_TESTS1 ${CXX_TEST_PATH}/otbLearningTests1)
SET(LEARNING_TESTS2 ${CXX_TEST_PATH}/otbLearningTests2)
SET(LEARNING_TESTS3 ${CXX_TEST_PATH}/otbLearningTests3)
SET(LEARNING_TESTS4 ${CXX_TEST_PATH}/otbLearningTests4)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbLearningTESTS1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......@@ -355,6 +357,30 @@ ADD_TEST(leTuSVMInverseCosSpectralAngleKernelFunctorImageClassificationTest ${LE
${TEMP}/leTvsvm_model_image_one_class)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbLearningTESTS4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ------- otb::RoidataConversion -----------------------------
ADD_TEST(leTuROIdataConversionNew ${LEARNING_TESTS4}
otbROIdataConversionNew)
ADD_TEST(leTuROIdataConversion ${LEARNING_TESTS4}
# --compare-image ${TOL}
# ${BASELINE}/leSOMPoupeesClassified.hdr
# ${TEMP}/leTuROIdataConversion.tif
otbROIdataConversion
${INPUTDATA}/ImageLineDir.bsq.hdr
${INPUTDATA}/ImageLine.bsq.hdr
${TEMP}/leTuROIdataConversion.txt
)
# A enrichir
SET(BasicLearning_SRCS1
otbSVMModelNew.cxx
......@@ -402,6 +428,12 @@ otbSVMInverseCosSpectralAngleKernelFunctorImageClassificationTest.cxx
)
SET(BasicLearning_SRCS4
otbROIdataConversionNew.cxx
otbROIdataConversion.cxx
)
INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}")
ADD_EXECUTABLE(otbLearningTests1 otbLearningTests1.cxx ${BasicLearning_SRCS1})
......@@ -410,6 +442,8 @@ ADD_EXECUTABLE(otbLearningTests2 otbLearningTests2.cxx ${BasicLearning_SRCS2})
TARGET_LINK_LIBRARIES(otbLearningTests2 OTBLearning OTBIO)
ADD_EXECUTABLE(otbLearningTests3 otbLearningTests3.cxx ${BasicLearning_SRCS3})
TARGET_LINK_LIBRARIES(otbLearningTests3 OTBLearning OTBIO)
ADD_EXECUTABLE(otbLearningTests4 otbLearningTests4.cxx ${BasicLearning_SRCS4})
TARGET_LINK_LIBRARIES(otbLearningTests4 OTBLearning OTBIO)
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 "otbTestMain.h"
void RegisterTests()
{
REGISTER_TEST(otbROIdataConversionNew);
REGISTER_TEST(otbROIdataConversion);
}
/*=========================================================================
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.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include "otbROIdataConversion.h"
#include "otbImage.h"
#include "otbVectorImage.h"
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
#include "itkImageRegionIterator.h"
#include <iostream>
int otbROIdataConversion( int argc, char* argv[] )
{
typedef double PixelType;
const unsigned int Dimension = 2;
typedef otb::VectorImage< PixelType, Dimension > InputImageType;
typedef otb::Image< PixelType, Dimension > InputROIImageType;
typedef otb::ROIdataConversion<InputImageType, InputROIImageType> ConvertorType;
typedef ConvertorType::OutputImageType OutputImageType;
typedef otb::ImageFileReader<InputImageType> ReaderType;
typedef otb::ImageFileReader<InputROIImageType> ReaderROIType;
typedef otb::ImageFileWriter<OutputImageType> WriterType;
ConvertorType::Pointer convertor = ConvertorType::New();
ReaderType::Pointer readerIm = ReaderType::New();
ReaderROIType::Pointer readerTr = ReaderROIType::New();
readerIm->SetFileName(argv[1]);
readerTr->SetFileName(argv[2]);
readerIm->Update();
readerTr->Update();
convertor->SetInput( readerIm->GetOutput() );
convertor->SetROIImage( readerTr->GetOutput() );
convertor->Update();
std::ofstream file;
file.open(argv[3]);
itk::ImageRegionIterator< OutputImageType > outputIter( convertor->GetOutput(), convertor->GetOutput()->GetLargestPossibleRegion() );
outputIter.GoToBegin();
while ( !outputIter.IsAtEnd() )
{
file <<outputIter.Get()<<" ";
++outputIter;
}
file <<std::endl;
file.close();
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.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include "otbROIdataConversion.h"
#include "otbImage.h"
#include "otbVectorImage.h"
int otbROIdataConversionNew( int argc, char* argv[] )
{
typedef double PixelType;
const unsigned int Dimension = 2;
typedef otb::VectorImage< PixelType, Dimension > InputImageType;
typedef otb::ROIdataConversion<InputImageType, InputImageType> ConvertorType;
ConvertorType::Pointer convertor = ConvertorType::New();
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment