diff --git a/Code/FeatureExtraction/CMakeLists.txt b/Code/FeatureExtraction/CMakeLists.txt index ed0c66843a6e1f35197e6222330d497bf0ed9f53..36ce2adb9327e6a30522758535e994674bc9309f 100644 --- a/Code/FeatureExtraction/CMakeLists.txt +++ b/Code/FeatureExtraction/CMakeLists.txt @@ -4,7 +4,7 @@ FILE(GLOB OTBFeatureExtraction_SRCS "*.cxx" ) ADD_LIBRARY(OTBFeatureExtraction ${OTBFeatureExtraction_SRCS}) -TARGET_LINK_LIBRARIES (OTBFeatureExtraction OTBCommon) +TARGET_LINK_LIBRARIES (OTBFeatureExtraction OTBCommon otbsiftfast) INSTALL(TARGETS OTBFeatureExtraction RUNTIME DESTINATION ${OTB_INSTALL_BIN_DIR} COMPONENT RuntimeLibraries diff --git a/Code/FeatureExtraction/otbImageToHessianDeterminantImageFilter.h b/Code/FeatureExtraction/otbImageToHessianDeterminantImageFilter.h index 6a7341b7d4186dd05bbacf35094d9eeac43b4ef9..da1c141db0978fa2d51f8fc766bc6f6c346ca07d 100644 --- a/Code/FeatureExtraction/otbImageToHessianDeterminantImageFilter.h +++ b/Code/FeatureExtraction/otbImageToHessianDeterminantImageFilter.h @@ -56,9 +56,9 @@ namespace otb */ inline TOutput operator()(const TInput& input) { - return static_cast<TOutput>(input[0]*input[1] - input[2]*input[2]); - + return static_cast<TOutput>(input[0]*input[1] - input[2]*input[2]); } + bool operator !=(const HessianDeterminant) const { diff --git a/Code/FeatureExtraction/otbSiftFastImageFilter.h b/Code/FeatureExtraction/otbSiftFastImageFilter.h new file mode 100755 index 0000000000000000000000000000000000000000..451155c0a176ffa567e091bb200a3e95415f0372 --- /dev/null +++ b/Code/FeatureExtraction/otbSiftFastImageFilter.h @@ -0,0 +1,93 @@ +/*========================================================================= + +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 __otbSiftFastImageFilter_h +#define __otbSiftFastImageFilter_h + +#include "otbImageToPointSetFilter.h" +#include "itkRescaleIntensityImageFilter.h" +#include "otbImage.h" + +namespace otb +{ + + + /** \class SiftFastImageFilter + * \brief + * + */ + template <class TInputImage, class TOutputPointSet> + class ITK_EXPORT SiftFastImageFilter + : public ImageToPointSetFilter<TInputImage,TOutputPointSet> + { + public: + /** Standard typedefs */ + typedef SiftFastImageFilter Self; + typedef ImageToPointSetFilter<TInputImage,TOutputPointSet> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Creation through object factory macro */ + itkNewMacro(Self); + + /** Type macro */ + itkTypeMacro(SiftFastImageFilter,ImageToPointSetFilter); + + /** Template parameters typedefs */ + typedef TInputImage InputImageType; + typedef typename TInputImage::Pointer InputImagePointerType; + typedef typename TInputImage::PixelType PixelType; + + typedef TOutputPointSet OutputPointSetType; + typedef typename TOutputPointSet::Pointer OutputPointSetPointerType; + typedef typename TOutputPointSet::PixelType OutputPixelType; + typedef typename TOutputPointSet::PointType OutputPointType; + typedef typename TOutputPointSet::PointIdentifier OutputPointIdentifierType; + + typedef otb::Image<float,2> FloatImageType; + + // Used to rescale data in the [0,1] range + typedef itk::RescaleIntensityImageFilter<InputImageType,FloatImageType> RescalerType; + + itkSetMacro(NumberOfScales,unsigned int); + itkGetMacro(NumberOfScales,unsigned int); + + protected: + /** Actually process the input */ + virtual void GenerateData(); + + /** Constructor */ + SiftFastImageFilter(); + + /** Destructor */ + virtual ~SiftFastImageFilter() {} + + /** PrintSelf method */ + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const; + + private: + /** The number of scales */ + unsigned int m_NumberOfScales; + + + }; +}// End namespace otb +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbSiftFastImageFilter.txx" +#endif + +#endif diff --git a/Code/FeatureExtraction/otbSiftFastImageFilter.txx b/Code/FeatureExtraction/otbSiftFastImageFilter.txx new file mode 100755 index 0000000000000000000000000000000000000000..91f36d124197d2ea1e56edeb0a72c11908753164 --- /dev/null +++ b/Code/FeatureExtraction/otbSiftFastImageFilter.txx @@ -0,0 +1,116 @@ +/*========================================================================= + +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 "otbSiftFastImageFilter.h" + +#include "siftfast.h" +#include "itkContinuousIndex.h" +#include "itkImageRegionIterator.h" + +#include "otbImageFileWriter.h" + +namespace otb +{ + /** + * Constructor + */ + template <class TInputImage, class TOutputPointSet> + SiftFastImageFilter<TInputImage,TOutputPointSet> + ::SiftFastImageFilter() + { } + + template <class TInputImage, class TOutputPointSet> + void + SiftFastImageFilter<TInputImage,TOutputPointSet> + ::GenerateData() + { + // Get the input image pointer + const InputImageType * inputPtr = this->GetInput(0); + OutputPointSetPointerType outputPointSet = this->GetOutput(); + + typename InputImageType::SizeType size = inputPtr->GetLargestPossibleRegion().GetSize(); + + // Rescale data in the [0,1] range + typename RescalerType::Pointer rescaler = RescalerType::New(); + rescaler->SetInput(inputPtr); + rescaler->SetOutputMinimum(0); + rescaler->SetOutputMaximum(1); + rescaler->Update(); + + typedef otb::ImageFileWriter<FloatImageType> WriterType; + WriterType::Pointer writer = WriterType::New(); + writer->SetInput(rescaler->GetOutput()); + writer->SetFileName("qb_RoadExtract.tif"); + writer->Update(); + + SiftFastImage siftInputImage = CreateImage(size[1],size[0]); + itk::ImageRegionIterator<FloatImageType> inIt(rescaler->GetOutput(),rescaler->GetOutput()->GetLargestPossibleRegion()); + + unsigned int index =0; + + for(inIt.GoToBegin();!inIt.IsAtEnd();++inIt) + { + siftInputImage->pixels[index]=inIt.Get(); + ++index; + } + + Keypoint keypts = GetKeypoints(siftInputImage,m_NumberOfScales); + + Keypoint key = keypts; + + unsigned int numkeys = 0; + + while(key) + { + // Get the key location + itk::ContinuousIndex<float,2> keyContIndex; + keyContIndex[0]=key->col; + keyContIndex[1]=key->row; + + OutputPointType point; + inputPtr->TransformContinuousIndexToPhysicalPoint(keyContIndex,point); + + // Get the key descriptor + OutputPixelType data; + data.SetSize(128); + for(int i = 0; i < 128; ++i) + { + data[i]=key->descrip[i]; + + } + outputPointSet->SetPoint(numkeys,point); + outputPointSet->SetPointData(numkeys,data); + + // go to next key + numkeys++; + key = key->next; + } + FreeKeypoints(keypts); + DestroyAllResources(); + } + /* + * PrintSelf Method + */ + template <class TInputImage, class TOutputPointSet> + void + SiftFastImageFilter<TInputImage,TOutputPointSet> + ::PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os, indent); + } + +} // End namespace otb diff --git a/Testing/Code/FeatureExtraction/CMakeLists.txt b/Testing/Code/FeatureExtraction/CMakeLists.txt index 59c66b541ee32ef9e1cd62a9732fce47f3c6246f..74e7178115864c33f6c686189d47d5302130d3ef 100644 --- a/Testing/Code/FeatureExtraction/CMakeLists.txt +++ b/Testing/Code/FeatureExtraction/CMakeLists.txt @@ -880,6 +880,11 @@ ADD_TEST(feTvImageFittingPolygonListFilter ${FEATUREEXTRACTION_TESTS9} 5 10 ) +# ------- otb::ImageToSIFTKeyPointSetFilter ------------- + +ADD_TEST(feTuImageToFastSIFTKeyPointSetFilterNew ${FEATUREEXTRACTION_TESTS9} + otbImageToFastSIFTKeyPointSetFilterNew) + @@ -992,6 +997,10 @@ otbImageFittingPolygonListFilterNew.cxx otbImageToSURFKeyPointSetFilterNew.cxx otbImageToSURFKeyPointSetFilterOutputImage.cxx otbImageToSURFKeyPointSetFilterOutputAscii.cxx +otbImageToFastSIFTKeyPointSetFilterNew.cxx +#otbImageToFastSIFTKeyPointSetFilterOutputAscii.cxx +#otbImageToFastSIFTKeyPointSetFilterOutputImage.cx + ) INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}") diff --git a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests9.cxx b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests9.cxx index 71c377316acbc924a892e50d34205ebb543e8f2d..3188ca63f99be3971b01ce70640c4d34046653ba 100644 --- a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests9.cxx +++ b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests9.cxx @@ -40,4 +40,5 @@ REGISTER_TEST(otbImageFittingPolygonListFilterNew); REGISTER_TEST(otbImageToSURFKeyPointSetFilterNew); REGISTER_TEST(otbImageToSURFKeyPointSetFilterOutputImage); REGISTER_TEST(otbImageToSURFKeyPointSetFilterOutputAscii); +REGISTER_TEST(otbImageToFastSIFTKeyPointSetFilterNew); } diff --git a/Testing/Code/FeatureExtraction/otbImageToFastSIFTKeyPointSetFilterNew.cxx b/Testing/Code/FeatureExtraction/otbImageToFastSIFTKeyPointSetFilterNew.cxx new file mode 100644 index 0000000000000000000000000000000000000000..25893652e139170eddabcdff93dd47f6232b2bb1 --- /dev/null +++ b/Testing/Code/FeatureExtraction/otbImageToFastSIFTKeyPointSetFilterNew.cxx @@ -0,0 +1,37 @@ +/*========================================================================= + +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 "otbSiftFastImageFilter.h" +#include "otbImage.h" +#include "itkPointSet.h" +#include "itkVariableLengthVector.h" + +int otbImageToFastSIFTKeyPointSetFilterNew(int argc, char * argv[]) +{ + typedef float RealType; + const unsigned int Dimension =2; + + typedef otb::Image<RealType,Dimension> ImageType; + typedef itk::VariableLengthVector<RealType> RealVectorType; + typedef itk::PointSet<RealVectorType,Dimension> PointSetType; + typedef otb::SiftFastImageFilter<ImageType,PointSetType> ImageToFastSIFTKeyPointSetFilterType; + + // Instantiating object + ImageToFastSIFTKeyPointSetFilterType::Pointer object = ImageToFastSIFTKeyPointSetFilterType::New(); + + return EXIT_SUCCESS; +}