Commit fe924929 authored by Julien Michel's avatar Julien Michel

ENH: Finished the optimized convolution algorithm. Added test to compare with...

ENH: Finished the optimized convolution algorithm. Added test to compare with the classical convolution.
parent 0f2bc52a
......@@ -938,6 +938,8 @@ ADD_TEST(bfTvScalarVectorImageTextureFunctor ${BASICFILTERS_TESTS9}
2 # radius
)
# ------- otb::GaborFilterGenerator ----------------------------
ADD_TEST(bfTuGaborFilterGeneratorNew ${BASICFILTERS_TESTS9}
otbGaborFilterGeneratorNew
)
......@@ -955,6 +957,39 @@ ADD_TEST(bfTvGaborFilterGenerator ${BASICFILTERS_TESTS9}
0
)
# ------- otb::OverlapSaveConvolutionImageFilter ----------------------------
IF(USE_FFTWD)
ADD_TEST(bfTuOverlapSaveConvolutionImageFilterNew ${BASICFILTERS_TESTS9}
otbOverlapSaveConvolutionImageFilterNew)
ADD_TEST(bfTvOverlapSaveConvolutionImageFilter ${BASICFILTERS_TESTS9}
--compare-image ${EPSILON}
${BASELINE}/bfTvConvolutionImageFilter.tif
${TEMP}/bfTvOverlapSaveConvolutionImageFilter.tif
otbOverlapSaveConvolutionImageFilter
${INPUTDATA}/QB_Suburb.png
${TEMP}/bfTvOverlapSaveConvolutionImageFilter.tif
)
ADD_TEST(bfTvCompareOverlapSaveAndClassicalConvolutionWithGaborFilter ${BASICFILTERS_TESTS9}
--compare-image ${EPSILON}
${TEMP}/bfTvCompareConvolutionOutput.tif
${TEMP}/bfTvCompareOSConvolutionoutput.tif
otbCompareOverlapSaveAndClassicalConvolutionWithGaborFilter
${INPUTDATA}/ROI_IKO_PAN_LesHalles_sub.tif
${TEMP}/bfTvCompareConvolutionOutput.tif
${TEMP}/bfTvCompareOSConvolutionoutput.tif
64 64 #Radius
0.02 0.025 # a b
-45 # theta
0.0125 0.0125 #u0 v0
0
)
ENDIF(USE_FFTWD)
# A enrichir
SET(BasicFilters_SRCS1
otbLeeFilter.cxx
......@@ -1095,8 +1130,17 @@ otbScalarVectorImageTextureFunctorNew.cxx
otbScalarVectorImageTextureFunctor.cxx
otbGaborFilterGeneratorNew.cxx
otbGaborFilterGenerator.cxx
)
IF(USE_FFTWD)
SET(BasicFilters_SRCS9
${BasicFilters_SRCS9}
otbOverlapSaveConvolutionImageFilterNew.cxx
otbOverlapSaveConvolutionImageFilter.cxx
otbCompareOverlapSaveAndClassicalConvolutionWithGaborFilter.cxx
)
ENDIF(USE_FFTWD)
INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}")
......
......@@ -43,4 +43,9 @@ REGISTER_TEST(otbScalarVectorImageTextureFunctorNew);
REGISTER_TEST(otbScalarVectorImageTextureFunctor);
REGISTER_TEST(otbGaborFilterGeneratorNew);
REGISTER_TEST(otbGaborFilterGenerator);
#if defined(USE_FFTWD)
REGISTER_TEST(otbOverlapSaveConvolutionImageFilterNew);
REGISTER_TEST(otbOverlapSaveConvolutionImageFilter);
REGISTER_TEST(otbCompareOverlapSaveAndClassicalConvolutionWithGaborFilter);
#endif
}
#if defined(_MSC_VER)
#pragma warning (disable : 4786)
#endif
#ifdef __BORLANDC__
#define ITK_LEAN_AND_MEAN
#endif
#include <math.h>
#include <iostream>
#include "otbImage.h"
#include "otbImageFileReader.h"
#include "otbStreamingImageFileWriter.h"
#include "otbConvolutionImageFilter.h"
#include "otbOverlapSaveConvolutionImageFilter.h"
#include "otbGaborFilterGenerator.h"
#include "itkConstantBoundaryCondition.h"
#include "itkTimeProbe.h"
int otbCompareOverlapSaveAndClassicalConvolutionWithGaborFilter( int argc, char *argv[])
{
if(argc!=12)
{
std::cerr<<"Usage: "<<argv[0]<<" infname outfname1 outfname2 xradius yradius a b theta u0 v0 phi"<<std::endl;
return EXIT_FAILURE;
}
const char * infname = argv[1];
const char * outfname1 = argv[2];
const char * outfname2 = argv[3];
const unsigned int xradius = atoi(argv[4]);
const unsigned int yradius = atoi(argv[5]);
const double a = atof(argv[6]);
const double b = atof(argv[7]);
const double theta = atof(argv[8]);
const double u0 = atof(argv[9]);
const double v0 = atof(argv[10]);
const double phi = atof(argv[11]);
typedef double PrecisionType;
typedef otb::GaborFilterGenerator<PrecisionType> GaborGeneratorType;
typedef GaborGeneratorType::RadiusType RadiusType;
typedef GaborGeneratorType::ArrayType ArrayType;
typedef otb::Image<PrecisionType,2> ImageType;
typedef otb::ImageFileReader<ImageType> ReaderType;
typedef otb::StreamingImageFileWriter<ImageType> WriterType;
typedef otb::OverlapSaveConvolutionImageFilter<ImageType,ImageType> OSConvolutionFilterType;
// Setting the same boundary conditions than the one used in the overlap save convolution filter
typedef itk::ConstantBoundaryCondition<ImageType> BoundaryConditionType;
typedef otb::ConvolutionImageFilter<ImageType,ImageType,BoundaryConditionType> ConvolutionFilterType;
// Gabor filter generation
GaborGeneratorType::Pointer gabor = GaborGeneratorType::New();
RadiusType radius;
radius[0]=xradius;
radius[1]=yradius;
gabor->SetRadius(radius);
gabor->SetA(a);
gabor->SetB(b);
gabor->SetTheta(theta);
gabor->SetU0(u0);
gabor->SetV0(v0);
gabor->SetPhi(phi);
ArrayType filter = gabor->GetFilter();
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(infname);
itk::TimeProbe probe1,probe2;
ConvolutionFilterType::Pointer convolution = ConvolutionFilterType::New();
convolution->SetRadius(radius);
convolution->SetFilter(filter);
convolution->SetInput(reader->GetOutput());
WriterType::Pointer writer1 = WriterType::New();
writer1->SetInput(convolution->GetOutput());
writer1->SetFileName(outfname1);
probe1.Start();
writer1->Update();
probe1.Stop();
std::cout<<"Classical convolution algorithm took "<<probe1.GetMeanTime()<<" seconds."<<std::endl;
OSConvolutionFilterType::Pointer osconvolution = OSConvolutionFilterType::New();
osconvolution->SetRadius(radius);
osconvolution->SetFilter(filter);
osconvolution->SetInput(reader->GetOutput());
WriterType::Pointer writer2 = WriterType::New();
writer2->SetInput(osconvolution->GetOutput());
writer2->SetFileName(outfname2);
probe2.Start();
writer2->Update();
probe2.Stop();
std::cout<<"Overlap-save convolution algorithm took "<<probe2.GetMeanTime()<<" seconds."<<std::endl;
return EXIT_SUCCESS;
}
......@@ -23,6 +23,7 @@
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
#include "otbConvolutionImageFilter.h"
#include "itkConstantBoundaryCondition.h"
int otbConvolutionImageFilter( int argc, char * argv[] )
......@@ -38,7 +39,9 @@ int otbConvolutionImageFilter( int argc, char * argv[] )
typedef otb::Image< OutputPixelType, Dimension > OutputImageType;
typedef otb::ImageFileReader< PanchroImageType > ReaderType;
typedef otb::ImageFileWriter< OutputImageType > WriterType;
typedef otb::ConvolutionImageFilter< PanchroImageType,OutputImageType > ConvFilterType;
// Overriding boundary condition to compare with the overlap save convolution results.
typedef itk::ConstantBoundaryCondition<PanchroImageType> BoundaryConditionType;
typedef otb::ConvolutionImageFilter< PanchroImageType,OutputImageType, BoundaryConditionType > ConvFilterType;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
......
/*=========================================================================
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.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include "otbImage.h"
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
#include "otbOverlapSaveConvolutionImageFilter.h"
int otbOverlapSaveConvolutionImageFilter( int argc, char * argv[] )
{
const char * inputFileName = argv[1];
const char * outputFileName = argv[2];
typedef double InputPixelType;
typedef double OutputPixelType;
const unsigned int Dimension = 2;
typedef otb::Image< InputPixelType, Dimension > PanchroImageType;
typedef otb::Image< OutputPixelType, Dimension > OutputImageType;
typedef otb::ImageFileReader< PanchroImageType > ReaderType;
typedef otb::ImageFileWriter< OutputImageType > WriterType;
typedef otb::OverlapSaveConvolutionImageFilter< PanchroImageType,OutputImageType > ConvFilterType;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
ConvFilterType::Pointer convFilter = ConvFilterType::New();
reader->SetFileName(inputFileName);
writer->SetFileName(outputFileName);
ConvFilterType::InputSizeType radius;
radius[0]=3;
radius[1]=3;
ConvFilterType::ArrayType filterCoeffs;
filterCoeffs.SetSize((2*radius[0]+1)*(2*radius[1]+1));
filterCoeffs.Fill(1);
convFilter->SetRadius(radius);
convFilter->SetFilter(filterCoeffs);
convFilter->NormalizeFilterOn();
convFilter->SetInput( reader->GetOutput() );
writer->SetInput( convFilter->GetOutput() );
writer->Update();
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.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include "otbImage.h"
#include "otbOverlapSaveConvolutionImageFilter.h"
int otbOverlapSaveConvolutionImageFilterNew( int argc, char * argv[] )
{
typedef double InputPixelType;
typedef double OutputPixelType;
const unsigned int Dimension = 2;
typedef otb::Image< InputPixelType, Dimension > InputImageType;
typedef otb::Image< OutputPixelType, Dimension > OutputImageType;
typedef otb::OverlapSaveConvolutionImageFilter< InputImageType,OutputImageType > FilterType;
FilterType::Pointer conv = FilterType::New();
return EXIT_SUCCESS;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment