Skip to content
Snippets Groups Projects
Commit 27dcf550 authored by Julien Michel's avatar Julien Michel
Browse files

Ajout de l'estimation de la déformation par plus proche transformation locale.

parent bdc3e82a
No related branches found
No related tags found
No related merge requests found
Showing with 568 additions and 1 deletion
/*=========================================================================
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.
=========================================================================*/
#ifndef _otbNearestTransformDeformationFieldGenerator_h
#define _otbNearestTransformDeformationFieldGenerator_h
#include "otbPointSetWithTransformToDeformationFieldGenerator.h"
namespace otb
{
/** \class NearestTransformDeformationFieldGenerator
* \brief This class implements deformation field generation by taking into account the local transform of the
* nearest point in pointset.
*
* \ingroup
* \ingroup
*/
template <class TPointSet, class TDeformationField>
class ITK_EXPORT NearestTransformDeformationFieldGenerator
: public PointSetWithTransformToDeformationFieldGenerator<TPointSet, TDeformationField>
{
public:
/** Standard typedefs */
typedef NearestTransformDeformationFieldGenerator Self;
typedef PointSetWithTransformToDeformationFieldGenerator<TPointSet,TDeformationField> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Type macro */
itkNewMacro(Self);
/** Creation through object factory macro */
itkTypeMacro(NearestTransformDeformationFieldGenerator,PointSetWithTransformToDeformationFieldGenerator);
/** Template parameters typedefs */
typedef typename Superclass::PointSetType PointSetType;
typedef typename Superclass::PointSetPointerType PointSetPointerType;
typedef typename Superclass::DeformationFieldType DeformationFieldType;
typedef typename Superclass::DeformationFieldPointerType DeformationFieldPointerType;
typedef typename Superclass::IndexType IndexType;
typedef typename Superclass::PointType PointType;
typedef typename DeformationFieldType::PixelType PixelType;
typedef typename Superclass::ValueType ValueType;
typedef typename Superclass::IndexVectorType IndexVectorType;
typedef typename Superclass::TransformType TransformType;
typedef typename TransformType::ParametersType ParametersType;
protected:
/** Constructor */
NearestTransformDeformationFieldGenerator() {};
/** Destructor */
virtual ~NearestTransformDeformationFieldGenerator() {};
/**PrintSelf method */
virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
/** Main computation method */
virtual void GenerateData();
private:
NearestTransformDeformationFieldGenerator(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
};
}// End namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbNearestTransformDeformationFieldGenerator.txx"
#endif
#endif
/*=========================================================================
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.
=========================================================================*/
#ifndef _otbNearestTransformDeformationFieldGenerator_txx
#define _otbNearestTransformDeformationFieldGenerator_txx
#include "otbNearestTransformDeformationFieldGenerator.h"
#include "itkImageRegionIteratorWithIndex.h"
#include "otbMacro.h"
namespace otb
{
/** Main computation method */
template <class TPointSet,class TDeformationField>
void
NearestTransformDeformationFieldGenerator<TPointSet, TDeformationField>
::GenerateData(void)
{
DeformationFieldPointerType outputPtr = this->GetOutput();
PixelType defaultValue(2);
defaultValue.Fill(this->GetDefaultValue());
outputPtr->Allocate();
outputPtr->FillBuffer(defaultValue);
typedef itk::ImageRegionIteratorWithIndex<DeformationFieldType> IteratorType;
IteratorType it(outputPtr,outputPtr->GetRequestedRegion());
for(it.GoToBegin();!it.IsAtEnd();++it)
{
IndexVectorType indexVector = this->GenerateNearestValidPointsPointSet(it.GetIndex(),1);
PixelType pixel(2);
if(indexVector.size()>=1)
{
ParametersType params(this->GetTransform()->GetNumberOfParameters());
for(unsigned int i = 0; i<this->GetTransform()->GetNumberOfParameters();++i)
{
params[i] = this->GetPointSet()->GetPointData()->GetElement(indexVector[0])[i+3];
}
this->GetTransform()->SetParameters(params);
PointType sourcePoint,targetPoint;
outputPtr->TransformIndexToPhysicalPoint(it.GetIndex(),sourcePoint);
targetPoint = this->GetTransform()->TransformPoint(sourcePoint);
pixel[0] = static_cast<ValueType>(targetPoint[0]-sourcePoint[0]);
pixel[1] = static_cast<ValueType>(targetPoint[1]-sourcePoint[1]);
}
else
{
pixel=defaultValue;
}
it.Set(pixel);
}
}
/**
* PrintSelf Method
*/
template <class TPointSet,class TDeformationField>
void
NearestTransformDeformationFieldGenerator<TPointSet, TDeformationField>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
}
} // End namespace otb
#endif
/*=========================================================================
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.
=========================================================================*/
#ifndef _otbPointSetWithTransformToDeformationFieldGenerator_h
#define _otbPointSetWithTransformToDeformationFieldGenerator_h
#include "otbPointSetToDeformationFieldGenerator.h"
#include "itkTransform.h"
namespace otb
{
/** \class PointSetWithTransformToDeformationFieldGenerator
* \brief Base class for filters generating a deformation field from a point set enriched with local transform information.
* The output of the filters deriving from this base class can be passed to the itk::WarpImageFilter for image resampling.
* \sa DisparityMapEstimationMethod
* \sa itk::WarpImageFilter
* \ingroup
*/
template <class TPointSet, class TDeformationField>
class ITK_EXPORT PointSetWithTransformToDeformationFieldGenerator
: public PointSetToDeformationFieldGenerator<TPointSet,TDeformationField>
{
public:
/** Standard typedefs */
typedef PointSetWithTransformToDeformationFieldGenerator Self;
typedef PointSetToDeformationFieldGenerator<TPointSet,TDeformationField> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Type macro */
itkNewMacro(Self);
/** Creation through object factory macro */
itkTypeMacro(PointSetWithTransformToDeformationFieldGenerator,PointSetToDeformationFieldGenerator);
/** Template parameters typedefs */
typedef TPointSet PointSetType;
typedef typename PointSetType::Pointer PointSetPointerType;
typedef TDeformationField DeformationFieldType;
typedef typename DeformationFieldType::Pointer DeformationFieldPointerType;
typedef typename DeformationFieldType::IndexType IndexType;
typedef typename DeformationFieldType::SizeType SizeType;
typedef typename DeformationFieldType::SpacingType SpacingType;
typedef typename DeformationFieldType::PointType PointType;
typedef typename DeformationFieldType::ValueType ValueType;
/** More typedefs */
typedef typename Superclass::DistanceVectorType DistanceVectorType;
typedef typename Superclass::IndexVectorType IndexVectorType;
/** Transform typedefs */
typedef itk::Transform<double,2,2> TransformType;
typedef typename TransformType::Pointer TransformPointerType;
typedef typename TransformType::ParametersType ParametersType;
/** Set/Get the Transfrom. */
itkSetObjectMacro(Transform,TransformType);
itkGetObjectMacro(Transform,TransformType);
protected:
/** Constructor */
PointSetWithTransformToDeformationFieldGenerator();
/** Destructor */
virtual ~PointSetWithTransformToDeformationFieldGenerator() {};
/**PrintSelf method */
virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
private:
PointSetWithTransformToDeformationFieldGenerator(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
/**
* The transform used for local registration.
*/
TransformPointerType m_Transform;
};
}// End namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbPointSetWithTransformToDeformationFieldGenerator.txx"
#endif
#endif
/*=========================================================================
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.
=========================================================================*/
#ifndef _otbPointSetWithTransformToDeformationFieldGenerator_txx
#define _otbPointSetWithTransformToDeformationFieldGenerator_txx
#include "otbPointSetWithTransformToDeformationFieldGenerator.h"
#include "otbMacro.h"
namespace otb
{
/**
* Constructor
*/
template <class TPointSet, class TDeformationField>
PointSetWithTransformToDeformationFieldGenerator<TPointSet, TDeformationField>
::PointSetWithTransformToDeformationFieldGenerator()
{
m_Transform = 0; // has to be provided by the user
}
/**
* PrintSelf Method
*/
template <class TPointSet, class TDeformationField>
void
PointSetWithTransformToDeformationFieldGenerator<TPointSet, TDeformationField>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
}
} // End namespace otb
#endif
......@@ -77,6 +77,26 @@ ADD_TEST(dmTvBSplinesInterpolateDeformationFieldGenerator ${DISPARITYMAP_TESTS}
${TEMP}/dmTvBSplinesInterpolateDeformationField.hdr
)
# ------- otb::PointSetToDeformationFieldGenerator ----------
ADD_TEST(dmTuPointSetWithTransformToDeformationFieldGeneratorNew ${DISPARITYMAP_TESTS}
otbPointSetWithTransformToDeformationFieldGeneratorNew)
# ------- otb::NearestPointDeformationFieldGenerator ----------
ADD_TEST(dmTuNearestTransformDeformationFieldGeneratorNew ${DISPARITYMAP_TESTS}
otbNearestTransformDeformationFieldGeneratorNew)
ADD_TEST(dmTvNearestTransformDeformationFieldGenerator ${DISPARITYMAP_TESTS}
--compare-image ${TOL}
${BASELINE}/dmTvNearestTransformDeformationField.hdr
${TEMP}/dmTvNearestTransformDeformationField.hdr
otbNearestTransformDeformationFieldGenerator
${TEMP}/dmTvNearestTransformDeformationField.hdr
)
# ------- Fichiers sources CXX -----------------------------------
SET(BasicDisparityMap_SRCS
otbDisparityMapEstimationMethodNew.cxx
......@@ -88,7 +108,9 @@ otbNNearestPointsLinearInterpolateDeformationFieldGeneratorNew.cxx
otbNNearestPointsLinearInterpolateDeformationFieldGenerator.cxx
otbBSplinesInterpolateDeformationFieldGeneratorNew.cxx
otbBSplinesInterpolateDeformationFieldGenerator.cxx
otbPointSetWithTransformToDeformationFieldGeneratorNew.cxx
otbNearestTransformDeformationFieldGeneratorNew.cxx
otbNearestTransformDeformationFieldGenerator.cxx
)
INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}")
......
......@@ -35,4 +35,7 @@ REGISTER_TEST(otbNNearestPointsLinearInterpolateDeformationFieldGeneratorNew);
REGISTER_TEST(otbNNearestPointsLinearInterpolateDeformationFieldGenerator);
REGISTER_TEST(otbBSplinesInterpolateDeformationFieldGeneratorNew);
REGISTER_TEST(otbBSplinesInterpolateDeformationFieldGenerator);
REGISTER_TEST(otbPointSetWithTransformToDeformationFieldGeneratorNew);
REGISTER_TEST(otbNearestTransformDeformationFieldGeneratorNew);
REGISTER_TEST(otbNearestTransformDeformationFieldGenerator);
}
/*=========================================================================
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 "itkPointSet.h"
#include "otbVectorImage.h"
#include "otbNearestTransformDeformationFieldGenerator.h"
#include "otbImageFileWriter.h"
#include "itkEuler2DTransform.h"
int otbNearestTransformDeformationFieldGenerator(int argc, char * argv[])
{
try
{
const unsigned int Dimension = 2;
const char * outfname = argv[1];
typedef double PixelType;
typedef otb::VectorImage<PixelType,Dimension> ImageType;
typedef itk::Array<double> ParamType;
typedef itk::PointSet<ParamType,Dimension> PointSetType;
typedef PointSetType::PointType PointType;
typedef otb::NearestTransformDeformationFieldGenerator<PointSetType,ImageType> FilterType;
typedef otb::ImageFileWriter<ImageType> WriterType;
typedef itk::Euler2DTransform<double> TransformType;
ImageType::SizeType size;
size.Fill(100);
double thresh = 0.9;
// Preparing point set
PointSetType::Pointer ps = PointSetType::New();
PointType p1,p2,p3,p4,p5;
ParamType pd1(6),pd2(6),pd3(6),pd4(6),pd5(6);
itk::Point<double,2> center;
p1[0] = 10;
p1[1] = 10;
p2[0] = 75;
p2[1] = 10;
p3[0] = 50;
p3[1] = 50;
p4[0] = 10;
p4[1] = 60;
p5[0] = 85;
p5[1] = 70;
center.Fill(0);
pd1[0] = 0.95;
pd1[1] = 0;
pd1[2] = 0;
pd1[3] = 5;
pd1[4] = 5;
pd1[5] = 0.1769;
pd2[0] = 0.98;
pd2[1] = 0;
pd2[2] = 0;
pd2[3] = -5;
pd2[4] = 5;
pd2[5] = -0.1769;
pd3[0] = 0.5;
pd3[1] = 0;
pd3[2] = 0;
pd3[3] = 0;
pd3[4] = 0;
pd3[5] = 0;
pd4[0] = 0.91;
pd4[1] = 0;
pd4[2] = 0;
pd4[3] = 5;
pd4[4] = -5;
pd4[5] = 0.1769;
pd5[0] = 0.91;
pd5[1] = 0;
pd5[2] = 0;
pd5[3] = -5;
pd5[4] = -5;
pd5[5] = -0.1769;
ps->SetPoint(0,p1);
ps->SetPointData(0,pd1);
ps->SetPoint(1,p2);
ps->SetPointData(1,pd2);
ps->SetPoint(2,p3);
ps->SetPointData(2,pd3);
ps->SetPoint(3,p4);
ps->SetPointData(3,pd4);
ps->SetPoint(4,p5);
ps->SetPointData(4,pd5);
TransformType::Pointer transform = TransformType::New();
transform->SetCenter(center);
// Instantiating object
FilterType::Pointer filter = FilterType::New();
filter->SetOutputSize(size);
filter->SetMetricThreshold(thresh);
filter->SetPointSet(ps);
filter->SetTransform(transform);
WriterType::Pointer writer = WriterType::New();
writer->SetInput(filter->GetOutput());
writer->SetFileName(outfname);
writer->Update();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject thrown !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception thrown !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "itkExceptionObject.h"
#include "itkPointSet.h"
#include "otbVectorImage.h"
#include "otbNearestTransformDeformationFieldGenerator.h"
int otbNearestTransformDeformationFieldGeneratorNew(int argc, char * argv[])
{
try
{
const unsigned int Dimension = 2;
typedef double PixelType;
typedef otb::VectorImage<PixelType,Dimension> ImageType;
typedef ImageType::PointType PointType;
typedef itk::PointSet<PointType,Dimension> PointSetType;
typedef otb::NearestTransformDeformationFieldGenerator<PointSetType,ImageType> FilterType;
// Instantiating object
FilterType::Pointer filter = FilterType::New();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject thrown !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception thrown !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "itkExceptionObject.h"
#include "itkPointSet.h"
#include "otbVectorImage.h"
#include "otbPointSetWithTransformToDeformationFieldGenerator.h"
int otbPointSetWithTransformToDeformationFieldGeneratorNew(int argc, char * argv[])
{
try
{
const unsigned int Dimension = 2;
typedef double PixelType;
typedef otb::VectorImage<PixelType,Dimension> ImageType;
typedef ImageType::PointType PointType;
typedef itk::PointSet<PointType,Dimension> PointSetType;
typedef otb::PointSetWithTransformToDeformationFieldGenerator<PointSetType,ImageType> FilterType;
// Instantiating object
FilterType::Pointer filter = FilterType::New();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject thrown !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception thrown !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment