diff --git a/Testing/Code/FeatureExtraction/CMakeLists.txt b/Testing/Code/FeatureExtraction/CMakeLists.txt index 74e7178115864c33f6c686189d47d5302130d3ef..8539f9b24e026d50dc0f120695e27585ed9385d3 100644 --- a/Testing/Code/FeatureExtraction/CMakeLists.txt +++ b/Testing/Code/FeatureExtraction/CMakeLists.txt @@ -869,6 +869,7 @@ ADD_TEST(feTvImageToSURFKeyPointSetFilterSceneOutputAscii ${FEATUREEXTRACTION_TE # ------- otb::ImageFittingPolygonListFilter ------------- ADD_TEST(feTuImageFittingPolygonListFilterNew ${FEATUREEXTRACTION_TESTS9} otbImageFittingPolygonListFilterNew) + ADD_TEST(feTvImageFittingPolygonListFilter ${FEATUREEXTRACTION_TESTS9} --compare-ascii ${EPS} ${BASELINE_FILES}/feTvImageFittingPolygonListFilter_Output.kml @@ -880,12 +881,31 @@ ADD_TEST(feTvImageFittingPolygonListFilter ${FEATUREEXTRACTION_TESTS9} 5 10 ) -# ------- otb::ImageToSIFTKeyPointSetFilter ------------- +# ------- otb::ImageToFastSIFTKeyPointSetFilter ------------- ADD_TEST(feTuImageToFastSIFTKeyPointSetFilterNew ${FEATUREEXTRACTION_TESTS9} otbImageToFastSIFTKeyPointSetFilterNew) - +ADD_TEST(feTvImageToFastSIFTKeyPointSetFilterSceneOutputImage ${FEATUREEXTRACTION_TESTS9} +--compare-image ${EPSILON} + ${BASELINE}/feTvImageToFastSIFTKeyPointSetFilterSceneImageOutput.png + ${TEMP}/feTvImageToFastSIFTKeyPointSetFilterSceneImageOutput.png + otbImageToFastSIFTKeyPointSetFilterOutputImage + ${INPUTDATA}/scene.png + ${TEMP}/feTvImageToFastSIFTKeyPointSetFilterSceneImageOutput.png + 6 +) + +ADD_TEST(feTvImageToFastSIFTKeyPointSetFilterSceneOutputAscii ${FEATUREEXTRACTION_TESTS9} +--compare-ascii ${EPS} + ${BASELINE_FILES}/feTvImageToFastSIFTKeyPointSetFilterSceneKeysOutput.txt + ${TEMP}/feTvImageToFastSIFTKeyPointSetFilterSceneKeysOutput.txt + otbImageToFastSIFTKeyPointSetFilterOutputAscii + ${INPUTDATA}/scene.png + ${TEMP}/feTvImageToFastSIFTKeyPointSetFilterSceneKeysOutput.txt + 6 +) + # A enrichir @@ -998,9 +1018,8 @@ otbImageToSURFKeyPointSetFilterNew.cxx otbImageToSURFKeyPointSetFilterOutputImage.cxx otbImageToSURFKeyPointSetFilterOutputAscii.cxx otbImageToFastSIFTKeyPointSetFilterNew.cxx -#otbImageToFastSIFTKeyPointSetFilterOutputAscii.cxx -#otbImageToFastSIFTKeyPointSetFilterOutputImage.cx - +otbImageToFastSIFTKeyPointSetFilterOutputImage.cxx +otbImageToFastSIFTKeyPointSetFilterOutputAscii.cxx ) INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}") diff --git a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests9.cxx b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests9.cxx index 3188ca63f99be3971b01ce70640c4d34046653ba..dca475bf979d1c91b705d7d29274373f169240c0 100644 --- a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests9.cxx +++ b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests9.cxx @@ -41,4 +41,6 @@ REGISTER_TEST(otbImageToSURFKeyPointSetFilterNew); REGISTER_TEST(otbImageToSURFKeyPointSetFilterOutputImage); REGISTER_TEST(otbImageToSURFKeyPointSetFilterOutputAscii); REGISTER_TEST(otbImageToFastSIFTKeyPointSetFilterNew); +REGISTER_TEST(otbImageToFastSIFTKeyPointSetFilterOutputImage); +REGISTER_TEST(otbImageToFastSIFTKeyPointSetFilterOutputAscii); } diff --git a/Testing/Code/FeatureExtraction/otbImageToFastSIFTKeyPointSetFilterOutputAscii.cxx b/Testing/Code/FeatureExtraction/otbImageToFastSIFTKeyPointSetFilterOutputAscii.cxx new file mode 100644 index 0000000000000000000000000000000000000000..9e58dc90273024d6e85f08f36941c318079e5110 --- /dev/null +++ b/Testing/Code/FeatureExtraction/otbImageToFastSIFTKeyPointSetFilterOutputAscii.cxx @@ -0,0 +1,87 @@ +/*========================================================================= + +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 "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "itkPointSet.h" +#include "itkVariableLengthVector.h" +#include "otbRationalQuotientResampleImageFilter.h" +#include "itkRGBPixel.h" +#include "itkImageRegionIterator.h" + +#include <iostream> +#include <fstream> + +int otbImageToFastSIFTKeyPointSetFilterOutputAscii(int argc, char * argv[]) +{ + const char * infname = argv[1]; + const char * outfname = argv[2]; + + const unsigned int scales = atoi(argv[3]); + + typedef float RealType; + const unsigned int Dimension =2; + + typedef otb::Image<RealType,Dimension> ImageType; + typedef itk::VariableLengthVector<RealType> RealVectorType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef itk::PointSet<RealVectorType,Dimension> PointSetType; + typedef otb::SiftFastImageFilter<ImageType,PointSetType> ImageToFastSIFTKeyPointSetFilterType; + + // PointSet iterator types + typedef PointSetType::PointsContainer PointsContainerType; + typedef PointsContainerType::Iterator PointsIteratorType; + typedef PointSetType::PointDataContainer PointDataContainerType; + typedef PointDataContainerType::Iterator PointDataIteratorType; + + // Instantiating object + ReaderType::Pointer reader = ReaderType::New(); + ImageToFastSIFTKeyPointSetFilterType::Pointer filter = ImageToFastSIFTKeyPointSetFilterType::New(); + + reader->SetFileName(infname); + filter->SetInput(0,reader->GetOutput()); + filter->SetNumberOfScales(scales); + filter->Update(); + + PointsIteratorType pIt = filter->GetOutput()->GetPoints()->Begin(); + PointDataIteratorType pDataIt = filter->GetOutput()->GetPointData()->Begin(); + + std::ofstream outfile(outfname); + + outfile << "Number of scales: "<<scales << std::endl; + outfile << "Number of SIFT key points: " << filter->GetOutput()->GetNumberOfPoints() << std::endl; + while( pIt!=filter->GetOutput()->GetPoints()->End() ) + { + outfile << "[" << std::fixed << std::setprecision(2) << pIt.Value()[0] << ", " << std::setprecision(2) << pIt.Value()[1] << "]["; + + unsigned int lIterDesc=0; + while (lIterDesc < pDataIt.Value().Size()) + { + outfile << std::setprecision(3) << pDataIt.Value()[lIterDesc] << " "; + lIterDesc++; + } + outfile << "]" << std::endl; + ++pIt; + ++pDataIt; + } + + outfile.close(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/FeatureExtraction/otbImageToFastSIFTKeyPointSetFilterOutputImage.cxx b/Testing/Code/FeatureExtraction/otbImageToFastSIFTKeyPointSetFilterOutputImage.cxx new file mode 100644 index 0000000000000000000000000000000000000000..3f08c2426d6387cfc4a072f9f4553e9e2d430c43 --- /dev/null +++ b/Testing/Code/FeatureExtraction/otbImageToFastSIFTKeyPointSetFilterOutputImage.cxx @@ -0,0 +1,162 @@ +/*========================================================================= + +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 "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "itkPointSet.h" +#include "itkVariableLengthVector.h" +#include "otbRationalQuotientResampleImageFilter.h" +#include "itkRGBPixel.h" +#include "itkImageRegionIterator.h" + +#include <iostream> +#include <fstream> + +int otbImageToFastSIFTKeyPointSetFilterOutputImage(int argc, char * argv[]) +{ + const char * infname = argv[1]; + const char * outputImageFilename = argv[2]; + + const unsigned int scales = atoi(argv[3]); + + typedef float RealType; + const unsigned int Dimension =2; + + typedef otb::Image<RealType,Dimension> ImageType; + typedef itk::VariableLengthVector<RealType> RealVectorType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef itk::PointSet<RealVectorType,Dimension> PointSetType; + typedef otb::SiftFastImageFilter<ImageType,PointSetType> ImageToFastSIFTKeyPointSetFilterType; + + // PointSet iterator types + typedef PointSetType::PointsContainer PointsContainerType; + typedef PointsContainerType::Iterator PointsIteratorType; + + // Instantiating object + ReaderType::Pointer reader = ReaderType::New(); + ImageToFastSIFTKeyPointSetFilterType::Pointer filter = ImageToFastSIFTKeyPointSetFilterType::New(); + + reader->SetFileName(infname); + filter->SetInput(0,reader->GetOutput()); + filter->SetNumberOfScales(scales); + filter->Update(); + + ImageType::OffsetType t = {{ 0, 1}}; + ImageType::OffsetType b = {{ 0,-1}}; + ImageType::OffsetType l = {{ 1, 0}}; + ImageType::OffsetType r = {{-1, 0}}; + + typedef unsigned char PixelType; + typedef otb::Image<PixelType,2> UCharImageType; + + typedef itk::RGBPixel<PixelType> RGBPixelType; + typedef otb::Image<RGBPixelType, 2> OutputImageType; + + typedef otb::ImageFileWriter<OutputImageType> WriterType; + OutputImageType::Pointer outputImage = OutputImageType::New(); + OutputImageType::RegionType region; + + OutputImageType::SizeType outputSize; + outputSize[0] = reader->GetOutput()->GetLargestPossibleRegion().GetSize()[0]; + outputSize[1] = reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]; + region.SetSize(outputSize); + + OutputImageType::IndexType indexStart; + indexStart[0] = 0; + indexStart[1] = 0; + region.SetIndex(indexStart); + + outputImage->SetRegions(region); + outputImage->Allocate(); + + itk::ImageRegionIterator<OutputImageType> iterOutput(outputImage, + outputImage->GetLargestPossibleRegion()); + itk::ImageRegionIterator<ImageType> iterInput(reader->GetOutput(), + reader->GetOutput()->GetLargestPossibleRegion()); + + for (iterOutput.GoToBegin(), iterInput.GoToBegin(); + !iterOutput.IsAtEnd(); + ++iterOutput, ++iterInput) + { + OutputImageType::PixelType rgbPixel; + rgbPixel.SetRed( static_cast<PixelType>(iterInput.Get()) ); + rgbPixel.SetGreen( static_cast<PixelType>(iterInput.Get()) ); + rgbPixel.SetBlue( static_cast<PixelType>(iterInput.Get()) ); + + iterOutput.Set(rgbPixel); + } + + WriterType::Pointer writerTmp = WriterType::New(); + writerTmp->SetFileName(outputImageFilename); + writerTmp->SetInput(outputImage); + writerTmp->Update(); + + std::cout << "Copy Input image in Output image" << std::endl; + + PointsIteratorType pIt = filter->GetOutput()->GetPoints()->Begin(); + ImageType::SpacingType spacing = reader->GetOutput()->GetSpacing(); + ImageType::PointType origin = reader->GetOutput()->GetOrigin(); + OutputImageType::SizeType size = outputImage->GetLargestPossibleRegion().GetSize(); + + while( pIt != filter->GetOutput()->GetPoints()->End() ) + { + ImageType::IndexType index; + + index[0] = (unsigned int) + (vcl_floor + ((double)((pIt.Value()[0]-origin[0])/spacing[0]+0.5))); + + index[1] = (unsigned int) + (vcl_floor + ((double)((pIt.Value()[1]-origin[1])/spacing[1]+0.5))); + + OutputImageType::PixelType keyPixel; + keyPixel.SetRed(0); + keyPixel.SetGreen(255); + keyPixel.SetBlue(0); + + if (outputImage->GetLargestPossibleRegion().IsInside(index)) + { + outputImage->SetPixel(index,keyPixel); + + if (outputImage->GetLargestPossibleRegion().IsInside(index+t)) + outputImage->SetPixel(index+t,keyPixel); + + if (outputImage->GetLargestPossibleRegion().IsInside(index+b)) + outputImage->SetPixel(index+b,keyPixel); + + if (outputImage->GetLargestPossibleRegion().IsInside(index+l)) + outputImage->SetPixel(index+l,keyPixel); + + if (outputImage->GetLargestPossibleRegion().IsInside(index+r)) + outputImage->SetPixel(index+r,keyPixel); + } + ++pIt; + } + + std::cout << "Copy sift key" << std::endl; + + WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(outputImageFilename); + writer->SetInput(outputImage); + writer->Update(); + + std::cout << "Write image" << std::endl; + return EXIT_SUCCESS; +}