diff --git a/Testing/Fa/0000041-mean_shift.cxx b/Testing/Fa/0000041-mean_shift.cxx new file mode 100644 index 0000000000000000000000000000000000000000..db93fec560bc01dc882babbfbf46fad7ae3c7268 --- /dev/null +++ b/Testing/Fa/0000041-mean_shift.cxx @@ -0,0 +1,80 @@ +#include "otbImage.h" +#include "otbVectorImage.h" +#include "otbImageFileReader.h" +#include "otbStreamingImageFileWriter.h" +#include "otbMeanShiftVectorImageFilter.h" + +//Code adapted from submission from Christophe Simler +// http://bugs.orfeo-toolbox.org/view.php?id=41 + +int main(int argc, char *argv[]) +{ + + if (argc < 9) + { + std::cout << + "Usage : inputImage rangeRadius spatialRadius minRegionSize outfilenamefiltered outfilenamesegmented outfilenamelabeled outfilenameboundary" + << std::endl; + + return EXIT_FAILURE; + } + + char * filename = argv[1]; + int rangeRadius = atoi(argv[2]); + int spatialRadius = atoi(argv[3]); + int minRegionSize = atoi(argv[4]); + char * outfilenamefiltered = argv[5]; + char * outfilenamesegmented = argv[6]; + char * outfilenamelabeled = argv[7]; + char * outfilenameboundary = argv[8]; + + typedef otb::VectorImage<unsigned char, 2> ImageType; // image d'entree, image filtree et image segmente + typedef otb::Image<int, 2> TLabeledOutput; // image labelisee, image des contours (de l'image labellisee) + + // lecture de l'image d'entree a partir d'un fichier + typedef otb::ImageFileReader<ImageType> ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(filename); + + // traitement avec le filtre + typedef otb::MeanShiftVectorImageFilter<ImageType, ImageType, TLabeledOutput> FilterType; + FilterType::Pointer filter = FilterType::New(); + filter->SetRangeRadius(rangeRadius); + filter->SetSpatialRadius(spatialRadius); + filter->SetMinimumRegionSize(minRegionSize); + + // sauvegarde de l'image filtree, + typedef otb::StreamingImageFileWriter<ImageType> WriterType1; + WriterType1::Pointer writer1 = WriterType1::New(); + writer1->SetFileName(outfilenamefiltered); + + // sauvegarde de l'image segmente, + typedef otb::StreamingImageFileWriter<ImageType> WriterType2; + WriterType2::Pointer writer2 = WriterType2::New(); + writer2->SetFileName(outfilenamesegmented); + + // sauvegarde de l'image labelisee + typedef otb::StreamingImageFileWriter<TLabeledOutput> WriterType3; + WriterType3::Pointer writer3 = WriterType3::New(); + writer3->SetFileName(outfilenamelabeled); + + // sauvegarde de l'image de contours + typedef otb::StreamingImageFileWriter<TLabeledOutput> WriterType4; + WriterType4::Pointer writer4 = WriterType4::New(); + writer4->SetFileName(outfilenameboundary); + + // construction du pipeline + filter->SetInput(reader->GetOutput()); + + writer1->SetInput(filter->GetOutput()); // image filtree (*) + writer2->SetInput(filter->GetClusteredOutput()); // image segmente (clusterisee avec coherence spaciale ?) (*) + writer3->SetInput(filter->GetLabeledClusteredOutput()); // image des labels des clusters + writer4->SetInput(filter->GetClusterBoundariesOutput()); // image des contours des clusters (contours de l'image labelisee) + + writer1->Update(); + writer2->Update(); + writer3->Update(); + writer4->Update(); + + return 0; +} diff --git a/Testing/Fa/0000132-jpg.cxx b/Testing/Fa/0000132-jpg.cxx new file mode 100644 index 0000000000000000000000000000000000000000..6e46e54ed5648c1b31d62fea5ce934443e692b79 --- /dev/null +++ b/Testing/Fa/0000132-jpg.cxx @@ -0,0 +1,46 @@ +/*========================================================================= + + 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 "otbVectorImage.h" +#include "otbImageFileReader.h" + +//Code adapted from submission from Jordi INGLADA +// http://bugs.orfeo-toolbox.org/view.php?id=132 + +int main(int argc, char *argv[]) +{ + if (argc < 1) + { + std::cout << "Usage : inputImage" << std::endl; + return EXIT_FAILURE; + } + + char * filename = argv[1]; + + typedef double PixelType; + typedef otb::VectorImage<PixelType> ImageType; + typedef otb::ImageFileReader<ImageType> ReaderType; + + // check for input images + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(filename); + reader->UpdateOutputInformation(); + std::cout << reader << std::endl; + + return EXIT_SUCCESS; +} diff --git a/Testing/Fa/0000169-fftcomplextocomplex.cxx b/Testing/Fa/0000169-fftcomplextocomplex.cxx new file mode 100644 index 0000000000000000000000000000000000000000..9e89ef469fcafeb0f025fbbe73b2482db198c2f7 --- /dev/null +++ b/Testing/Fa/0000169-fftcomplextocomplex.cxx @@ -0,0 +1,30 @@ +/*========================================================================= + + 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 "itkMacro.h" +#include "itkFFTComplexToComplexImageFilter.h" + +int main(int argc, char * argv[]) +{ + typedef itk::FFTComplexToComplexImageFilter <float, 2> FFTFilterType; + + FFTFilterType::Pointer fftFilter = FFTFilterType::New(); + fftFilter->DebugOn(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Fa/0000209-SVMValidationLinearlySeparableProbEstimation.cxx b/Testing/Fa/0000209-SVMValidationLinearlySeparableProbEstimation.cxx new file mode 100644 index 0000000000000000000000000000000000000000..98d06da6f71263a6ab5e5b66a9a4f1aba906719f --- /dev/null +++ b/Testing/Fa/0000209-SVMValidationLinearlySeparableProbEstimation.cxx @@ -0,0 +1,208 @@ +/*========================================================================= + + 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 "itkMacro.h" +#include "itkListSample.h" +#include <iostream> + +#include "otbSVMSampleListModelEstimator.h" +#include "otbSVMClassifier.h" +#include "otbSVMKernels.h" + +#include "itkMersenneTwisterRandomVariateGenerator.h" +#include "otbSVMClassifier.h" +#include "otbConfusionMatrixCalculator.h" + +#include "otbMath.h" + +#include <fstream> + +/* +This test show a problem with the SVM library using the probability +estimation : bug 209. +If the probability estimation is activated, the classifier isn't +abble to find the hyperplan even if the sample are linearly +seperable. +cf. test leTvBug209_SVMValidationLinearlySeparableWithoutProbEstimate +=> OK +and leTvBug209_SVMValidationLinearlySeparableWithProbEstimate => KO +http://bugs.orfeo-toolbox.org/view.php?id=209 +*/ + +int main(int argc, char* argv[]) +{ + if(argc != 14) + { + std::cerr<<"Usage: "<<argv[0]<<" nbTrainingSamples nbValidationSamples positiveCenterX positiveCenterY negativeCenterX negativeCenterY positiveRadiusMin positiveRadiusMax negativeRadiusMin negativeRadiusMax kernel probEstimate"<<std::endl; + return EXIT_FAILURE; + } + unsigned int nbTrainingSamples = atoi(argv[2]); + unsigned int nbValidationSamples = atoi(argv[3]); + double cpx = atof(argv[4]); + double cpy = atof(argv[5]); + double cnx = atof(argv[6]); + double cny = atof(argv[7]); + double prmin = atof(argv[8]); + double prmax = atof(argv[9]); + double nrmin = atof(argv[10]); + double nrmax = atof(argv[11]); + unsigned int kernel = atoi(argv[12]); + bool probEstimate = atoi(argv[13]); + + typedef double InputPixelType; + typedef unsigned short LabelType; + + typedef itk::VariableLengthVector<InputPixelType> SampleType; + typedef itk::Statistics::ListSample<SampleType> ListSampleType; + typedef itk::FixedArray<LabelType, 1> TrainingSampleType; + typedef itk::Statistics::ListSample<TrainingSampleType> TrainingListSampleType; + typedef itk::Statistics::MersenneTwisterRandomVariateGenerator RandomGeneratorType; + typedef otb::SVMSampleListModelEstimator<ListSampleType, TrainingListSampleType> EstimatorType; + typedef otb::SVMClassifier<ListSampleType, LabelType> ClassifierType; + typedef ClassifierType::OutputType ClassifierOutputType; + typedef otb::ConfusionMatrixCalculator + <TrainingListSampleType, TrainingListSampleType> ConfusionMatrixCalculatorType; + + + RandomGeneratorType::Pointer random = RandomGeneratorType::New(); + random->SetSeed((unsigned int)0); + + // First, generate training and validation sets + ListSampleType::Pointer trainingSamples = ListSampleType::New(); + TrainingListSampleType::Pointer trainingLabels = TrainingListSampleType::New(); + ListSampleType::Pointer validationSamples = ListSampleType::New(); + TrainingListSampleType::Pointer validationLabels = TrainingListSampleType::New(); + + // Generate training set + //std::ofstream training("training.csv"); + for(unsigned int i =0; i < nbTrainingSamples; ++i) + { + // Generate a positive sample + double angle = random->GetVariateWithOpenUpperRange( otb::CONST_2PI ); + double radius = random->GetUniformVariate(prmin, prmax); + SampleType pSample(2); + pSample[0] = cpx+radius*vcl_sin(angle); + pSample[1] = cpy+radius*vcl_cos(angle); + TrainingSampleType label; + label[0]=1; + trainingSamples->PushBack(pSample); + trainingLabels->PushBack(label); + + //training<<"1 1:"<<pSample[0]<<" 2:"<<pSample[1]<<std::endl; + + // Generate a negative sample + angle = random->GetVariateWithOpenUpperRange( otb::CONST_2PI ); + radius = random->GetUniformVariate(nrmin, nrmax); + SampleType nSample(2); + nSample[0] = cnx+radius*vcl_sin(angle); + nSample[1] = cny+radius*vcl_cos(angle); + label[0]=2; + trainingSamples->PushBack(nSample); + trainingLabels->PushBack(label); + + //training<<"2 1:"<<nSample[0]<<" 2:"<<nSample[1]<<std::endl; + + } + //training.close(); + + // Generate validation set + + std::ofstream validation("validation.csv"); + for(unsigned int i =0; i < nbValidationSamples; ++i) + { + // Generate a positive sample + double angle = random->GetVariateWithOpenUpperRange( otb::CONST_2PI ); + double radius = random->GetUniformVariate(prmin, prmax); + SampleType pSample(2); + pSample[0] = cpx+radius*vcl_sin(angle); + pSample[1] = cpy+radius*vcl_cos(angle); + TrainingSampleType label; + label[0]=1; + validationSamples->PushBack(pSample); + validationLabels->PushBack(label); + //validation<<"1 1:"<<pSample[0]<<" 2:"<<pSample[1]<<std::endl; + + // Generate a negative sample + angle = random->GetVariateWithOpenUpperRange( otb::CONST_2PI ); + radius = random->GetUniformVariate(nrmin, nrmax); + SampleType nSample(2); + nSample[0] = cnx+radius*vcl_sin(angle); + nSample[1] = cny+radius*vcl_cos(angle); + label[0]=2; + validationSamples->PushBack(nSample); + validationLabels->PushBack(label); + //validation<<"2 1:"<<nSample[0]<<" 2:"<<nSample[1]<<std::endl; + + } + //validation.close(); + + // Learn + EstimatorType::Pointer estimator = EstimatorType::New(); + estimator->SetInputSampleList(trainingSamples); + estimator->SetTrainingSampleList(trainingLabels); + + estimator->SetKernelType(kernel); + estimator->DoProbabilityEstimates(probEstimate); +// estimator->SetParametersOptimization(true); + estimator->Update(); + + //estimator->SaveModel("model.svm"); + + // Classify + ClassifierType::Pointer validationClassifier = ClassifierType::New(); + validationClassifier->SetSample(validationSamples); + validationClassifier->SetNumberOfClasses(2); + validationClassifier->SetModel(estimator->GetModel()); + validationClassifier->Update(); + + // Confusion + ClassifierOutputType::ConstIterator it = validationClassifier->GetOutput()->Begin(); + ClassifierOutputType::ConstIterator itEnd = validationClassifier->GetOutput()->End(); + + TrainingListSampleType::Pointer classifierListLabel = TrainingListSampleType::New(); + + while (it != itEnd) + { + classifierListLabel->PushBack(it.GetClassLabel()); + ++it; + } + + ConfusionMatrixCalculatorType::Pointer confMatCalc = ConfusionMatrixCalculatorType::New(); + + confMatCalc->SetReferenceLabels(validationLabels); + confMatCalc->SetProducedLabels(classifierListLabel); + + confMatCalc->Update(); + + std::cout<<std::endl; + std::cout<<"Confusion matrix: "<<std::endl<< confMatCalc->GetConfusionMatrix()<<std::endl<<std::endl; + std::cout<<"Kappa Index: "<<std::endl<< confMatCalc->GetKappaIndex()<<std::endl<<std::endl; + + if(confMatCalc->GetKappaIndex()!=1) + { + std::cerr<<"Kappa index should be 1."<<std::endl; + return EXIT_FAILURE; + } + else + { + return EXIT_SUCCESS; + } +} + diff --git a/Testing/Fa/0000307-ExtractROICompareRegionsImplementations.cxx b/Testing/Fa/0000307-ExtractROICompareRegionsImplementations.cxx new file mode 100644 index 0000000000000000000000000000000000000000..10ac9755b5fe4133f8dff03b10679121ac7b12ec --- /dev/null +++ b/Testing/Fa/0000307-ExtractROICompareRegionsImplementations.cxx @@ -0,0 +1,418 @@ +/*========================================================================= + + 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 "otbImage.h" +#include "otbVectorImage.h" + +#include "itkExtractImageFilter.h" +#include "itkVectorIndexSelectionCastImageFilter.h" +#include "otbExtractROI.h" +#include "otbMultiChannelExtractROI.h" +#include "otbMultiToMonoChannelExtractROI.h" + + +typedef unsigned char PixelType; + +typedef otb::Image<PixelType> ImageType; +typedef otb::VectorImage<PixelType> VectorImageType; + +typedef ImageType::RegionType RegionType; +typedef ImageType::IndexType IndexType; +typedef IndexType::IndexValueType IndexValueType; +typedef ImageType::SizeType SizeType; +typedef SizeType::SizeValueType SizeValueType; + +// ITK filters +typedef itk::ExtractImageFilter<ImageType, ImageType> + ExtractImageFilterType; +typedef itk::VectorIndexSelectionCastImageFilter<VectorImageType, ImageType> + VectorIndexSelectionCastImageFilterType; + +// OTB filters +typedef otb::ExtractROI<PixelType, PixelType> + ExtractROIType; +typedef otb::MultiChannelExtractROI<PixelType, PixelType> + MultiChannelExtractROIType; +typedef otb::MultiToMonoChannelExtractROI<PixelType, PixelType> + MultiToMonoChannelExtractROIType; + + +ImageType::Pointer makeImage(IndexValueType startX, IndexValueType startY, SizeValueType sizeX, SizeValueType sizeY) +{ + ImageType::Pointer im = ImageType::New(); + + RegionType region; + + region.SetIndex(0, startX); + region.SetIndex(1, startY); + region.SetSize(0, sizeX); + region.SetSize(1, sizeY); + + im->SetRegions(region); + im->Allocate(); + + return im; +} + +VectorImageType::Pointer makeVectorImage(IndexValueType startX, IndexValueType startY, SizeValueType sizeX, SizeValueType sizeY, int nbChannel = 3) +{ + VectorImageType::Pointer im = VectorImageType::New(); + + RegionType region; + + region.SetIndex(0, startX); + region.SetIndex(1, startY); + region.SetSize(0, sizeX); + region.SetSize(1, sizeY); + + im->SetRegions(region); + im->SetNumberOfComponentsPerPixel(nbChannel); + im->Allocate(); + + return im; +} + +int otbITKExtractImageFilterROITestRegion(int argc, char * argv[]) +{ + ImageType::Pointer in; + RegionType extractionRegion; + ExtractImageFilterType::Pointer extract; + + in = makeImage(0, 0, 100, 100); + + extractionRegion.SetIndex(0, 50); + extractionRegion.SetIndex(1, 50); + extractionRegion.SetSize(0, 10); + extractionRegion.SetSize(1, 10); + + extract = ExtractImageFilterType::New(); + extract->SetInput(in); + extract->SetExtractionRegion(extractionRegion); + extract->UpdateOutputInformation(); + + std::cout << "Input LargestPossibleRegion : " << in->GetLargestPossibleRegion() << std::endl; + std::cout << "ExtractionRegion : " << extract->GetExtractionRegion() << std::endl; + std::cout << "Output LargestPossibleRegion : " << extract->GetOutput()->GetLargestPossibleRegion() << std::endl; + + if (extract->GetOutput()->GetLargestPossibleRegion() != extract->GetExtractionRegion()) + { + return EXIT_FAILURE; + } + + in = makeImage(20, 20, 100, 100); + + extractionRegion.SetIndex(0, 50); + extractionRegion.SetIndex(1, 50); + extractionRegion.SetSize(0, 10); + extractionRegion.SetSize(1, 10); + + extract = ExtractImageFilterType::New(); + extract->SetInput(in); + extract->SetExtractionRegion(extractionRegion); + extract->UpdateOutputInformation(); + + std::cout << "Input LargestPossibleRegion : " << in->GetLargestPossibleRegion() << std::endl; + std::cout << "ExtractionRegion : " << extract->GetExtractionRegion() << std::endl; + std::cout << "Output LargestPossibleRegion : " << extract->GetOutput()->GetLargestPossibleRegion() << std::endl; + + if (extract->GetOutput()->GetLargestPossibleRegion() != extract->GetExtractionRegion()) + { + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + + +int otbITKVectorIndexSelectionCastTestRegion(int argc, char * argv[]) +{ + VectorImageType::Pointer in; + RegionType extractionRegion; + VectorIndexSelectionCastImageFilterType::Pointer extract; + + in = makeVectorImage(0, 0, 100, 100, 3); + + extract = VectorIndexSelectionCastImageFilterType::New(); + extract->SetInput(in); + extract->SetIndex(1); + extract->UpdateOutputInformation(); + + std::cout << "Input LargestPossibleRegion : " << in->GetLargestPossibleRegion() << std::endl; + std::cout << "Output LargestPossibleRegion : " << extract->GetOutput()->GetLargestPossibleRegion() << std::endl; + + if (extract->GetOutput()->GetLargestPossibleRegion() != in->GetLargestPossibleRegion()) + { + return EXIT_FAILURE; + } + + in = makeVectorImage(50, 50, 100, 100, 3); + + extract = VectorIndexSelectionCastImageFilterType::New(); + extract->SetInput(in); + extract->SetIndex(1); + extract->UpdateOutputInformation(); + + std::cout << "Input LargestPossibleRegion : " << in->GetLargestPossibleRegion() << std::endl; + std::cout << "Output LargestPossibleRegion : " << extract->GetOutput()->GetLargestPossibleRegion() << std::endl; + + if (extract->GetOutput()->GetLargestPossibleRegion() != in->GetLargestPossibleRegion()) + { + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + + +int otbMultiToMonoChannelExtractROITestRegion(int argc, char * argv[]) +{ + VectorImageType::Pointer in; + RegionType extractionRegion; + MultiToMonoChannelExtractROIType::Pointer extract; + + in = makeVectorImage(0, 0, 100, 100, 3); + + extractionRegion.SetIndex(0, 50); + extractionRegion.SetIndex(1, 50); + extractionRegion.SetSize(0, 10); + extractionRegion.SetSize(1, 10); + + extract = MultiToMonoChannelExtractROIType::New(); + extract->SetInput(in); + extract->SetExtractionRegion(extractionRegion); + extract->UpdateOutputInformation(); + + std::cout << "Input LargestPossibleRegion : " << in->GetLargestPossibleRegion() << std::endl; + std::cout << "ExtractionRegion : " << extract->GetExtractionRegion() << std::endl; + std::cout << "Output LargestPossibleRegion : " << extract->GetOutput()->GetLargestPossibleRegion() << std::endl; + + if (extract->GetOutput()->GetLargestPossibleRegion() != extract->GetExtractionRegion()) + { + return EXIT_FAILURE; + } + + in = makeVectorImage(20, 20, 100, 100, 3); + + extractionRegion.SetIndex(0, 50); + extractionRegion.SetIndex(1, 50); + extractionRegion.SetSize(0, 10); + extractionRegion.SetSize(1, 10); + + extract = MultiToMonoChannelExtractROIType::New(); + extract->SetInput(in); + extract->SetExtractionRegion(extractionRegion); + extract->UpdateOutputInformation(); + + std::cout << "Input LargestPossibleRegion : " << in->GetLargestPossibleRegion() << std::endl; + std::cout << "ExtractionRegion : " << extract->GetExtractionRegion() << std::endl; + std::cout << "Output LargestPossibleRegion : " << extract->GetOutput()->GetLargestPossibleRegion() << std::endl; + + if (extract->GetOutput()->GetLargestPossibleRegion() != extract->GetExtractionRegion()) + { + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + + + +int otbMultiChannelExtractROITestRegion(int argc, char * argv[]) +{ + VectorImageType::Pointer in; + RegionType extractionRegion; + MultiChannelExtractROIType::Pointer extract; + + in = makeVectorImage(0, 0, 100, 100, 3); + + extractionRegion.SetIndex(0, 50); + extractionRegion.SetIndex(1, 50); + extractionRegion.SetSize(0, 10); + extractionRegion.SetSize(1, 10); + + extract = MultiChannelExtractROIType::New(); + extract->SetInput(in); + extract->SetExtractionRegion(extractionRegion); + extract->UpdateOutputInformation(); + + std::cout << "Input LargestPossibleRegion : " << in->GetLargestPossibleRegion() << std::endl; + std::cout << "ExtractionRegion : " << extract->GetExtractionRegion() << std::endl; + std::cout << "Output LargestPossibleRegion : " << extract->GetOutput()->GetLargestPossibleRegion() << std::endl; + + if (extract->GetOutput()->GetLargestPossibleRegion() != extract->GetExtractionRegion()) + { + return EXIT_FAILURE; + } + + in = makeVectorImage(20, 20, 100, 100, 3); + + extractionRegion.SetIndex(0, 50); + extractionRegion.SetIndex(1, 50); + extractionRegion.SetSize(0, 10); + extractionRegion.SetSize(1, 10); + + extract = MultiChannelExtractROIType::New(); + extract->SetInput(in); + extract->SetExtractionRegion(extractionRegion); + extract->UpdateOutputInformation(); + + std::cout << "Input LargestPossibleRegion : " << in->GetLargestPossibleRegion() << std::endl; + std::cout << "ExtractionRegion : " << extract->GetExtractionRegion() << std::endl; + std::cout << "Output LargestPossibleRegion : " << extract->GetOutput()->GetLargestPossibleRegion() << std::endl; + + if (extract->GetOutput()->GetLargestPossibleRegion() != extract->GetExtractionRegion()) + { + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + + +int otbExtractROITestRegion(int argc, char * argv[]) +{ + ImageType::Pointer in; + RegionType extractionRegion; + ExtractROIType::Pointer extract; + + in = makeImage(0, 0, 100, 100); + + extractionRegion.SetIndex(0, 50); + extractionRegion.SetIndex(1, 50); + extractionRegion.SetSize(0, 10); + extractionRegion.SetSize(1, 10); + + extract = ExtractROIType::New(); + extract->SetInput(in); + extract->SetExtractionRegion(extractionRegion); + extract->UpdateOutputInformation(); + + std::cout << "Input LargestPossibleRegion : " << in->GetLargestPossibleRegion() << std::endl; + std::cout << "ExtractionRegion : " << extract->GetExtractionRegion() << std::endl; + std::cout << "Output LargestPossibleRegion : " << extract->GetOutput()->GetLargestPossibleRegion() << std::endl; + + if (extract->GetOutput()->GetLargestPossibleRegion() != extract->GetExtractionRegion()) + { + return EXIT_FAILURE; + } + + in = makeImage(20, 20, 100, 100); + + extractionRegion.SetIndex(0, 50); + extractionRegion.SetIndex(1, 50); + extractionRegion.SetSize(0, 10); + extractionRegion.SetSize(1, 10); + + extract = ExtractROIType::New(); + extract->SetInput(in); + extract->SetExtractionRegion(extractionRegion); + extract->UpdateOutputInformation(); + + std::cout << "Input LargestPossibleRegion : " << in->GetLargestPossibleRegion() << std::endl; + std::cout << "ExtractionRegion : " << extract->GetExtractionRegion() << std::endl; + std::cout << "Output LargestPossibleRegion : " << extract->GetOutput()->GetLargestPossibleRegion() << std::endl; + + if (extract->GetOutput()->GetLargestPossibleRegion() != extract->GetExtractionRegion()) + { + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + + + +int main(int argc, char * argv[]) +{ + int unitaryResult; + int finalResult = EXIT_SUCCESS; + + std::cout << "*******************************" << std::endl; + std::cout << "Starting test itk::ExtractImageFilter" << std::endl; + unitaryResult = otbITKExtractImageFilterROITestRegion(argc, argv); + if (unitaryResult == EXIT_FAILURE) + { + std::cout << "-> Testing itk::ExtractImageFilter FAILED" << std::endl; + finalResult = EXIT_FAILURE; + } + else + { + std::cout << "-> Testing itk::ExtractImageFilter OK" << std::endl; + } + + + std::cout << "*******************************" << std::endl; + std::cout << "Starting test itk::VectorIndexSelectionCast" << std::endl; + unitaryResult = otbITKVectorIndexSelectionCastTestRegion(argc, argv); + if (unitaryResult == EXIT_FAILURE) + { + std::cout << "-> Testing itk::VectorIndexSelectionCast FAILED" << std::endl; + finalResult = EXIT_FAILURE; + } + else + { + std::cout << "-> Testing itk::VectorIndexSelectionCast OK" << std::endl; + } + + + std::cout << "*******************************" << std::endl; + std::cout << "Starting test otb::MultiToMonoChannelExtractROI" << std::endl; + unitaryResult = otbMultiToMonoChannelExtractROITestRegion(argc, argv); + if (unitaryResult == EXIT_FAILURE) + { + std::cout << "-> Testing otb::MultiToMonoChannelExtractROI FAILED" << std::endl; + finalResult = EXIT_FAILURE; + } + else + { + std::cout << "-> Testing otb::MultiToMonoChannelExtractROI OK" << std::endl; + } + + + std::cout << "*******************************" << std::endl; + std::cout << "Starting test otb::MultiChannelExtractROI" << std::endl; + unitaryResult = otbMultiChannelExtractROITestRegion(argc, argv); + if (unitaryResult == EXIT_FAILURE) + { + std::cout << "-> Testing otb::MultiChannelExtractROI FAILED" << std::endl; + finalResult = EXIT_FAILURE; + } + else + { + std::cout << "-> Testing otb::MultiChannelExtractROI OK" << std::endl; + } + + + std::cout << "*******************************" << std::endl; + std::cout << "Starting test otb::ExtractROI" << std::endl; + unitaryResult = otbExtractROITestRegion(argc, argv); + if (unitaryResult == EXIT_FAILURE) + { + std::cout << "-> Testing otb::ExtractROI FAILED" << std::endl; + finalResult = EXIT_FAILURE; + } + else + { + std::cout << "-> Testing otb::ExtractROI OK" << std::endl; + } + + return finalResult; + +} + diff --git a/Testing/Fa/0000428-CastImageFilterStreaming.cxx b/Testing/Fa/0000428-CastImageFilterStreaming.cxx new file mode 100644 index 0000000000000000000000000000000000000000..6831ca938240ec2933b6bd1f3858ebb889f48b65 --- /dev/null +++ b/Testing/Fa/0000428-CastImageFilterStreaming.cxx @@ -0,0 +1,60 @@ +/*========================================================================= + + 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 "otbImage.h" + +#include "otbImageFileReader.h" +#include "otbStreamingImageFileWriter.h" + +#include "itkCastImageFilter.h" + +/** + * This test reproduces a problem encountered with CastImageFilter and a streaming + * writer. When the image to write is already loaded in memory and InPlaceOn() is + * called, only the first stripe is repeated across the output image. + * Issue number 0000428 + */ +int main(int argc, char* argv[]) +{ + if (argc != 3) + { + std::cout << argv[0] << " <input image> <output image>" << std::endl; + return EXIT_FAILURE; + } + + typedef otb::Image<float, 2> ImageType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::StreamingImageFileWriter<ImageType> WriterType; + typedef itk::CastImageFilter<ImageType, ImageType> CastFilterType; + + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(argv[1]); + reader->Update(); + + CastFilterType::Pointer caster = CastFilterType::New(); + caster->SetInput( reader->GetOutput() ); + caster->InPlaceOn(); + + WriterType::Pointer writer = WriterType::New(); + writer->SetInput(caster->GetOutput()); + writer->SetFileName(argv[2]); + //writer->SetAutomaticTiledStreaming(1024); + writer->SetNumberOfDivisionsStrippedStreaming(10); + writer->Update(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Fa/0000433-LineSegmentDetector_8b_16b_compare.cxx b/Testing/Fa/0000433-LineSegmentDetector_8b_16b_compare.cxx new file mode 100644 index 0000000000000000000000000000000000000000..b2f7411626a23b1f158f8a2f94d952a4b338ca8d --- /dev/null +++ b/Testing/Fa/0000433-LineSegmentDetector_8b_16b_compare.cxx @@ -0,0 +1,88 @@ +/*========================================================================= + + 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 "otbImage.h" +#include "otbLineSegmentDetector.h" + +#include "otbImageFileReader.h" +#include "otbVectorDataFileWriter.h" +#include "otbImageFileWriter.h" + +// Code showing difference between LSD with 8 and 16 bits images. +// http://bugs.orfeo-toolbox.org/view.php?id=433 + +int main(int argc, char *argv[]) +{ + if (argc != 6) + { + std::cout << "Usage : <inputImage_8b> <inputImage_16b> <outputImage_8b> <outputImage_16b>" << std::endl; + + return EXIT_FAILURE; + } + + const char * infname8 = argv[2]; + const char * infname16 = argv[3]; + const char * outfname8 = argv[4]; + const char * outfname16 = argv[5]; + + /** Typedefs */ + typedef unsigned char PixelType8; + typedef otb::Image<PixelType8> ImageType8; + typedef otb::ImageFileReader<ImageType8> ReaderType8; + typedef otb::LineSegmentDetector<ImageType8, double> LSDFilterType8; + typedef otb::ImageFileWriter<ImageType8> WriterType8; + + typedef unsigned short PixelType16; + typedef otb::Image<PixelType16> ImageType16; + typedef otb::ImageFileReader<ImageType16> ReaderType16; + typedef otb::LineSegmentDetector<ImageType16, double> LSDFilterType16; + typedef otb::ImageFileWriter<ImageType16> WriterType16; + + typedef LSDFilterType8::VectorDataType VectorDataType; + typedef otb::VectorDataFileWriter<VectorDataType> VectorDataWriterType; + + /** 8bits */ + //Instantiation of smart pointer + ReaderType8::Pointer reader8 = ReaderType8::New(); + LSDFilterType8::Pointer lsdFilter8 = LSDFilterType8::New(); + //Reade the input image + reader8->SetFileName(infname8); + reader8->GenerateOutputInformation(); + //LSD Detection + lsdFilter8->SetInput(reader8->GetOutput()); + VectorDataWriterType::Pointer vdWriter8 = VectorDataWriterType::New(); + vdWriter8->SetFileName(outfname8); + vdWriter8->SetInput(lsdFilter8->GetOutput()); + vdWriter8->Update(); + + /** 16bits */ + //Instantiation of smart pointer + ReaderType16::Pointer reader16 = ReaderType16::New(); + LSDFilterType16::Pointer lsdFilter16 = LSDFilterType16::New(); + //Reade the input image + reader16->SetFileName(infname16); + reader16->GenerateOutputInformation(); + //LSD Detection + lsdFilter16->SetInput(reader16->GetOutput()); + VectorDataWriterType::Pointer vdWriter16 = VectorDataWriterType::New(); + vdWriter16->SetFileName(outfname16); + vdWriter16->SetInput(lsdFilter16->GetOutput()); + vdWriter16->Update(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Fa/0000436-WrapperInputImage_GetImage.cxx b/Testing/Fa/0000436-WrapperInputImage_GetImage.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e542e2f593556bc79188df03c9ad291ed2015d32 --- /dev/null +++ b/Testing/Fa/0000436-WrapperInputImage_GetImage.cxx @@ -0,0 +1,54 @@ +/*========================================================================= + + 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 "otbWrapperInputImageParameter.h" + + +#include "otbImage.h" +#include "otbLineSegmentDetector.h" + +#include "otbImageFileReader.h" +#include "otbVectorDataFileWriter.h" +#include "otbImageFileWriter.h" + +// Code showing a problem calling twice GetImputImageParameter +// http://bugs.orfeo-toolbox.org/view.php?id=436 + +int main(int argc, char *argv[]) +{ + if (argc != 3) + { + std::cout << "Usage : <inputImage>" << std::endl; + + return EXIT_FAILURE; + } + + typedef otb::Wrapper::InputImageParameter InputImageParameterType; + InputImageParameterType::Pointer param = InputImageParameterType::New(); + + param->SetFromFileName(argv[2]); + + if( param->GetImage() != param->GetImage() ) + { + return EXIT_FAILURE; + } + + + + return EXIT_SUCCESS; +} diff --git a/Testing/Fa/0000437-WriteImageCentOS.cxx b/Testing/Fa/0000437-WriteImageCentOS.cxx new file mode 100644 index 0000000000000000000000000000000000000000..dbbfed069c7bdd13295c238987f037f65dc92732 --- /dev/null +++ b/Testing/Fa/0000437-WriteImageCentOS.cxx @@ -0,0 +1,59 @@ +/*========================================================================= + + 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 "otbImage.h" + +#include "otbImageFileReader.h" +#include "otbStreamingImageFileWriter.h" + +#include "itkCastImageFilter.h" + +/** + * This test reproduces a problem encountered with CentOS5.5 using 3.8.2 libTIFF version + * Issue number 0000437 + */ +int main(int argc, char* argv[]) +{ + if (argc != 3) + { + std::cout << argv[0] << " <input image> <output image>" << std::endl; + return EXIT_FAILURE; + } + + typedef otb::Image<unsigned short, 2> ImageType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::StreamingImageFileWriter<ImageType> WriterType; + typedef itk::CastImageFilter<ImageType, ImageType> CastFilterType; + + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(argv[1]); + reader->Update(); + + CastFilterType::Pointer caster = CastFilterType::New(); + caster->SetInput( reader->GetOutput() ); + caster->InPlaceOn(); + + WriterType::Pointer writer = WriterType::New(); + writer->SetInput(caster->GetOutput()); + writer->SetFileName(argv[2]); + //writer->SetAutomaticTiledStreaming(1024); + writer->WriteGeomFileOn(); + writer->SetTileDimensionTiledStreaming(256); + writer->Update(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Fa/000295-MeanShiftVectorImageFilterWithStreamingShrink.cxx b/Testing/Fa/000295-MeanShiftVectorImageFilterWithStreamingShrink.cxx new file mode 100644 index 0000000000000000000000000000000000000000..061e354aafbbfa794c107aae4ada9f1195e09f2e --- /dev/null +++ b/Testing/Fa/000295-MeanShiftVectorImageFilterWithStreamingShrink.cxx @@ -0,0 +1,60 @@ +/*========================================================================= + + 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 "itkMacro.h" +#include "otbVectorImage.h" +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "otbMeanShiftVectorImageFilter.h" +#include "otbStreamingShrinkImageFilter.h" + + +int main(int argc, char * argv[]) +{ + const char * infname = argv[1]; + const unsigned int spatialRadius = atoi(argv[2]); + const double rangeRadius = atof(argv[3]); + const unsigned int minRegionSize = atoi(argv[4]); + unsigned int factor = atoi(argv[5]); + + const unsigned int Dimension = 2; + typedef float PixelType; + typedef otb::VectorImage<PixelType, Dimension> ImageType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::MeanShiftVectorImageFilter<ImageType, ImageType> FilterType; + typedef otb::StreamingShrinkImageFilter<ImageType, ImageType> ShrinkType; + + // Instantiating object + FilterType::Pointer filter = FilterType::New(); + ReaderType::Pointer reader = ReaderType::New(); + ShrinkType::Pointer shrinker = ShrinkType::New(); + + reader->SetFileName(infname); + + + filter->SetSpatialRadius(spatialRadius); + filter->SetRangeRadius(rangeRadius); + filter->SetMinimumRegionSize(minRegionSize); + filter->SetInput(reader->GetOutput()); + filter->UpdateOutputInformation(); + + shrinker->SetInput(filter->GetOutput()); + shrinker->SetShrinkFactor(factor); + shrinker->Update(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Fa/00134-feature_extraction.cxx b/Testing/Fa/00134-feature_extraction.cxx new file mode 100644 index 0000000000000000000000000000000000000000..5b2fd4f3491294b3c2578f081bacde651964910e --- /dev/null +++ b/Testing/Fa/00134-feature_extraction.cxx @@ -0,0 +1,113 @@ +/*========================================================================= + + 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 "otbImage.h" +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "otbVectorImage.h" +#include "otbImageList.h" +#include "otbImageListToVectorImageFilter.h" +#include "itkMeanImageFilter.h" +#include "otbMultiToMonoChannelExtractROI.h" +#include "otbMultiChannelExtractROI.h" +#include "otbMultiChannelRAndNIRIndexImageFilter.h" +#include "otbVegetationIndicesFunctor.h" + +int main(int argc, char* argv[]) +{ + const char * inputName = argv[1]; + const char * outputName = argv[2]; + const unsigned int radius = atoi(argv[3]); + const unsigned int id = atoi(argv[4]); + const unsigned int size = atoi(argv[5]); + + typedef double PixelType; + typedef otb::Image<PixelType, 2> ImageType; + typedef otb::VectorImage<PixelType, 2> VectorImageType; + typedef otb::ImageFileReader<VectorImageType> ReaderType; + typedef otb::ImageFileWriter<VectorImageType> WriterType; + + typedef otb::ImageList<ImageType> ImageListType; + typedef otb::ImageListToVectorImageFilter<ImageListType, VectorImageType> ListToImageFilterType; + typedef otb::MultiToMonoChannelExtractROI<PixelType, PixelType> ExtractorFilterType; + typedef otb::MultiChannelExtractROI<PixelType, PixelType> MultiChannelExtractorFilterType; + typedef itk::MeanImageFilter<ImageType, ImageType> MeanFilterType; + typedef otb::Functor::NDVI<PixelType, PixelType, PixelType> NDVIFunctorType; + typedef otb::MultiChannelRAndNIRIndexImageFilter<VectorImageType, ImageType, NDVIFunctorType> NDVIFilterType; + + ReaderType::Pointer reader = ReaderType::New(); + WriterType::Pointer writer = WriterType::New(); + ImageListType::Pointer imListOut = ImageListType::New(); + ExtractorFilterType::Pointer extract = ExtractorFilterType::New(); + MultiChannelExtractorFilterType::Pointer MCExtract = MultiChannelExtractorFilterType::New(); + MeanFilterType::Pointer meanner = MeanFilterType::New(); + NDVIFilterType::Pointer ndvi = NDVIFilterType::New(); + ListToImageFilterType::Pointer caster = ListToImageFilterType::New(); + + reader->SetFileName(inputName); + reader->GenerateOutputInformation(); + + ImageType::RegionType region; + ImageType::SizeType extSize; + ImageType::IndexType extId; + extSize.Fill(size); + extId.Fill(id); + region.SetSize(extSize); + region.SetIndex(extId); + MCExtract->SetInput(reader->GetOutput()); + MCExtract->SetExtractionRegion(region); + MCExtract->UpdateOutputInformation(); + + extract->SetInput(MCExtract->GetOutput()); + extract->SetChannel(1); + extract->UpdateOutputInformation(); + + ImageType::SizeType rad; + rad[0] = radius; + rad[1] = radius; + meanner->SetInput(extract->GetOutput()); + meanner->SetRadius(rad); + + ndvi->SetInput(MCExtract->GetOutput()); + + imListOut->PushBack(meanner->GetOutput()); + imListOut->PushBack(ndvi->GetOutput()); + + caster->SetInput(imListOut); + writer->SetInput(caster->GetOutput()); + writer->SetFileName(outputName); + writer->Update(); + + /*** With 2 writers : OK */ + /* + typedef otb::ImageFileWriter<ImageType> WriterMonoType; + WriterMonoType::Pointer w1 = WriterMonoType::New(); + WriterMonoType::Pointer w2 = WriterMonoType::New(); + w1->SetInput( imListOut->GetNthElement(0) ); + w2->SetInput( imListOut->GetNthElement(1) ); + w1->SetFileName("meaner.tif"); + w2->SetFileName("ndvi.tif"); + w1->Update(); + w2->Update(); + */ + + return EXIT_SUCCESS; +} diff --git a/Testing/Fa/AlignementsQB.cxx b/Testing/Fa/AlignementsQB.cxx new file mode 100644 index 0000000000000000000000000000000000000000..cf0f607a9def2e50242f193c57ccc52693f66027 --- /dev/null +++ b/Testing/Fa/AlignementsQB.cxx @@ -0,0 +1,140 @@ +/*========================================================================= + + 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 <iostream> +#include "itkPolyLineParametricPath.h" + +#include "otbImage.h" +#include "otbImageFileWriter.h" +#include "otbImageFileReader.h" +#include "otbExtractROI.h" +#include "otbImageToPathListAlignFilter.h" +#include "otbDrawPathFilter.h" +//#include "otbColorImageViewer.h" + +#include <stdio.h> + +int main(int argc, char ** argv) +{ + if (argc != 3) + { + + std::cout << "Usage : " << argv[0] << " inputImage outputImage" << std::endl; + return 1; + + } + + const char * inputFilename = argv[1]; + const char * outputFilename = argv[2]; + + typedef unsigned char InputPixelType; + typedef unsigned char OutputPixelType; + + const unsigned int Dimension = 2; + + typedef otb::Image<InputPixelType, Dimension> InputImageType; + typedef otb::Image<OutputPixelType, Dimension> OutputImageType; + + typedef otb::ImageFileReader<InputImageType> ReaderType; + typedef otb::ImageFileWriter<OutputImageType> WriterType; + + ReaderType::Pointer reader = ReaderType::New(); + WriterType::Pointer writer = WriterType::New(); + + reader->SetFileName(inputFilename); + writer->SetFileName(outputFilename); + + reader->Update(); + + std::cout << "Lecture terminee" << std::endl; + + typedef otb::ExtractROI<InputPixelType, InputPixelType> ROIFilterType; + + ROIFilterType::Pointer roiFilter = ROIFilterType::New(); + + roiFilter->SetInput(reader->GetOutput()); + roiFilter->SetStartX(10); + roiFilter->SetStartY(0); + roiFilter->SetSizeX(256); + roiFilter->SetSizeY(256); + + roiFilter->Update(); + + std::cout << "Extraction ROI" << std::endl; + + typedef itk::PolyLineParametricPath<Dimension> PathType; + typedef otb::ImageToPathListAlignFilter<InputImageType, PathType> ListAlignFilterType; + + ListAlignFilterType::Pointer alignFilter = ListAlignFilterType::New(); + + alignFilter->SetInput(roiFilter->GetOutput()); + + alignFilter->Update(); + + std::cout << "Alignements termines" << std::endl; + + typedef ROIFilterType::OutputImageType BackgroundImageType; + + typedef otb::DrawPathFilter<BackgroundImageType, PathType, OutputImageType> DrawPathFilterType; + + DrawPathFilterType::Pointer drawPathFilter = DrawPathFilterType::New(); + + typedef ListAlignFilterType::OutputPathListType ListType; + + ListType* listePaths = alignFilter->GetOutput(); + + ListType::Iterator listIt = listePaths->Begin(); + + BackgroundImageType::Pointer backgroundImage = roiFilter->GetOutput(); + + roiFilter->Update(); + + unsigned int color = 0; + + while (listIt != listePaths->End()) + { + + drawPathFilter->SetImageInput(backgroundImage); + drawPathFilter->SetInputPath(listIt.Get()); + //drawPathFilter->SetPathValue( color ); + + drawPathFilter->Update(); + + backgroundImage = drawPathFilter->GetOutput(); + + ++listIt; + ++color; + + } + + writer->SetInput(drawPathFilter->GetOutput()); + + writer->Update(); + +/* typedef otb::ColorImageViewer<unsigned char, double> ViewerType; + ViewerType viewer; + + viewer.SetLabel( "Input Image" ); + viewer.SetImage( drawPathFilter->GetOutput() ); + + viewer.Show(); + Fl::run(); +*/ + + return EXIT_SUCCESS; +} diff --git a/Testing/Fa/MapActivation.cxx b/Testing/Fa/MapActivation.cxx new file mode 100644 index 0000000000000000000000000000000000000000..480a543d9a8b9a22f29006646e5ded7d7c223b2e --- /dev/null +++ b/Testing/Fa/MapActivation.cxx @@ -0,0 +1,194 @@ +/*========================================================================= + + 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 <iostream> +#include <fstream> +#include "otbVectorImage.h" +#include "otbSOMMap.h" +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "itkImageRegionIterator.h" +#include "otbImage.h" + +#include "otbSOMMap.h" +#include "otbSOM.h" +#include "otbSOMActivationBuilder.h" +#include "itkVectorExpandImageFilter.h" +#include "itkVectorNearestNeighborInterpolateImageFunction.h" + +#include "itkExpandImageFilter.h" +#include "itkNearestNeighborInterpolateImageFunction.h" + +#include "itkListSample.h" + +#include "otbSOMClassifier.h" +#include "itkVariableLengthVector.h" +#include "itkMembershipSample.h" + +int main(int argc, char* argv[]) +{ + + if (argc < 12) + { + std::cout << "Usage : " << argv[0] << + " inputTabImage size radius NumberOfIterations BetaInit BetaEnd MaxWeight MinWeight som actMap som" << std::endl; + + return EXIT_FAILURE; + } + + typedef otb::Image<double, 2> ListImageType; + + typedef otb::ImageFileReader<ListImageType> TabReaderType; + TabReaderType::Pointer Tabreader = TabReaderType::New(); + Tabreader->SetFileName(argv[1]); + Tabreader->Update(); + ListImageType::Pointer tabreadImage = Tabreader->GetOutput(); + + typedef itk::ImageRegionIterator<ListImageType> IteratorType; + IteratorType It1(tabreadImage, tabreadImage->GetLargestPossibleRegion()); + const int nblines = 591; //const int)(tabreadImage->GetLargestPossibleRegion().GetSize()[1]); + + const int nbcolonnes = 9; //(const int)tabreadImage->GetLargestPossibleRegion().GetSize()[0]; + + double vectTab[nblines][nbcolonnes]; + std::cout << "lignes = " << nblines << " colonnes = " << nbcolonnes << std::endl; + for (It1.GoToBegin(); !It1.IsAtEnd(); ++It1) + { + vectTab[It1.GetIndex()[1]][It1.GetIndex()[0]] = It1.Get(); + } + + typedef itk::VariableLengthVector<double> MeasurementVectorType; + typedef itk::Statistics::ListSample<MeasurementVectorType> SampleType; + SampleType::Pointer liste = SampleType::New(); + + for (int j = 0; j < nblines; ++j) + { + MeasurementVectorType tab; + tab.SetSize(nbcolonnes); + for (int i = 0; i < nbcolonnes; ++i) + { + tab[i] = vectTab[j][i]; + } + liste->PushBack(tab); + } + // std::cout<<"liste: "<<liste->GetMeasurementVectorSize()<< " " << liste->GetMeasurementVector(1) + // <<" " <<liste->GetMeasurementVector(2)<< " " <<liste->GetMeasurementVector(3)<<std::endl; + + typedef itk::Statistics::EuclideanDistance<MeasurementVectorType> DistanceType; + typedef otb::SOMMap<MeasurementVectorType, DistanceType, 2> MapType; + + typedef otb::SOM<SampleType, MapType> SOMType; + SOMType::Pointer som = SOMType::New(); + som->SetListSample(liste); + SOMType::SizeType som_size; + som_size[0] = atoi(argv[2]); + som_size[1] = atoi(argv[2]); + som->SetMapSize(som_size); + SOMType::SizeType radius; + radius[0] = atoi(argv[3]); + radius[1] = atoi(argv[3]); + som->SetNeighborhoodSizeInit(radius); + + som->SetNumberOfIterations(atoi(argv[4])); + som->SetBetaInit(atoi(argv[5])); + som->SetBetaEnd(atoi(argv[6])); + som->SetMaxWeight(atoi(argv[7])); + som->SetMinWeight(atoi(argv[8])); + som->Update(); + + typedef otb::ImageFileWriter<MapType> SomWriterType; + SomWriterType::Pointer somwriter = SomWriterType::New(); + somwriter->SetFileName(argv[9] /*"som.hd"*/); + somwriter->SetInput(som->GetOutput()); + somwriter->Update(); + + typedef unsigned char OutputPixelType; + + typedef otb::Image<OutputPixelType, 2> OutputImageType; + typedef otb::ImageFileWriter<OutputImageType> ActivationWriterType; + typedef otb::SOMActivationBuilder<SampleType, MapType, OutputImageType> SOMActivationBuilderType; + SOMActivationBuilderType::Pointer somAct = SOMActivationBuilderType::New(); + somAct->SetInput(som->GetOutput()); + somAct->SetListSample(liste); + + ActivationWriterType::Pointer actWriter = ActivationWriterType::New(); + actWriter->SetFileName(argv[10] /*"actMap.png"*/); + actWriter->SetInput(somAct->GetOutput()); + actWriter->Update(); + + //Classifier : + + typedef otb::ImageFileReader<MapType> SOMReaderType; + typedef otb::SOMClassifier<SampleType, MapType, unsigned char> ClassifierType; + + SOMReaderType::Pointer somreader = SOMReaderType::New(); + somreader->SetFileName(argv[11] /*"som.mhd"*/); + somreader->Update(); + + ClassifierType::Pointer classifier = ClassifierType::New(); + + classifier->SetSample(liste); + classifier->SetMap(somreader->GetOutput()); + classifier->Update(); + + ClassifierType::OutputType* membershipSample = classifier->GetOutput(); + // std::cout<<"liste: "<<membershipSample->GetMeasurementVectorSize()<< " " << membershipSample->GetMeasurementVector(1)<<std::endl; + + ClassifierType::OutputType::ConstIterator m_iter = membershipSample->Begin(); + ClassifierType::OutputType::ConstIterator m_last = membershipSample->End(); + + /*int count[16]; + for(int i=0; i<16; ++i) + { + count[i]=0; + } + */ + while (m_iter != m_last) + { +// std::cout<<" classlabel : "<<m_iter.GetClassLabel()<< +// " ClassSize= "<< membershipSample->GetClassSampleSize(m_iter.GetClassLabel()) << +// " instance id = " << m_iter.GetInstanceIdentifier() << +// " measurement vector = " << m_iter.GetMeasurementVector() << +// +// " class sample: "<< membershipSample->GetClassSample(m_iter.GetClassLabel())<< +// std::endl; + //count[m_iter.GetClassLabel()]++; + ++m_iter; + } + + /*for(int i=0; i<16; ++i) + { + std::cout<<" classe: "<< i <<" nb elements= "<<count[i]<<std::endl; + }*/ + + int nbclass = membershipSample->GetNumberOfClasses(); + std::cout << " nb of classes= " << nbclass << std::endl; + + for (int i = 0; i < nbclass; ++i) + { + if (membershipSample->GetInternalClassLabel(i) != -1) + { + std::cout << "classlabel= " << i << " classSize= " << membershipSample->GetClassSampleSize(i) << std::endl; + } + } + + return EXIT_SUCCESS; +} diff --git a/Testing/Fa/PolygonsVectorization.cxx b/Testing/Fa/PolygonsVectorization.cxx new file mode 100644 index 0000000000000000000000000000000000000000..f9241cf82abdef8cbf160d75d46a36727916dda4 --- /dev/null +++ b/Testing/Fa/PolygonsVectorization.cxx @@ -0,0 +1,314 @@ +/*========================================================================= + + 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 "itkMacro.h" +#include "otbCommandLineArgumentParser.h" + +#include "otbImage.h" +#include "otbVectorImage.h" +#include "itkImageRegion.h" + +#include "otbPolygon.h" +#include "otbObjectList.h" +#include "otbPersistentVectorizationImageFilter.h" +#include "itkRelabelComponentImageFilter.h" +#include "itkConnectedComponentImageFilter.h" +#include "itkRescaleIntensityImageFilter.h" + +/* +#include "itkBinaryErodeImageFilter.h" +#include "itkBinaryDilateImageFilter.h" +#include "itkBinaryBallStructuringElement.h" +//#include "itkBinaryMorphologicalClosingImageFilter.h" +//#include "itkBinaryMorphologicalOpeningImageFilter.h" +#include "itkMedianImageFilter.h" +#include "otbRemoveObjectPreprocessingImageFilter.h" +*/ + +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "otbStreamingImageFileWriter.h" + +#include "otbStandardWriterWatcher.h" +#include "otbStandardFilterWatcher.h" + +int main(int argc, char * argv[]) +{ + + typedef unsigned char PixelType; + typedef unsigned long LabelPixelType; + typedef unsigned char PixelTypeOutput; + + typedef otb::Image<PixelType, 2> SingleImageType; + typedef otb::Image<LabelPixelType, 2> LabeledImageType; + typedef otb::Image<PixelTypeOutput, 2> OutputImageType; + + typedef itk::ImageRegionIterator<LabeledImageType> IteratorType; + + typedef otb::Polygon<double> PolygonType; + typedef PolygonType::Pointer PolygonPointerType; + typedef PolygonType::ContinuousIndexType PolygonIndexType; + typedef otb::ObjectList<PolygonType> PolygonListType; + typedef PolygonListType::Pointer PolygonListPointerType; + typedef itk::ImageRegion<2> ImageRegionType; + + typedef otb::PersistentVectorizationImageFilter<LabeledImageType, PolygonType> PersistentVectorizationFilterType; + typedef itk::RelabelComponentImageFilter<LabeledImageType, LabeledImageType> RelabelFilterType; + typedef itk::ConnectedComponentImageFilter<LabeledImageType, LabeledImageType> ConnectedFilterType; + typedef itk::RescaleIntensityImageFilter<LabeledImageType, OutputImageType> RescalerType; +/* + typedef itk::BinaryBallStructuringElement< LabelPixelType, 2 > StructuringElementType; + typedef itk::BinaryErodeImageFilter<LabeledImageType, LabeledImageType, StructuringElementType> ErodeFilterType; + typedef itk::BinaryDilateImageFilter<LabeledImageType, LabeledImageType, StructuringElementType> DilateFilterType; + typedef itk::MedianImageFilter<LabeledImageType, LabeledImageType> MedianFilterType; + typedef otb::RemoveObjectPreprocessingImageFilter<LabeledImageType> PreprocessingFilterType; +*/ + typedef otb::ImageFileReader<LabeledImageType> ReaderType; + typedef otb::ImageFileWriter<OutputImageType> WriterType; + + //----------------------------------------------------------------- + //Command Line Argument Parser + try + { + typedef otb::CommandLineArgumentParser ParserType; + ParserType::Pointer parser = ParserType::New(); + + parser->SetProgramDescription("This program remove small objects"); + parser->AddInputImage(); + parser->AddOutputImage(); + parser->AddOption("--surface", "objects surface limit. Default is 100", "-s", 1, false); + parser->AddOption("--outputText", "output text file name", "-ot", 1, false); + + typedef otb::CommandLineArgumentParseResult ParserResultType; + ParserResultType::Pointer parseResult = ParserResultType::New(); + + try + { + parser->ParseCommandLine(argc, argv, parseResult); + } + catch (itk::ExceptionObject& err) + { + std::string descriptionException = err.GetDescription(); + if (descriptionException.find("ParseCommandLine(): Help Parser") + != std::string::npos) + { + return EXIT_SUCCESS; + } + if (descriptionException.find("ParseCommandLine(): Version Parser") + != std::string::npos) + { + return EXIT_SUCCESS; + } + return EXIT_FAILURE; + } + + //object under this value will be removed + double surfaceLimit; + if (parseResult->IsOptionPresent("--surface")) surfaceLimit = parseResult->GetParameterDouble("--surface"); + else surfaceLimit = 100; + + //----------------------------------------------------------------- + //read image + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(parseResult->GetInputImage().c_str()); + reader->UpdateOutputInformation(); + + /////////////////////////////////////////////////////////////////// + // Object Processing + /////////////////////////////////////////////////////////////////// + + //----------------------------------------------------------------- + //Label the objects in a binary image + ConnectedFilterType::Pointer connectedFilter = ConnectedFilterType::New(); + connectedFilter->SetInput(reader->GetOutput()); + + //----------------------------------------------------------------- + //Perform vectorization in a persistent way + PersistentVectorizationFilterType::Pointer persistentVectorization = PersistentVectorizationFilterType::New(); + persistentVectorization->Reset(); + persistentVectorization->SetInput(connectedFilter->GetOutput()); + try + { + persistentVectorization->Update(); + } + catch (itk::ExceptionObject& err) + { + std::cout << "\nExceptionObject caught !" << std::endl; + std::cout << err << std::endl; + return EXIT_FAILURE; + } + + PolygonListPointerType OutputPolyList = persistentVectorization->GetPathList(); + + //Display results + std::cout << "nb objects found = " << OutputPolyList->Size() << std::endl; + + //------------------- + //DEBUG + //------------------- + unsigned int polygon = 0; + std::ofstream file; + if (parseResult->IsOptionPresent("--outputText")) + { + file.open(parseResult->GetParameterString("--outputText").c_str()); + } + + double minSize = -1; + //Initializing the minSize + if (OutputPolyList->Size() > 0) + { + minSize = OutputPolyList->GetNthElement(0)->GetArea(); + } + + while (polygon < OutputPolyList->Size()) + { + ImageRegionType polygonRegion = OutputPolyList->GetNthElement(polygon)->GetBoundingRegion().GetImageRegion(); + if (OutputPolyList->GetNthElement(polygon)->GetArea() < minSize) + { + minSize = OutputPolyList->GetNthElement(polygon)->GetArea(); + } + if (parseResult->IsOptionPresent("--outputText")) + { + file << "polygon " << polygon << "\tnPoints=" + << OutputPolyList->GetNthElement(polygon)->GetVertexList()->Size() << "\tsurface=" + << OutputPolyList->GetNthElement(polygon)->GetArea() << "\tlength=" + << OutputPolyList->GetNthElement(polygon)->GetLength() << "\tregion size=" + << polygonRegion.GetSize() << "\tregion nb pixel=" + << polygonRegion.GetNumberOfPixels() << std::endl; +// file << OutputPolyList->GetNthElement(polygon)<< std::endl << std::endl; + } + else + { + std::cout << "polygon " << polygon << "\tnPoints=" + << OutputPolyList->GetNthElement(polygon)->GetVertexList()->Size() << "\tsurface=" + << OutputPolyList->GetNthElement(polygon)->GetArea() << "\tlength=" + << OutputPolyList->GetNthElement(polygon)->GetLength() << "\tregion size=" + << polygonRegion.GetSize() << "\tregion nb pixel=" + << polygonRegion.GetNumberOfPixels() << std::endl; +// std::cout << OutputPolyList->GetNthElement(polygon)<< std::endl << std::endl; + } + polygon++; + } + if (parseResult->IsOptionPresent("--outputText")) + { + file.close(); + } + //------------------- + // END DEBUG + //------------------- + + //----------------------------------------------------------------- + //erase object + unsigned int i = 0; + std::cout << "erase ..." << std::endl; + while (i < OutputPolyList->Size()) + { + if ((OutputPolyList->GetNthElement(i)->GetArea() > surfaceLimit) //delete big polygon + || (OutputPolyList->GetNthElement(i)->GetArea() == 0)) //delete invalid polygon + OutputPolyList->Erase(i); + else ++i; + } + + //Display results after erasure + std::cout << "nb objects found = " << OutputPolyList->Size() << std::endl; + std::cout << "------------------------------------------------" << std::endl; + + /////////////////////////////////////////////////////////////////// + // Output Image Writing + /////////////////////////////////////////////////////////////////// + + //----------------------------------------------------------------- + //allocate the memory for the output file + LabeledImageType::Pointer outputImage = LabeledImageType::New(); + outputImage->SetRegions(reader->GetOutput()->GetRequestedRegion()); + outputImage->CopyInformation(reader->GetOutput()); + outputImage->Allocate(); + // copy input + IteratorType iit(reader->GetOutput(), reader->GetOutput()->GetRequestedRegion()); + IteratorType oit(outputImage, outputImage->GetRequestedRegion()); + + for (iit.GoToBegin(), oit.GoToBegin(); !iit.IsAtEnd(); ++iit, ++oit) + oit.Set(iit.Get()); + + // erase small polygon + for (unsigned int i = 0; i < OutputPolyList->Size(); ++i) + { + std::cout << "polygon " << i << std::endl; + ImageRegionType polygonRegion = OutputPolyList->GetNthElement(i)->GetBoundingRegion().GetImageRegion(); + + IteratorType outputIt(outputImage, polygonRegion); + + outputIt.GoToBegin(); + while (!outputIt.IsAtEnd()) + { + outputIt.Set(0); + ++outputIt; + } + + } + + //----------------------------------------------------------------- + //rescale image + RescalerType::Pointer rescaler = RescalerType::New(); + rescaler->SetOutputMinimum(0); + rescaler->SetOutputMaximum(255); + rescaler->SetInput(outputImage); + rescaler->Update(); + + //----------------------------------------------------------------- + //write image + WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(parseResult->GetOutputImage().c_str()); + writer->SetInput(rescaler->GetOutput()); + + try + { + otb::StandardWriterWatcher watcher(writer, "Remove small object"); + writer->Update(); + } + catch (itk::ExceptionObject& err) + { + std::cout << "ExceptionObject caught !" << std::endl; + std::cout << err << std::endl; + return EXIT_FAILURE; + } + + if (minSize == 0) + { + return EXIT_FAILURE; + } + + } //end block try global + catch (itk::ExceptionObject& err) + { + std::cout << "Following otbException catch :" << std::endl; + std::cout << err << std::endl; + return EXIT_FAILURE; + } + catch (std::bad_alloc& err) + { + std::cout << "Exception bad_alloc : " << (char*) err.what() << std::endl; + return EXIT_FAILURE; + } + catch (...) + { + std::cout << "Unknown Exception found !" << std::endl; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} diff --git a/Testing/Fa/SensorModelBorder.cxx b/Testing/Fa/SensorModelBorder.cxx new file mode 100644 index 0000000000000000000000000000000000000000..a8261ba56529128a219a10ec611a1614404c24a5 --- /dev/null +++ b/Testing/Fa/SensorModelBorder.cxx @@ -0,0 +1,239 @@ +/*========================================================================= + + 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 <iomanip> +#include <iostream> + +#include "otbVectorImage.h" +#include "otbImageFileReader.h" +#include "otbForwardSensorModel.h" +#include "otbInverseSensorModel.h" + +// Exercise the Spot5 sensor model on the image border +int main(int argc, char* argv[]) +{ + if (argc != 3) + { + std::cout << argv[0] << " <input filename> <output filename>" << std::endl; + + return EXIT_FAILURE; + } + + char * filename = argv[1]; + char* outFilename = argv[2]; + + + typedef otb::VectorImage<double, 2> ImageType; + typedef otb::ImageFileReader<ImageType> ReaderType; + + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(filename); + reader->UpdateOutputInformation(); + + ImageType::Pointer image = reader->GetOutput(); + ImageType::RegionType region = image->GetLargestPossibleRegion(); + + typedef otb::ForwardSensorModel<double> ForwardSensorModelType; + ForwardSensorModelType::Pointer forwardSensorModel = ForwardSensorModelType::New(); + forwardSensorModel->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist()); + if (forwardSensorModel->IsValidSensorModel() == false) + { + std::cout << "Invalid Model pointer m_Model == NULL!\n The ossim keywordlist is invalid!" << std::endl; + return EXIT_FAILURE; + } + forwardSensorModel->SetAverageElevation(16.19688987731934); + + typedef otb::InverseSensorModel<double> InverseSensorModelType; + InverseSensorModelType::Pointer inverseSensorModel = InverseSensorModelType::New(); + inverseSensorModel->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist()); + if (inverseSensorModel->IsValidSensorModel() == false) + { + std::cout << "Invalid Model pointer m_Model == NULL!\n The ossim keywordlist is invalid!" << std::endl; + return EXIT_FAILURE; + } + inverseSensorModel->SetAverageElevation(16.19688987731934); + + const int radius = 10; + const double gridstep = 0.1; + + itk::Point<double, 2> imagePoint; + + // Test upper left corner + std::cout << " --- upper left corner ---" << std::endl; + for (imagePoint[0] = region.GetIndex(0) - radius; imagePoint[0] < region.GetIndex(0) + radius; imagePoint[0] += gridstep) + { + + for (imagePoint[1] = region.GetIndex(1) - radius; imagePoint[1] < region.GetIndex(1) + radius; imagePoint[1] += gridstep) + { + + itk::Point<double, 2> geoPoint; + geoPoint = forwardSensorModel->TransformPoint(imagePoint); + std::cout << "Image to geo: " << imagePoint << " -> " << geoPoint << "\n"; + + if (vnl_math_isnan(geoPoint[0]) || vnl_math_isnan(geoPoint[1])) + { + return EXIT_FAILURE; + } + + itk::Point<double, 2> reversedImagePoint; + reversedImagePoint = inverseSensorModel->TransformPoint(geoPoint); + + std::cout << "Geo to image: " << geoPoint << " -> " << reversedImagePoint << "\n"; + + if (vnl_math_isnan(reversedImagePoint[0]) || vnl_math_isnan(reversedImagePoint[1])) + { + return EXIT_FAILURE; + } + } + } + + // Test lower left corner + std::cout << " --- lower left corner ---" << std::endl; + for (imagePoint[0] = region.GetIndex(0) - radius; imagePoint[0] < region.GetIndex(0) + radius; imagePoint[0] += gridstep) + { + for (imagePoint[1] = region.GetIndex(1) + region.GetSize(1) - radius; imagePoint[1] < region.GetIndex(1) + region.GetSize(1) + radius; imagePoint[1] += gridstep) + { + + itk::Point<double, 2> geoPoint; + geoPoint = forwardSensorModel->TransformPoint(imagePoint); + std::cout << "Image to geo: " << imagePoint << " -> " << geoPoint << "\n"; + + if (vnl_math_isnan(geoPoint[0]) || vnl_math_isnan(geoPoint[1])) + { + return EXIT_FAILURE; + } + + itk::Point<double, 2> reversedImagePoint; + reversedImagePoint = inverseSensorModel->TransformPoint(geoPoint); + + std::cout << "Geo to image: " << geoPoint << " -> " << reversedImagePoint << "\n"; + + if (vnl_math_isnan(reversedImagePoint[0]) || vnl_math_isnan(reversedImagePoint[1])) + { + return EXIT_FAILURE; + } + } + } + + // Test lower right corner + std::cout << " --- lower right corner ---" << std::endl; + for (imagePoint[0] = region.GetIndex(0) + region.GetSize(0) - radius; imagePoint[0] < region.GetIndex(0) + region.GetSize(0) + radius; imagePoint[0] += gridstep) + { + for (imagePoint[1] = region.GetIndex(1) + region.GetSize(1) - radius; imagePoint[1] < region.GetIndex(1) + region.GetSize(1) + radius; imagePoint[1] += gridstep) + { + + itk::Point<double, 2> geoPoint; + geoPoint = forwardSensorModel->TransformPoint(imagePoint); + std::cout << "Image to geo: " << imagePoint << " -> " << geoPoint << "\n"; + + if (vnl_math_isnan(geoPoint[0]) || vnl_math_isnan(geoPoint[1])) + { + return EXIT_FAILURE; + } + + itk::Point<double, 2> reversedImagePoint; + reversedImagePoint = inverseSensorModel->TransformPoint(geoPoint); + + std::cout << "Geo to image: " << geoPoint << " -> " << reversedImagePoint << "\n"; + + if (vnl_math_isnan(reversedImagePoint[0]) || vnl_math_isnan(reversedImagePoint[1])) + { + return EXIT_FAILURE; + } + } + } + + // Test upper right corner + std::cout << " --- upper right corner ---" << std::endl; + for (imagePoint[0] = region.GetIndex(0) + region.GetSize(0) - radius; imagePoint[0] < region.GetIndex(0) + region.GetSize(0) + radius; imagePoint[0] += gridstep) + { + for (imagePoint[1] = region.GetIndex(1) - radius; imagePoint[1] < region.GetIndex(1) + radius; imagePoint[1] += gridstep) + { + + itk::Point<double, 2> geoPoint; + geoPoint = forwardSensorModel->TransformPoint(imagePoint); + std::cout << "Image to geo: " << imagePoint << " -> " << geoPoint << "\n"; + + if (vnl_math_isnan(geoPoint[0]) || vnl_math_isnan(geoPoint[1])) + { + return EXIT_FAILURE; + } + + itk::Point<double, 2> reversedImagePoint; + reversedImagePoint = inverseSensorModel->TransformPoint(geoPoint); + + std::cout << "Geo to image: " << geoPoint << " -> " << reversedImagePoint << "\n"; + + if (vnl_math_isnan(reversedImagePoint[0]) || vnl_math_isnan(reversedImagePoint[1])) + { + return EXIT_FAILURE; + } + } + } + + + + // generat the output value along a segment crossing the lower image border + // at the center position + itk::Point<double, 2> imagePoint1; + imagePoint1[0] = region.GetIndex(0) + region.GetSize(0)/2; + imagePoint1[1] = region.GetIndex(1) + region.GetSize(1) - radius; + + itk::Point<double, 2> imagePoint2; + imagePoint2[0] = region.GetIndex(0) + region.GetSize(0)/2; + imagePoint2[1] = region.GetIndex(1) + region.GetSize(1) + radius; + + itk::Point<double, 2> geoPoint1, geoPoint2; + geoPoint1 = forwardSensorModel->TransformPoint(imagePoint1); + geoPoint2 = forwardSensorModel->TransformPoint(imagePoint2); + + itk::Vector<double, 2> geoDir; + geoDir[0] = geoPoint2[0] - geoPoint1[0]; + geoDir[1] = geoPoint2[1] - geoPoint1[1]; + + const int nbStep = 50; + itk::Vector<double, 2> geoStep = geoDir / nbStep; + + std::ofstream file; + file.open(outFilename); + + file << "# image_x image_y geo_x geo_y reversed_image_x reversed_image_y" << std::endl; + file << std::setprecision(15); + + for (int i = 0; i < nbStep; ++i) + { + itk::Point<double, 2> geoPoint; + geoPoint[0] = geoPoint1[0] + geoStep[0] * i; + geoPoint[1] = geoPoint1[1] + geoStep[1] * i; + + itk::Point<double, 2> reversedImagePoint; + reversedImagePoint = inverseSensorModel->TransformPoint(geoPoint); + + file << geoPoint[0] << "\t" << geoPoint[1] << "\t" + << reversedImagePoint[0] << "\t" << reversedImagePoint[1] << std::endl; + + if (vnl_math_isnan(geoPoint[0]) || vnl_math_isnan(geoPoint[1])) + { + return EXIT_FAILURE; + } + } + + file.close(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Fa/StreamingStat.cxx b/Testing/Fa/StreamingStat.cxx new file mode 100644 index 0000000000000000000000000000000000000000..68c8a5b7eaa8ce182cfd3b505b2765f8a971e9a0 --- /dev/null +++ b/Testing/Fa/StreamingStat.cxx @@ -0,0 +1,33 @@ +#include "otbImage.h" +#include "otbVectorImage.h" +#include "otbImageFileReader.h" +#include "otbStreamingStatisticsImageFilter.h" +#include "otbVectorImageTo3DScalarImageFilter.h" + +int main(int argc, char ** argv) +{ + + typedef otb::Image<double, 2> ImageType; + typedef otb::Image<double, 3> Image3DType; + typedef otb::VectorImage<double, 2> VectorImageType; + typedef otb::ImageFileReader<VectorImageType> ReaderType; + + ReaderType::Pointer reader1 = ReaderType::New(); + reader1->SetFileName(argv[1]); + + typedef otb::VectorImageTo3DScalarImageFilter<VectorImageType, Image3DType> + VectorImageTo3DScalarImageFilterType; + VectorImageTo3DScalarImageFilterType::Pointer filter1 = + VectorImageTo3DScalarImageFilterType::New(); + + typedef otb::StreamingStatisticsImageFilter<Image3DType> statFilterType; + statFilterType::Pointer statFilter = statFilterType::New(); + + filter1->SetInput(reader1->GetOutput()); +// filter1->Update(); + statFilter->SetInput(filter1->GetOutput()); + statFilter->Update(); + + std::cout << statFilter->GetMean() << std::endl; + +} diff --git a/Testing/Fa/WriteUnsignedLong.cxx b/Testing/Fa/WriteUnsignedLong.cxx new file mode 100644 index 0000000000000000000000000000000000000000..42fbed4d0c0d5049db282c393d2982ea98913a9f --- /dev/null +++ b/Testing/Fa/WriteUnsignedLong.cxx @@ -0,0 +1,89 @@ +/*========================================================================= + + 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 "otbImage.h" +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" + +//TODO change the bug tracker url +//http://bugs.orfeo-toolbox.org/view.php?id=406 + +int main(int argc, char *argv[]) +{ + char * filename = argv[1]; + + typedef unsigned long PixelType; + typedef otb::Image<PixelType, 2> ImageType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::ImageFileWriter<ImageType> WriterType; + + // check for input images + ImageType::Pointer image = ImageType::New(); + WriterType::Pointer writer = WriterType::New(); + ReaderType::Pointer reader = ReaderType::New(); + + ImageType::IndexType start; + + start[0] = 0; // first index on X + start[1] = 0; // first index on Y + + ImageType::SizeType size; + + size[0] = 10; // size along X + size[1] = 10; + + ImageType::RegionType region; + + region.SetSize(size); + region.SetIndex(start); + + image->SetRegions(region); + image->Allocate(); + + ImageType::PixelType initialValue = 0; + image->FillBuffer(initialValue); + + ImageType::IndexType pixelIndex; + + pixelIndex[0] = 1; // x position + pixelIndex[1] = 1; + + image->SetPixel(pixelIndex, initialValue + 1); + + writer->SetInput(image); + writer->SetFileName(filename); + writer->Update(); + + reader->SetFileName(filename); + reader->Update(); + + ImageType::RegionType outputRegion; + outputRegion = reader->GetOutput()->GetLargestPossibleRegion(); + + ImageType::SizeType outputSize; + outputSize = outputRegion.GetSize(); + + if (reader->GetOutput()->GetPixel(pixelIndex) != initialValue + 1 ) + { + return EXIT_FAILURE; + } + else + { + return EXIT_SUCCESS; + } +}