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/otbImageToHessianDeterminantImageFilter.h b/Code/FeatureExtraction/otbImageToHessianDeterminantImageFilter.h index b805b91a4bda57bad5ce28263b79c1d3b6dc6320..2595c01ced41974c18690391e57dbaa3341e534d 100644 --- a/Code/FeatureExtraction/otbImageToHessianDeterminantImageFilter.h +++ b/Code/FeatureExtraction/otbImageToHessianDeterminantImageFilter.h @@ -9,6 +9,8 @@ Version: $Revision$ Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. See OTBCopyright.txt for details. +Copyright (c) CS Systèmes d'Information. All rights reserved. +See CSCopyright.txt for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 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/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;