diff --git a/Code/BasicFilters/otbProlateInterpolateImageFunction.h b/Code/BasicFilters/otbProlateInterpolateImageFunction.h index cb7b750a492f11dcd239e77f966bd6d2a22fc2e1..17a0bc2ed0fd70d6a09fd0a31970a2287686f4ee 100644 --- a/Code/BasicFilters/otbProlateInterpolateImageFunction.h +++ b/Code/BasicFilters/otbProlateInterpolateImageFunction.h @@ -87,7 +87,9 @@ class ProlateFunction static const unsigned int m_OriginalProfileSize; /** Original prolate profil */ static const double m_OriginalProfile[721]; - + protected: + ProlateFunction(){ m_Radius = 1; }; + ~ProlateFunction(){}; }; }//namespace Function diff --git a/Code/Common/otbPolyLineParametricPathWithValue.txx b/Code/Common/otbPolyLineParametricPathWithValue.txx index ed4d60b6edabdce758cf29574a66e50b5bc0a51d..8724e8d56a7e1637b8b52a9a33024ca8f1d09883 100644 --- a/Code/Common/otbPolyLineParametricPathWithValue.txx +++ b/Code/Common/otbPolyLineParametricPathWithValue.txx @@ -81,6 +81,13 @@ namespace otb ::PrintSelf(std::ostream& os, itk::Indent indent) const { Superclass::PrintSelf(os, indent); + VertexListConstIteratorType it = this->GetVertexList()->Begin(); + while(it != this->GetVertexList()->End()) + { + os << it.Value() << " - "; + it++; + } + os << std::endl; } } // end namespace otb diff --git a/Code/DisparityMap/otbMIRegistrationFilter.h b/Code/DisparityMap/otbMIRegistrationFilter.h index cdae1331e8a841c2314445d0836cdad2735ec8be..3c05a37b502edc9849a4aa0705a6609084887342 100644 --- a/Code/DisparityMap/otbMIRegistrationFilter.h +++ b/Code/DisparityMap/otbMIRegistrationFilter.h @@ -127,6 +127,9 @@ protected: /** Apply update. */ virtual void ApplyUpdate(TimeStepType dt); + /** Update the Input requested region. */ + virtual void GenerateInputRequestedRegion(); + private: MIRegistrationFilter(const Self&); //purposely not implemented void operator=(const Self&); //purposely not implemented diff --git a/Code/DisparityMap/otbMIRegistrationFilter.txx b/Code/DisparityMap/otbMIRegistrationFilter.txx index c7459469bf863fdd4b043097c21e50f4a6d4d7e4..7b031702e907bf88ccf5da5d496ef7b3e7ce5eb2 100644 --- a/Code/DisparityMap/otbMIRegistrationFilter.txx +++ b/Code/DisparityMap/otbMIRegistrationFilter.txx @@ -15,9 +15,9 @@ PURPOSE. See the above copyright notices for more information. =========================================================================*/ - #ifndef __otbMIRegistrationFilter_txx #define __otbMIRegistrationFilter_txx + #include "otbMIRegistrationFilter.h" namespace otb { @@ -187,7 +187,73 @@ MIRegistrationFilter<TFixedImage,TMovingImage,TDeformationField> } - +template <class TFixedImage, class TMovingImage, class TDeformationField> +void +MIRegistrationFilter<TFixedImage,TMovingImage,TDeformationField> +::GenerateInputRequestedRegion() +{ + // get pointers to the input and output + typename Superclass::FixedImagePointer fixedPtr = + const_cast< TFixedImage * >( this->GetFixedImage() ); + typename Superclass::MovingImagePointer movingPtr = + const_cast< TMovingImage * >( this->GetMovingImage() ); + typename TDeformationField::Pointer outputPtr = this->GetOutput(); + + if ( !fixedPtr || !movingPtr || !outputPtr ) + { + return; + } + + // get a copy of the input requested region (should equal the output + // requested region) + typename TDeformationField::RegionType requestedRegion; + requestedRegion = outputPtr->GetRequestedRegion(); + + // pad the input requested region by the operator radius + requestedRegion.PadByRadius( this->GetMIRadius() ); + + // crop the input requested region at the input's largest possible region + if ( requestedRegion.Crop(fixedPtr->GetLargestPossibleRegion())) + { + if ( requestedRegion.Crop(movingPtr->GetLargestPossibleRegion())) + { + fixedPtr->SetRequestedRegion( requestedRegion ); + movingPtr->SetRequestedRegion( requestedRegion ); + return; + } + else + { + // Couldn't crop the region (requested region is outside the largest + // possible region). Throw an exception. + + // store what we tried to request (prior to trying to crop) + movingPtr->SetRequestedRegion( requestedRegion ); + + // build an exception + itk::InvalidRequestedRegionError e(__FILE__, __LINE__); + e.SetLocation(ITK_LOCATION); + e.SetDescription("Requested region is (at least partially) outside the largest possible region of the moving image."); + e.SetDataObject(movingPtr); + throw e; + + } + } + else + { + // Couldn't crop the region (requested region is outside the largest + // possible region). Throw an exception. + + // store what we tried to request (prior to trying to crop) + fixedPtr->SetRequestedRegion( requestedRegion ); + + // build an exception + itk::InvalidRequestedRegionError e(__FILE__, __LINE__); + e.SetLocation(ITK_LOCATION); + e.SetDescription("Requested region is (at least partially) outside the largest possible region of the fixed image."); + e.SetDataObject(fixedPtr); + throw e; + } +} } // end namespace otb diff --git a/Code/DisparityMap/otbStreamingWarpImageFilter.txx b/Code/DisparityMap/otbStreamingWarpImageFilter.txx index 8018205eeca0e7cd1a7132ecfb5db8250e987556..fc825a5efa42004d0532c9de026544f9da751c10 100644 --- a/Code/DisparityMap/otbStreamingWarpImageFilter.txx +++ b/Code/DisparityMap/otbStreamingWarpImageFilter.txx @@ -32,7 +32,6 @@ StreamingWarpImageFilter<TInputImage,TOutputImage,TDeformationField> ::StreamingWarpImageFilter() { // Fill the default maximum deformation - m_MaximumDeformation.SetSize(InputImageType::ImageDimension); m_MaximumDeformation.Fill(1); } diff --git a/Code/FeatureExtraction/otbLinkPathListFilter.h b/Code/FeatureExtraction/otbLinkPathListFilter.h index 63728f26461ab3b3bebbadb28e9d3837f5d0f0cc..ad5b512959a71c0b9478c48184911b3c0aa5b257 100644 --- a/Code/FeatureExtraction/otbLinkPathListFilter.h +++ b/Code/FeatureExtraction/otbLinkPathListFilter.h @@ -34,6 +34,11 @@ namespace otb * Please note that this filter may invert the order of the vertices in the newly created path. * * This filter is part of the road extraction framework. + * + * \sa ParallelLinePathListFilter + * + * \ingroup PathFilters + * */ template <class TPath> class ITK_EXPORT LinkPathListFilter diff --git a/Code/FeatureExtraction/otbParallelLinePathListFilter.h b/Code/FeatureExtraction/otbParallelLinePathListFilter.h index be647ad19702fe1d8a13b14c348b3a35caf0ddd2..7ec50024fede41741eda05217afa6f9087c77856 100644 --- a/Code/FeatureExtraction/otbParallelLinePathListFilter.h +++ b/Code/FeatureExtraction/otbParallelLinePathListFilter.h @@ -24,9 +24,26 @@ PURPOSE. See the above copyright notices for more information. namespace otb { /** \class ParallelLinePathListFilter - * \brief Description needed - * + * \brief otbParallelLinePathListFilter detects parallel lines in imagery. The required input data are a pathlist object. * + * The class consists of three basic functions that determine the angle between two lines, + * the distance between the lines and the common part of the lines. First, all input lines + * are checked if there is a second line running in the same direction. Thereafter, all line + * pairs that already fulfilled the angular criterion are checked whether they are close to + * each other or not, i.e. the orthogonal distance between them is calculated. Finally, it + * has to be verified if the two lines have a common part since lines may fulfil the two + * first criteria but be located in different parts of the image. In order to adapt the + * detection algorithm to the user’s needs, the thresholds AngularThreshold, DistanceThreshold + * and CommonDistanceThreshold can be set. + * + * A possible processing chain would be to extract lines with a line detector, to convert the + * result to pathlist objects, to link short line segments with the otbLinkPathListFilter to + * longer lines and to finally detect all parallel long lines. + * + * \sa LinkPathListFilter + * + * \ingroup PathFilters + * */ template <class TPath> class ITK_EXPORT ParallelLinePathListFilter diff --git a/Copyright/CSCopyright.txt b/Copyright/CSCopyright.txt new file mode 100644 index 0000000000000000000000000000000000000000..a2d3fae32c40dd106eaa184f2db58b8d9ee0be5e --- /dev/null +++ b/Copyright/CSCopyright.txt @@ -0,0 +1,23 @@ +Parts of the code have been developed by CS during internships and self-financed +studies. + +Copyright (c) CS Systemes d'Information + +This code has been contributed to the ORFEO Toolbox (OTB) under +the CeCILL licence version 2. See Licence_CeCILL_V2-en.txt or +http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt for more +details. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + diff --git a/Testing/Code/BasicFilters/otbProlateInterpolateImageFunction.cxx b/Testing/Code/BasicFilters/otbProlateInterpolateImageFunction.cxx index 7d5fd02ead2b915e34e327866954cc7141c88eaf..d3ba2e53d3ab92f6d2f98b77a23cf05ab7ed1a7c 100644 --- a/Testing/Code/BasicFilters/otbProlateInterpolateImageFunction.cxx +++ b/Testing/Code/BasicFilters/otbProlateInterpolateImageFunction.cxx @@ -124,136 +124,7 @@ int otbProlateInterpolateImageFunction(int argc, char * argv[]) itkcoswriter->SetFileName(itkcosfname); coswriter->Update(); itkcoswriter->Update(); - /* - unsigned int rad = 10; - - typedef otb::WindowedSincInterpolateImageGaussianFunction<ImageType> GaussInterpolatorType; - typedef otb::WindowedSincInterpolateImageHammingFunction<ImageType> HamInterpolatorType; - typedef otb::WindowedSincInterpolateImageCosineFunction<ImageType> CosInterpolatorType; - typedef itk::Function::HammingWindowFunction<10, double, double> itkHamType; - typedef itk::WindowedSincInterpolateImageFunction<ImageType, 10, itkHamType> itkHamInterpolatorType; - typedef itk::Function::CosineWindowFunction<10, double, double> itkCosType; - typedef itk::WindowedSincInterpolateImageFunction<ImageType, 10, itkCosType> itkCosInterpolatorType; - typedef itk::DifferenceImageFilter<ImageType, ImageType> DiffType; - */ - // Instantiating object - - /* - WriterType::Pointer gausswriter = WriterType::New(); - WriterType::Pointer hamwriter = WriterType::New(); - WriterType::Pointer coswriter = WriterType::New(); - WriterType::Pointer itkhamwriter = WriterType::New(); - WriterType::Pointer itkcoswriter = WriterType::New(); - WriterType::Pointer cosdiffwriter = WriterType::New(); - WriterType::Pointer hamdiffwriter = WriterType::New(); - */ - - /* - StreamingResampleImageFilterType::Pointer gaussresampler = StreamingResampleImageFilterType::New(); - StreamingResampleImageFilterType::Pointer hamresampler = StreamingResampleImageFilterType::New(); - StreamingResampleImageFilterType::Pointer cosresampler = StreamingResampleImageFilterType::New(); - StreamingResampleImageFilterType::Pointer itkhamresampler = StreamingResampleImageFilterType::New(); - StreamingResampleImageFilterType::Pointer itkcosresampler = StreamingResampleImageFilterType::New(); - DiffType::Pointer hamdiff = DiffType::New(); - DiffType::Pointer cosdiff = DiffType::New(); - */ - - - /* - HamInterpolatorType::Pointer ham = HamInterpolatorType::New(); - CosInterpolatorType::Pointer cos = CosInterpolatorType::New(); - itkHamInterpolatorType::Pointer itkham = itkHamInterpolatorType::New(); - itkCosInterpolatorType::Pointer itkcos = itkCosInterpolatorType::New(); - GaussInterpolatorType::Pointer gauss = GaussInterpolatorType::New(); - */ - - //proresampler->SetInterpolatorNeighborhoodRadius(rad); - /* - gaussresampler->SetInput(reader->GetOutput()); - gauss->SetRadius(rad); - gaussresampler->SetInterpolator(gauss); - //gaussresampler->SetInterpolatorNeighborhoodRadius(rad); - - hamresampler->SetInput(reader->GetOutput()); - ham->SetRadius(rad); - hamresampler->SetInterpolator(ham); - //hamresampler->SetInterpolatorNeighborhoodRadius(rad); - - cosresampler->SetInput(reader->GetOutput()); - cos->SetRadius(rad); - cosresampler->SetInterpolator(cos); - //cosresampler->SetInterpolatorNeighborhoodRadius(30); - - itkhamresampler->SetInput(reader->GetOutput()); - itkhamresampler->SetInterpolator(itkham); - //itkhamresampler->SetInterpolatorNeighborhoodRadius(rad); - - itkcosresampler->SetInput(reader->GetOutput()); - itkcosresampler->SetInterpolator(itkcos); - //itkcosresampler->SetInterpolatorNeighborhoodRadius(30); - */ - // Size of output resampler result - - /* - gaussresampler->SetSize(size); - gaussresampler->SetOutputSpacing(tutu); - - hamresampler->SetSize(size); - hamresampler->SetOutputSpacing(tutu); - - cosresampler->SetSize(size); - cosresampler->SetOutputSpacing(tutu); - - itkhamresampler->SetSize(size); - itkhamresampler->SetOutputSpacing(tutu); - - itkcosresampler->SetSize(size); - itkcosresampler->SetOutputSpacing(tutu); - */ - /* - gausswriter->SetInput(gaussresampler->GetOutput()); - //gausswriter->SetNumberOfStreamDivisions(1); - gausswriter->SetFileName("gaussresample.tif"); - - hamwriter->SetInput(hamresampler->GetOutput()); - //hamwriter->SetNumberOfStreamDivisions(1); - hamwriter->SetFileName("hamresample.tif"); - - coswriter->SetInput(cosresampler->GetOutput()); - //coswriter->SetNumberOfStreamDivisions(1); - coswriter->SetFileName("cosresample.tif"); - - itkhamwriter->SetInput(itkhamresampler->GetOutput()); - //itkhamwriter->SetNumberOfStreamDivisions(1); - itkhamwriter->SetFileName("itkhamresample.tif"); - - itkcoswriter->SetInput(itkcosresampler->GetOutput()); - //itkcoswriter->SetNumberOfStreamDivisions(1); - itkcoswriter->SetFileName("itkcosresample.tif"); - - gausswriter->Update(); - hamwriter->Update(); - coswriter->Update(); - itkhamwriter->Update(); - itkcoswriter->Update(); - - cosdiff->SetInput(0, cosresampler->GetOutput()); - cosdiff->SetInput(1, itkcosresampler->GetOutput()); - //cosdiffwriter->SetNumberOfStreamDivisions(1); - cosdiffwriter->SetFileName("cosdiff.tif"); - cosdiffwriter->SetInput(cosdiff->GetOutput()); - - hamdiff->SetInput(0, hamresampler->GetOutput()); - hamdiff->SetInput(1, itkhamresampler->GetOutput()); - //hamdiffwriter->SetNumberOfStreamDivisions(1); - hamdiffwriter->SetFileName("hamdiff.tif"); - hamdiffwriter->SetInput(hamdiff->GetOutput()); - - cosdiffwriter->Update(); - hamdiffwriter->Update(); - */ - return EXIT_SUCCESS; } diff --git a/Testing/Code/BasicFilters/otbProlateValidationTest.cxx b/Testing/Code/BasicFilters/otbProlateValidationTest.cxx index 5d4e30ccfcc43a27db27fc07954fdfb8bf29979d..706f39248aa6e1f1685561a0f0e3eccfcbdfee5c 100644 --- a/Testing/Code/BasicFilters/otbProlateValidationTest.cxx +++ b/Testing/Code/BasicFilters/otbProlateValidationTest.cxx @@ -67,14 +67,6 @@ int otbProlateValidationTest(int argc, char * argv[]) std::cout<<"Radius : "<<prolate->GetRadius()<<std::endl; std::cout<<"Factor : "<<factor<<std::endl; - /* - otb::Function::ProlateFunction<double,double> function; ///= prolate->GetFunction(); - function.SetRadius(rad); - std::cout<<"Originalprofilsize: "<< function.GetOriginalProfileSize()<<std::endl; - std::cout<<"Energy : "<<function.ComputeEnergy(factor)<<std::endl; - std::cout<<"Radius : "<<function.GetRadius()<<std::endl; - std::cout<<"Factor : "<<factor<<std::endl; - */ proresampler->SetInput(reader->GetOutput()); proresampler->SetInterpolator(prolate); StreamingResampleImageFilterType::SizeType size; @@ -88,18 +80,6 @@ int otbProlateValidationTest(int argc, char * argv[]) prowriter->SetFileName(outfname); prowriter->Update(); - /* - prowriter = WriterType::New(); - proresampler = StreamingResampleImageFilterType::New(); - proresampler->SetSize(size); - proresampler->SetOutputSpacing(newSpacing); - proresampler->SetOutputOrigin(origin); - proresampler->SetInput(reader->GetOutput()); - def->SetInputImage(reader->GetOutput()); - proresampler->SetInterpolator(def); - prowriter->SetInput(proresampler->GetOutput()); - prowriter->SetFileName(defaultoutfname); - prowriter->Update(); - */ + return EXIT_SUCCESS; } diff --git a/Testing/Code/DisparityMap/CMakeLists.txt b/Testing/Code/DisparityMap/CMakeLists.txt index 7037e7980f035d1ecca853236e723331b3f98450..f190b389793b4cd8b8bad792e73dd83c4cdeeabb 100644 --- a/Testing/Code/DisparityMap/CMakeLists.txt +++ b/Testing/Code/DisparityMap/CMakeLists.txt @@ -59,12 +59,31 @@ ADD_TEST(dmTvNearestPointDeformationFieldGenerator ${DISPARITYMAP_TESTS1} ADD_TEST(dmTuNCCRegistrationFilterNew ${DISPARITYMAP_TESTS1} otbNCCRegistrationFilterNew) +ADD_TEST(dmTvNCCRegistrationFilter ${DISPARITYMAP_TESTS1} +--compare-image ${EPSILON} + ${BASELINE}/dmNCCRegistrationFilterOutput.tif + ${TEMP}/dmNCCRegistrationFilterOutput.tif + otbNCCRegistrationFilter + ${INPUTDATA}/ROI_IKO_PAN_LesHalles_sub.tif + ${INPUTDATA}/ROI_IKO_PAN_LesHalles_sub_warped_sinus.tif + ${TEMP}/dmNCCRegistrationFilterOutput.tif + 5 1.0 2) + # ------- otb::MIRegistrationFilter ---------- ADD_TEST(dmTuMIRegistrationFilterNew ${DISPARITYMAP_TESTS1} otbMIRegistrationFilterNew) - +ADD_TEST(dmTvMIRegistrationFilter ${DISPARITYMAP_TESTS1} +--compare-image ${EPSILON} + ${BASELINE}/dmMIRegistrationFilterOutput.tif + ${TEMP}/dmMIRegistrationFilterOutput.tif + otbMIRegistrationFilter + ${INPUTDATA}/ROI_IKO_PAN_LesHalles_sub.tif + ${INPUTDATA}/ROI_IKO_PAN_LesHalles_sub_warped_sinus.tif + ${TEMP}/dmMIRegistrationFilterOutput.tif + 5 1.0 2) + # ------- otb::NNearestPointsLinearInterpolateDeformationFieldGenerator ---------- ADD_TEST(dmTuNNearestPointsLinearInterpolateDeformationFieldGeneratorNew ${DISPARITYMAP_TESTS1} @@ -332,7 +351,9 @@ SET(BasicDisparityMap_SRCS1 otbDisparityMapEstimationMethodNew.cxx otbDisparityMapEstimationMethod.cxx otbNCCRegistrationFilterNew.cxx +otbNCCRegistrationFilter.cxx otbMIRegistrationFilterNew.cxx +otbMIRegistrationFilter.cxx otbPointSetToDeformationFieldGeneratorNew.cxx otbNearestPointDeformationFieldGeneratorNew.cxx otbNearestPointDeformationFieldGenerator.cxx diff --git a/Testing/Code/DisparityMap/otbDisparityMapTests1.cxx b/Testing/Code/DisparityMap/otbDisparityMapTests1.cxx index 82515423c023942365a1ae168b431eb7aafd8c9e..1a81a498335257a2a551170e39ef6f3da6364ab8 100644 --- a/Testing/Code/DisparityMap/otbDisparityMapTests1.cxx +++ b/Testing/Code/DisparityMap/otbDisparityMapTests1.cxx @@ -37,5 +37,7 @@ REGISTER_TEST(otbBSplinesInterpolateDeformationFieldGeneratorNew); REGISTER_TEST(otbBSplinesInterpolateDeformationFieldGenerator); REGISTER_TEST(otbPointSetWithTransformToDeformationFieldGeneratorNew); REGISTER_TEST(otbNCCRegistrationFilterNew); -REGISTER_TEST(otbMIRegistrationFilterNew); +REGISTER_TEST(otbNCCRegistrationFilter); +REGISTER_TEST(otbMIRegistrationFilterNew); +REGISTER_TEST(otbMIRegistrationFilter); } diff --git a/Testing/Code/DisparityMap/otbMIRegistrationFilter.cxx b/Testing/Code/DisparityMap/otbMIRegistrationFilter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..3f2e794018b503aab55b4140261852a6c67f2b0e --- /dev/null +++ b/Testing/Code/DisparityMap/otbMIRegistrationFilter.cxx @@ -0,0 +1,101 @@ +/*========================================================================= + + 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 "otbStreamingImageFileWriter.h" +#include "otbImageFileReader.h" + +#include "otbMIRegistrationFilter.h" +#include "itkRecursiveGaussianImageFilter.h" + +int otbMIRegistrationFilter(int argc, char* argv []) +{ + + if(argc!= 7) + { + std::cerr <<"Usage: "<<argv[0]; + std::cerr<<" fixedFileName movingFileName fieldOutName"; + std::cerr<<"explorationSize bluringSigma nbIterations "; + + return EXIT_FAILURE; + } + + const unsigned int ImageDimension = 2; + + typedef double PixelType; + typedef itk::Vector<double,ImageDimension> DeformationPixelType; + typedef double CoordinateRepresentationType; + typedef double OutputPixelType; + typedef otb::Image<OutputPixelType,ImageDimension> OutputImageType; + typedef otb::Image<PixelType,ImageDimension> MovingImageType; + typedef otb::Image<PixelType,ImageDimension> FixedImageType; + typedef otb::Image<DeformationPixelType, + ImageDimension> DeformationFieldType; + + typedef otb::ImageFileReader< FixedImageType > FixedReaderType; + FixedReaderType::Pointer fReader = FixedReaderType::New(); + fReader->SetFileName(argv[1]); + + typedef otb::ImageFileReader< MovingImageType > MovingReaderType; + MovingReaderType::Pointer mReader = MovingReaderType::New(); + mReader->SetFileName(argv[2]); + + typedef itk::RecursiveGaussianImageFilter< FixedImageType, + FixedImageType > FixedBlurType; + + FixedBlurType::Pointer fBlur = FixedBlurType::New(); + fBlur->SetInput( fReader->GetOutput() ); + fBlur->SetSigma( atof(argv[5]) ); + + typedef itk::RecursiveGaussianImageFilter< MovingImageType, + MovingImageType > MovingBlurType; + + MovingBlurType::Pointer mBlur = MovingBlurType::New(); + mBlur->SetInput( mReader->GetOutput() ); + mBlur->SetSigma(atof(argv[5]) ); + + typedef otb::MIRegistrationFilter< FixedImageType, + MovingImageType, + DeformationFieldType > + RegistrationFilterType; + + RegistrationFilterType::Pointer registrator = RegistrationFilterType::New(); + + registrator->SetMovingImage( mBlur->GetOutput() ); + registrator->SetFixedImage( fBlur->GetOutput() ); + + typedef RegistrationFilterType::RadiusType RadiusType; + + RadiusType radius; + + radius[0] = atoi(argv[4]); + radius[1] = atoi(argv[4]); + + registrator->SetMIRadius( radius ); + + registrator->SetNumberOfIterations( atoi(argv[6]) ); + + typedef otb::StreamingImageFileWriter<DeformationFieldType> DFWriterType; + DFWriterType::Pointer dfWriter = DFWriterType::New(); + dfWriter->SetFileName(argv[3]); + dfWriter->SetInput( registrator->GetOutput() ); + dfWriter->Update(); + + return EXIT_SUCCESS; + +} + diff --git a/Testing/Code/DisparityMap/otbNCCRegistrationFilter.cxx b/Testing/Code/DisparityMap/otbNCCRegistrationFilter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..476f89f1512a4284f9d9b858c7a60022c5b9cefa --- /dev/null +++ b/Testing/Code/DisparityMap/otbNCCRegistrationFilter.cxx @@ -0,0 +1,101 @@ +/*========================================================================= + + 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 "otbStreamingImageFileWriter.h" +#include "otbImageFileReader.h" + +#include "otbNCCRegistrationFilter.h" +#include "itkRecursiveGaussianImageFilter.h" + +int otbNCCRegistrationFilter(int argc, char* argv []) +{ + + if(argc!= 7) + { + std::cerr <<"Usage: "<<argv[0]; + std::cerr<<" fixedFileName movingFileName fieldOutName"; + std::cerr<<"explorationSize bluringSigma nbIterations "; + + return EXIT_FAILURE; + } + + const unsigned int ImageDimension = 2; + + typedef double PixelType; + typedef itk::Vector<double,ImageDimension> DeformationPixelType; + typedef double CoordinateRepresentationType; + typedef double OutputPixelType; + typedef otb::Image<OutputPixelType,ImageDimension> OutputImageType; + typedef otb::Image<PixelType,ImageDimension> MovingImageType; + typedef otb::Image<PixelType,ImageDimension> FixedImageType; + typedef otb::Image<DeformationPixelType, + ImageDimension> DeformationFieldType; + + typedef otb::ImageFileReader< FixedImageType > FixedReaderType; + FixedReaderType::Pointer fReader = FixedReaderType::New(); + fReader->SetFileName(argv[1]); + + typedef otb::ImageFileReader< MovingImageType > MovingReaderType; + MovingReaderType::Pointer mReader = MovingReaderType::New(); + mReader->SetFileName(argv[2]); + + typedef itk::RecursiveGaussianImageFilter< FixedImageType, + FixedImageType > FixedBlurType; + + FixedBlurType::Pointer fBlur = FixedBlurType::New(); + fBlur->SetInput( fReader->GetOutput() ); + fBlur->SetSigma( atof(argv[5]) ); + + typedef itk::RecursiveGaussianImageFilter< MovingImageType, + MovingImageType > MovingBlurType; + + MovingBlurType::Pointer mBlur = MovingBlurType::New(); + mBlur->SetInput( mReader->GetOutput() ); + mBlur->SetSigma(atof(argv[5]) ); + + typedef otb::NCCRegistrationFilter< FixedImageType, + MovingImageType, + DeformationFieldType > + RegistrationFilterType; + + RegistrationFilterType::Pointer registrator = RegistrationFilterType::New(); + + registrator->SetMovingImage( mBlur->GetOutput() ); + registrator->SetFixedImage( fBlur->GetOutput() ); + + typedef RegistrationFilterType::RadiusType RadiusType; + + RadiusType radius; + + radius[0] = atoi(argv[4]); + radius[1] = atoi(argv[4]); + + registrator->SetNCCRadius( radius ); + + registrator->SetNumberOfIterations( atoi(argv[6]) ); + + typedef otb::StreamingImageFileWriter<DeformationFieldType> DFWriterType; + DFWriterType::Pointer dfWriter = DFWriterType::New(); + dfWriter->SetFileName(argv[3]); + dfWriter->SetInput( registrator->GetOutput() ); + dfWriter->Update(); + + return EXIT_SUCCESS; + +} + diff --git a/Testing/Code/DisparityMap/otbStreamingWarpImageFilter.cxx b/Testing/Code/DisparityMap/otbStreamingWarpImageFilter.cxx index b2d8f157b7a5346c5f49356702699c8d53b0c58d..cd136dca3024aa58decb4743b78488bf4dda3dff 100644 --- a/Testing/Code/DisparityMap/otbStreamingWarpImageFilter.cxx +++ b/Testing/Code/DisparityMap/otbStreamingWarpImageFilter.cxx @@ -15,14 +15,13 @@ PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#include "otbImage.h" #include "otbVectorImage.h" +#include "itkVector.h" +#include "otbImage.h" #include "otbImageFileReader.h" #include "otbStreamingImageFileWriter.h" - #include "otbStreamingWarpImageFilter.h" - int otbStreamingWarpImageFilter(int argc, char* argv[]) { if(argc!=5) @@ -41,7 +40,8 @@ int otbStreamingWarpImageFilter(int argc, char* argv[]) const unsigned int Dimension=2; typedef double PixelType; typedef otb::Image<PixelType,Dimension> ImageType; - typedef otb::VectorImage<PixelType,Dimension> DeformationFieldType; + typedef itk::Vector<PixelType,2> DeformationValueType; + typedef otb::Image<DeformationValueType,Dimension> DeformationFieldType; // Warper typedef otb::StreamingWarpImageFilter<ImageType,ImageType,DeformationFieldType> ImageWarperType; @@ -62,7 +62,7 @@ int otbStreamingWarpImageFilter(int argc, char* argv[]) deformationReader->SetFileName(deffname); // Warping - ImageWarperType::DeformationValueType maxDeformation; + DeformationValueType maxDeformation; maxDeformation.Fill(maxdef); warper->SetMaximumDeformation(maxDeformation); warper->SetInput(reader->GetOutput()); diff --git a/Testing/Code/DisparityMap/otbStreamingWarpImageFilterNew.cxx b/Testing/Code/DisparityMap/otbStreamingWarpImageFilterNew.cxx index 62499b69d0a585d8dd5700c5b10ab7c570b88e38..e1279094ae256121b3308aba81f3231dc3e3d8a7 100644 --- a/Testing/Code/DisparityMap/otbStreamingWarpImageFilterNew.cxx +++ b/Testing/Code/DisparityMap/otbStreamingWarpImageFilterNew.cxx @@ -16,21 +16,18 @@ =========================================================================*/ #include "otbImage.h" -#include "otbVectorImage.h" -#include "otbImageFileReader.h" -#include "otbStreamingImageFileWriter.h" - +#include "itkVector.h" #include "otbStreamingWarpImageFilter.h" - int otbStreamingWarpImageFilterNew(int argc, char* argv[]) { // Images definition const unsigned int Dimension=2; typedef double PixelType; + typedef itk::Vector<PixelType,2> DeformationValueType; typedef otb::Image<PixelType,Dimension> ImageType; - typedef otb::VectorImage<PixelType,Dimension> DeformationFieldType; - + typedef otb::Image<DeformationValueType,2> DeformationFieldType; + // Warper typedef otb::StreamingWarpImageFilter<ImageType,ImageType,DeformationFieldType> ImageWarperType; diff --git a/Testing/Code/FeatureExtraction/CMakeLists.txt b/Testing/Code/FeatureExtraction/CMakeLists.txt index f3ff009c402da4ef6f240a5750ed5c7762f9d046..59c66b541ee32ef9e1cd62a9732fce47f3c6246f 100644 --- a/Testing/Code/FeatureExtraction/CMakeLists.txt +++ b/Testing/Code/FeatureExtraction/CMakeLists.txt @@ -838,7 +838,7 @@ ADD_TEST(feTvImageToHessianDeterminantImageFilter ${FEATUREEXTRACTION_TESTS9} ${INPUTDATA}/ROI_IKO_PAN_LesHalles_sub.tif ${TEMP}/feTvImageToHessianDeterminantImageFilterOutput.tif 1.5 - ) + ) # ------- otb::ImageToSURFKeyPointSetFilterNew ------------- @@ -865,11 +865,24 @@ ADD_TEST(feTvImageToSURFKeyPointSetFilterSceneOutputAscii ${FEATUREEXTRACTION_TE ${TEMP}/feTvImageToSURFKeyPointSetFilterSceneKeysOutput.txt 1 3 ) + +# ------- otb::ImageFittingPolygonListFilter ------------- +ADD_TEST(feTuImageFittingPolygonListFilterNew ${FEATUREEXTRACTION_TESTS9} + otbImageFittingPolygonListFilterNew) +ADD_TEST(feTvImageFittingPolygonListFilter ${FEATUREEXTRACTION_TESTS9} +--compare-ascii ${EPS} + ${BASELINE_FILES}/feTvImageFittingPolygonListFilter_Output.kml + ${TEMP}/feTvImageFittingPolygonListFilter_Output.kml + otbImageFittingPolygonListFilter + ${INPUTDATA}/polygon.png + ${INPUTDATA}/polygon-start.kml + ${TEMP}/feTvImageFittingPolygonListFilter_Output.kml + 5 10 +) - # A enrichir SET(BasicFeatureExtraction_SRCS1 otbAlignImageToPath.cxx @@ -974,10 +987,11 @@ otbImageToSIFTKeyPointSetFilterOutputImage.cxx otbImageToSIFTKeyPointSetFilterOutputAscii.cxx otbImageToHessianDeterminantImageFilterNew.cxx otbImageToHessianDeterminantImageFilter.cxx +otbImageFittingPolygonListFilter.cxx +otbImageFittingPolygonListFilterNew.cxx otbImageToSURFKeyPointSetFilterNew.cxx otbImageToSURFKeyPointSetFilterOutputImage.cxx otbImageToSURFKeyPointSetFilterOutputAscii.cxx -#otbImageToSURFKeyPointSetFilterDistanceMap.cxx ) INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}") diff --git a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests9.cxx b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests9.cxx index 359428b9e59a911acbde11ab3faba4cebb9a84f7..a213921eb09334109151fee7b2e4b8b7d5774808 100644 --- a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests9.cxx +++ b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests9.cxx @@ -35,8 +35,9 @@ REGISTER_TEST(otbImageToSIFTKeyPointSetFilterOutputAscii); //REGISTER_TEST(otbImageToSIFTKeyPointSetFilterValid); REGISTER_TEST(otbImageToHessianDeterminantImageFilterNew); REGISTER_TEST(otbImageToHessianDeterminantImageFilter); +REGISTER_TEST(otbImageFittingPolygonListFilter); +REGISTER_TEST(otbImageFittingPolygonListFilterNew); REGISTER_TEST(otbImageToSURFKeyPointSetFilterNew); REGISTER_TEST(otbImageToSURFKeyPointSetFilterOutputImage); REGISTER_TEST(otbImageToSURFKeyPointSetFilterOutputAscii); -//REGISTER_TEST(otbImageToSURFKeyPointSetFilterDistanceMap); } diff --git a/Testing/Code/FeatureExtraction/otbImageFittingPolygonListFilter.cxx b/Testing/Code/FeatureExtraction/otbImageFittingPolygonListFilter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..35968ee020dc0bde944571437a3a23c8d1ec6378 --- /dev/null +++ b/Testing/Code/FeatureExtraction/otbImageFittingPolygonListFilter.cxx @@ -0,0 +1,129 @@ +/*========================================================================= + + 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 "otbImageFittingPolygonListFilter.h" +#include "otbPolygon.h" +#include "otbImage.h" +#include "otbVectorData.h" +#include "otbImageFileReader.h" +#include "otbVectorDataFileReader.h" +#include "otbVectorDataFileWriter.h" +#include "itkCannyEdgeDetectionImageFilter.h" +#include "otbObjectList.h" +#include <fstream> +#include <cstdlib> + +int otbImageFittingPolygonListFilter(int argc, char * argv[]) +{ + const char * imageFileName = argv[1]; + const char * polyFileName = argv[2]; + const char * outFileName = argv[3]; + const int fittingRadius = atoi(argv[4]); + const int fittingIters = atoi(argv[5]); + + const unsigned int Dimension =2; + typedef otb::Polygon<double> PolygonType; + typedef otb::Image<double,Dimension> ImageType; + + //Read the reference image and extract its contours + typedef otb::ImageFileReader<ImageType> ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(imageFileName); + + typedef itk::CannyEdgeDetectionImageFilter<ImageType,ImageType> CannyFilterType; + CannyFilterType::Pointer canny = CannyFilterType::New(); + canny->SetInput(reader->GetOutput()); + + //Read the original polygon list (kml file) + typedef otb::VectorData<> VectorDataType; + typedef VectorDataType::DataTreeType DataTreeType; + typedef itk::PreOrderTreeIterator<DataTreeType> TreeIteratorType; + typedef VectorDataType::DataNodeType DataNodeType; + typedef DataNodeType::Pointer DataNodePointerType; + typedef otb::VectorDataFileReader<VectorDataType> VectorDataFileReaderType; + VectorDataFileReaderType::Pointer readerVector = VectorDataFileReaderType::New(); + + readerVector->SetFileName(polyFileName); + readerVector->Update(); + + //Copy the polygons of the data tree in a polygon list + typedef otb::ObjectList<PolygonType> PolygonListType; + PolygonListType::Pointer polygonList = PolygonListType::New(); + + TreeIteratorType it(readerVector->GetOutput()->GetDataTree()); + it.GoToBegin(); + + while(!it.IsAtEnd()) + { + DataNodePointerType dataNode = it.Get(); + if(dataNode->IsPolygonFeature()) + { + polygonList->PushBack(dataNode->GetPolygonExteriorRing()); + } + ++it; + } + + //Fit the polygons on the image + typedef otb::ImageFittingPolygonListFilter<PolygonType,ImageType> FittingPolygonType; + + FittingPolygonType::Pointer fittingPolygon = FittingPolygonType::New(); + fittingPolygon->SetInput(polygonList); + fittingPolygon->SetInputImage(canny->GetOutput()); + fittingPolygon->SetRadius(fittingRadius); + fittingPolygon->SetNumberOfIterations(fittingIters); + fittingPolygon->Update(); + + + //Write the improved polygon list (kml file) + VectorDataType::Pointer data = VectorDataType::New(); + + DataNodeType::Pointer document = DataNodeType::New(); + DataNodeType::Pointer folder = DataNodeType::New(); + + document->SetNodeType(otb::DOCUMENT); + folder->SetNodeType(otb::FOLDER); + + document->SetNodeId("DOCUMENT"); + folder->SetNodeId("FOLDER"); + + DataNodeType::Pointer root = data->GetDataTree()->GetRoot()->Get(); + + data->GetDataTree()->Add(document,root); + data->GetDataTree()->Add(folder,document); + + typedef PolygonListType::ConstIterator ListIteratorType; + ListIteratorType listIt = fittingPolygon->GetOutput()->Begin(); + while(listIt != fittingPolygon->GetOutput()->End()) + { + DataNodeType::Pointer polygon = DataNodeType::New(); + polygon->SetNodeType(otb::FEATURE_POLYGON); + polygon->SetNodeId("FEATURE_POLYGON"); + polygon->SetPolygonExteriorRing(listIt.Get()); + data->GetDataTree()->Add(polygon,folder); + ++listIt; + } + + typedef otb::VectorDataFileWriter<VectorDataType> WriterType; + WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(outFileName); + writer->SetInput(data); + writer->Update(); + + return EXIT_SUCCESS; +}