Skip to content
Snippets Groups Projects
Commit 1ea3f5a8 authored by Cyrille Valladeau's avatar Cyrille Valladeau
Browse files

Ajout du test sur BasicFilters/otbConvolutionImageFilter.

parent 43079ea9
Branches
Tags
No related merge requests found
......@@ -25,7 +25,7 @@
namespace otb
{
/** \class ConvolutionImageFilter
* \brief Applies a convolution filter to an image
* \brief Applies a convolution filter to a mono channel image
*
* Computes an image which is the convolution of the input image
* with a filter.
......@@ -72,7 +72,9 @@ public:
typedef typename InputImageType::PixelType InputPixelType;
typedef typename OutputImageType::PixelType OutputPixelType;
typedef typename itk::NumericTraits<InputPixelType>::RealType InputRealType;
//typedef typename InputPixelType::InternalPixelType InputRealType;
typedef typename InputImageType::RegionType InputImageRegionType;
typedef typename OutputImageType::RegionType OutputImageRegionType;
......@@ -102,9 +104,20 @@ public:
itkGetConstReferenceMacro(Radius, InputSizeType);
/** Set the input filter */
itkSetMacro(Filter, ArrayType);
void SetFilter( ArrayType filter )
{
if(filter.Size()!= m_Filter.Size())
{
itkExceptionMacro("Error in SetFilter, invalid filter size:"<< filter.Size()<<" instead of 2*(m_Radius[0]+1)*(2*m_Radius[1]+1): "<<m_Filter.Size());
}
else
{
m_Filter = filter;
}
this->Modified();
}
itkGetConstReferenceMacro(Filter, ArrayType);
/** ConvolutionImageFilter needs a larger input requested region than
* the output requested region. As such, ConvolutionImageFilter needs
* to provide an implementation for GenerateInputRequestedRegion()
......
......@@ -126,28 +126,28 @@ ConvolutionImageFilter< TInputImage, TOutputImage>
//std::cout << m_Radius << std::endl;
//std::cout << bit << std::endl;
unsigned int neighborhoodSize = bit.Size();
it = itk::ImageRegionIterator<OutputImageType>(output, *fit);
bit.OverrideBoundaryCondition(&nbc);
bit.GoToBegin();
unsigned int neighborhoodSize = bit.Size();
while ( ! bit.IsAtEnd() )
{
sum = itk::NumericTraits<InputRealType>::Zero;
norm = itk::NumericTraits<InputRealType>::Zero;
//std::cout << neighborhoodSize << std::endl;
for (i = 0; i < neighborhoodSize; ++i)
{
sum += static_cast<InputRealType>( bit.GetPixel(i)*m_Filter(i) );
norm += static_cast<InputRealType>( m_Filter(i) );
}
// get the mean value
it.Set( static_cast<OutputPixelType>(sum / double(norm)) );
++bit;
++it;
progress.CompletedPixel();
sum = itk::NumericTraits<InputRealType>::Zero;
norm = itk::NumericTraits<InputRealType>::Zero;
for (i = 0; i < neighborhoodSize; ++i)
{
sum += static_cast<InputRealType>( bit.GetPixel(i)*m_Filter(i) );
norm += static_cast<InputRealType>( m_Filter(i) );
}
// get the mean value
it.Set( static_cast<OutputPixelType>(sum / double(norm)) );
++bit;
++it;
progress.CompletedPixel();
}
}
}
......
......@@ -814,6 +814,21 @@ ADD_TEST(bfTvEuclideanDistanceWithMissingValue ${BASICFILTERS_TESTS8}
127 127 2 3 1
)
# ------- otb::ConvolutionImageFilter ----------------------------
ADD_TEST(bfTuConvolutionImageFilterNew ${BASICFILTERS_TESTS8}
otbConvolutionImageFilterNew)
ADD_TEST(bfTuConvolutionImageFilter ${BASICFILTERS_TESTS8}
--compare-image ${EPSILON}
${BASELINE}/bfTuConvolutionImageFilter.tif
${TEMP}/bfTuConvolutionImageFilter.tif
otbConvolutionImageFilter
${INPUTDATA}/QB_Suburb.png
${TEMP}/bfTuConvolutionImageFilter.tif
)
# A enrichir
SET(BasicFilters_SRCS1
otbLeeFilter.cxx
......@@ -930,6 +945,8 @@ otbLabelizeConfidenceConnectedImageFilterNew.cxx
otbLabelizeConfidenceConnectedImageFilter.cxx
otbEuclideanDistanceWithMissingValueNew.cxx
otbEuclideanDistanceWithMissingValue.cxx
otbConvolutionImageFilterNew.cxx
otbConvolutionImageFilter.cxx
)
INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}")
......
......@@ -35,4 +35,6 @@ void RegisterTests()
REGISTER_TEST(otbLabelizeConfidenceConnectedImageFilter);
REGISTER_TEST(otbEuclideanDistanceWithMissingValueNew);
REGISTER_TEST(otbEuclideanDistanceWithMissingValue);
REGISTER_TEST(otbConvolutionImageFilterNew);
REGISTER_TEST(otbConvolutionImageFilter);
}
/*=========================================================================
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 "otbConvolutionImageFilter.h"
int otbConvolutionImageFilter( 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::ConvolutionImageFilter< 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;
//itk::Array< double > filterCoeffs;
ConvFilterType::ArrayType filterCoeffs;
filterCoeffs.SetSize((2*radius[0]+1)*(2*radius[1]+1));
filterCoeffs.Fill(1);
convFilter->SetRadius(radius);
convFilter->SetFilter(filterCoeffs);
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 "otbConvolutionImageFilter.h"
int otbConvolutionImageFilterNew( 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::ConvolutionImageFilter< InputImageType,OutputImageType > FilterType;
FilterType::Pointer conv = FilterType::New();
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment