Commit 485fc707 authored by Julien Michel's avatar Julien Michel
Browse files

Ajout du filtre qui applique un filtre ImageToImageFilter quelconque à une VectorImage par bande.

parent f6994514
......@@ -24,10 +24,20 @@ PURPOSE. See the above copyright notices for more information.
namespace otb
{
/** \class ImageListToImageListApplyFilter
* \brief
* \brief This filter applies the filter given as template to the input image list.
*
* \ingroup
* \ingroup
* It produces one output image in the output list for one input image in the output list.
*
* It uses the given filter methods to generate output information and input requested region.
*
* The filter can be set up via the GetFilter() accessor.
*
* It also support streaming when the templated filter support it.
*
* No type checking is done : it is up to the user to check the adequation between the input images,
* output images and filter IO types.
*
* \ingroup Streamed
*/
template <class TInputImageList, class TOutputImageList, class TFilter>
class ITK_EXPORT ImageListToImageListApplyFilter
......
/*=========================================================================
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 _otbPerBandVectorImageFilter_h
#define _otbPerBandVectorImageFilter_h
#include "otbVectorImageToImageListFilter.h"
#include "otbImageListToImageListApplyFilter.h"
#include "otbImageListToVectorImageFilter.h"
#include "otbImageList.h"
#include "otbImage.h"
#include "itkImageToImageFilter.h"
namespace otb
{
/** \class PerBandVectorImageFilter
* \brief This filter is a helper class to apply per band a standard ImageToImageFilter to a VectorImage.
*
* This filter is a composite filter composed of the following filters :
* - VectorImageToImageListFilter
* - ImageListToImageListApplyFilter
* - ImageListToVectorImageFilter
*
* \sa VectorImageToImageListFilter
* \sa ImageListToImageListApplyFilter
* \sa ImageListToVectorImageFilter
* \ingroup Streamed
*/
template <class TInputImage, class TOutputImage, class TFilter>
class ITK_EXPORT PerBandVectorImageFilter
: public itk::ImageToImageFilter<TInputImage,TOutputImage>
{
public:
/** Standard typedefs */
typedef PerBandVectorImageFilter Self;
typedef itk::ImageToImageFilter<TInputImage,TOutputImage> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Type macro */
itkNewMacro(Self);
/** Creation through object factory macro */
itkTypeMacro(PerBandVectorImageFilter, ImageToImageFilter);
/** Template parameters typedefs */
typedef TInputImage InputVectorImageType;
typedef typename InputVectorImageType::Pointer InputVectorImagePointerType;
typedef typename InputVectorImageType::InternalPixelType InputPixelType;
typedef Image<InputPixelType,InputVectorImageType::ImageDimension> InputImageType;
typedef ImageList<InputImageType> InputImageListType;
typedef TOutputImage OutputVectorImageType;
typedef typename OutputVectorImageType::Pointer OutputVectorImagePointerType;
typedef typename OutputVectorImageType::InternalPixelType OutputPixelType;
typedef Image<OutputPixelType,OutputVectorImageType::ImageDimension> OutputImageType;
typedef ImageList<OutputImageType> OutputImageListType;
typedef TFilter FilterType;
typedef typename FilterType::Pointer FilterPointerType;
// Internal filters definition
typedef VectorImageToImageListFilter<InputVectorImageType,InputImageListType> DecompositionFilterType;
typedef typename DecompositionFilterType::Pointer DecompositionFilterPointerType;
typedef ImageListToImageListApplyFilter<InputImageListType,OutputImageListType,FilterType>
ProcessingFilterType;
typedef typename ProcessingFilterType::Pointer ProcessingFilterPointerType;
typedef ImageListToVectorImageFilter<OutputImageListType,OutputVectorImageType> RecompositionFilterType;
typedef typename RecompositionFilterType::Pointer RecompositionFilterPointerType;
/**
* Set the processing filter. This method is provided to allow the setting up of the filter.
* \param filter The filter to use.
*/
void SetFilter(FilterType * filter);
/**
* Get the processing filter. This method is provided to allow the setting of the filter.
* \return The filter used.
*/
FilterType * GetFilter(void);
/**
* Set the index of the output of the filter from which to recompose the vector image.
* Default is 0.
* \param index The index of the output of the filter to use.
*/
void SetOutputIndex(unsigned int index);
/**
* Get the index of the output of the filter from which the vector image is recomposed.
* Default is 0.
* \return The index of the output of the filter used.
*/
unsigned int GetOutputIndex(void);
protected:
/** Main computation method */
virtual void GenerateData(void);
/** Constructor */
PerBandVectorImageFilter();
/** Destructor */
virtual ~PerBandVectorImageFilter() {};
/**PrintSelf method */
virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
private:
PerBandVectorImageFilter(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
/// Splits VectorImage to ImageList
DecompositionFilterPointerType m_DecompositionFilter;
/// Processes the ImageList
ProcessingFilterPointerType m_ProcessingFilter;
/// Recompose the VectorImage
RecompositionFilterPointerType m_RecompositionFilter;
};
}// End namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbPerBandVectorImageFilter.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 _otbPerBandVectorImageFilter_txx
#define _otbPerBandVectorImageFilter_txx
#include "otbPerBandVectorImageFilter.h"
namespace otb
{
/**
* Constructor
*/
template <class TInputImage, class TOutputImage, class TFilter>
PerBandVectorImageFilter<TInputImage,TOutputImage,TFilter>
::PerBandVectorImageFilter()
{
m_DecompositionFilter = DecompositionFilterType::New();
m_ProcessingFilter = ProcessingFilterType::New();
m_RecompositionFilter = RecompositionFilterType::New();
}
/**
* Set the processing filter. This method is provided to allow the setting up of the filter.
* \param filter The filter to use.
*/
template <class TInputImage, class TOutputImage, class TFilter>
void
PerBandVectorImageFilter<TInputImage,TOutputImage,TFilter>
::SetFilter(FilterType * filter)
{
m_ProcessingFilter->SetFilter(filter);
}
/**
* Get the processing filter. This method is provided to allow the setting of the filter.
* \return The filter used.
*/
template <class TInputImage, class TOutputImage, class TFilter>
typename PerBandVectorImageFilter<TInputImage,TOutputImage,TFilter>
::FilterType *
PerBandVectorImageFilter<TInputImage,TOutputImage,TFilter>
::GetFilter()
{
return m_ProcessingFilter->GetFilter();
}
/**
* Set the index of the output of the filter from which to recompose the vector image.
* Default is 0.
* \param index The index of the output of the filter to use.
*/
template <class TInputImage, class TOutputImage, class TFilter>
void
PerBandVectorImageFilter<TInputImage,TOutputImage,TFilter>
::SetOutputIndex(unsigned int index)
{
m_ProcessingFilter->SetOutputIndex(index);
}
/**
* Get the index of the output of the filter from which the vector image is recomposed.
* Default is 0.
* \return The index of the output of the filter used.
*/
template <class TInputImage, class TOutputImage, class TFilter>
unsigned int
PerBandVectorImageFilter<TInputImage,TOutputImage,TFilter>
::GetOutputIndex()
{
return m_ProcessingFilter->GetOutputIndex();
}
/**
* Main computation method
*/
template <class TInputImage, class TOutputImage, class TFilter>
void
PerBandVectorImageFilter<TInputImage,TOutputImage,TFilter>
::GenerateData()
{
m_DecompositionFilter->SetInput(this->GetInput());
m_ProcessingFilter->SetInput(m_DecompositionFilter->GetOutput());
m_RecompositionFilter->SetInput(m_ProcessingFilter->GetOutput());
m_RecompositionFilter->GraftOutput(this->GetOutput());
m_RecompositionFilter->Update();
this->GraftOutput(m_RecompositionFilter->GetOutput());
}
/**
* PrintSelf Method
*/
template <class TInputImage, class TOutputImage, class TFilter>
void
PerBandVectorImageFilter<TInputImage,TOutputImage,TFilter>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
}
} // End namespace otb
#endif
......@@ -52,12 +52,18 @@ class ITK_EXPORT VectorImageToImageListFilter
/** Template parameters typedefs */
typedef TVectorImageType InputVectorImageType;
typedef typename InputVectorImageType::ConstPointer InputVectorImageConstPointerType;
typedef typename InputVectorImageType::Pointer InputVectorImagePointerType;
typedef TImageList OutputImageListType;
typedef typename OutputImageListType::Pointer OutputImageListPointerType;
typedef typename OutputImageListType::ImageType OutputImageType;
typedef typename OutputImageType::Pointer OutputImagePointerType;
/** Generate the input requested region from the first element in the list. */
virtual void GenerateInputRequestedRegion(void);
/** Generate the output information by building the output list. */
virtual void GenerateOutputInformation(void);
protected:
/** Main computation method */
......
......@@ -26,6 +26,43 @@ PURPOSE. See the above copyright notices for more information.
namespace otb
{
/** Generate the input requested region from the first element in the list. */
template <class TVectorImageType, class TImageList>
void
VectorImageToImageListFilter<TVectorImageType,TImageList>
::GenerateOutputInformation(void)
{
OutputImageListPointerType outputPtr = this->GetOutput();
InputVectorImagePointerType inputPtr = this->GetInput();
if(inputPtr)
{
for(unsigned int i=0;i<inputPtr->GetNumberOfComponentsPerPixel();++i)
{
typename OutputImageType::Pointer tmpImagePtr = OutputImageType::New();
tmpImagePtr->CopyInformation(inputPtr);
tmpImagePtr->SetRegions(inputPtr->GetLargestPossibleRegion());
outputPtr->PushBack(tmpImagePtr);
}
}
}
/** Generate the output information by building the output list. */
template <class TVectorImageType, class TImageList>
void
VectorImageToImageListFilter<TVectorImageType,TImageList>
::GenerateInputRequestedRegion(void)
{
OutputImageListPointerType outputPtr = this->GetOutput();
InputVectorImagePointerType inputPtr = this->GetInput();
if(inputPtr)
{
if(outputPtr->Size()>0)
{
inputPtr->SetRequestedRegion(outputPtr->GetNthElement(0)->GetRequestedRegion());
}
}
}
/**
* Main computation method
*/
......@@ -34,9 +71,8 @@ void
VectorImageToImageListFilter<TVectorImageType,TImageList>
::GenerateData(void)
{
OutputImageListPointerType outputPtr = this->GetOutput();
InputVectorImageConstPointerType inputPtr = this->GetInput();
InputVectorImagePointerType inputPtr = this->GetInput();
typedef itk::ImageRegionConstIterator<InputVectorImageType> InputIteratorType;
typedef itk::ImageRegionIterator<OutputImageType> OutputIteratorType;
......@@ -45,13 +81,11 @@ VectorImageToImageListFilter<TVectorImageType,TImageList>
std::vector<OutputIteratorType> outputIteratorList;
for(unsigned int i = 0;i<inputPtr->GetNumberOfComponentsPerPixel();++i)
typename OutputImageListType::ConstIterator outputListIt = outputPtr->Begin();
for(;outputListIt!=outputPtr->End();++outputListIt)
{
typename OutputImageType::Pointer tmpImagePtr = OutputImageType::New();
tmpImagePtr->SetRegions(inputPtr->GetRequestedRegion());
tmpImagePtr->Allocate();
outputPtr->PushBack(tmpImagePtr);
outputIteratorList.push_back(OutputIteratorType(outputPtr->Back(),inputPtr->GetRequestedRegion()));
outputListIt.Get()->Allocate();
outputIteratorList.push_back(OutputIteratorType(outputListIt.Get(),outputListIt.Get()->GetRequestedRegion()));
outputIteratorList.back().GoToBegin();
}
......
......@@ -294,6 +294,28 @@ ADD_TEST(bfTvImageListToImageListApplyFilter ${BASICFILTERS_TESTS}
${TEMP}/bfTvImageListToImageListApplyFilterBand3.png
)
# ------- otb::PerBandVectorImageFilter ----------------------------
ADD_TEST(bfTuPerBandVectorImageFilterNew ${BASICFILTERS_TESTS}
otbPerBandVectorImageFilterNew)
ADD_TEST(bfTvPerBandVectorImageFilterWithMeanFilter ${BASICFILTERS_TESTS}
--compare-image ${EPSILON}
${BASELINE}/bfTvPerBandVectorImageFilterWithMeanFilterOutput.hdr
${TEMP}/bfTvPerBandVectorImageFilterWithMeanFilterOutput.hdr
otbPerBandVectorImageFilterWithMeanFilter
${INPUTDATA}/poupees.png
${TEMP}/bfTvPerBandVectorImageFilterWithMeanFilterOutput.hdr
)
ADD_TEST(bfTvPerBandVectorImageFilterWithSobelFilter ${BASICFILTERS_TESTS}
--compare-image ${EPSILON}
${BASELINE}/bfTvPerBandVectorImageFilterWithSobelFilterOutput.hdr
${TEMP}/bfTvPerBandVectorImageFilterWithSobelFilterOutput.hdr
otbPerBandVectorImageFilterWithSobelFilter
${INPUTDATA}/poupees.png
${TEMP}/bfTvPerBandVectorImageFilterWithSobelFilterOutput.hdr
)
# A enrichir
SET(BasicFilters_SRCS
otbLeeFilter.cxx
......@@ -329,6 +351,9 @@ otbImageListToVectorImageFilterNew.cxx
otbImageListToVectorImageFilter.cxx
otbImageListToImageListApplyFilterNew.cxx
otbImageListToImageListApplyFilter.cxx
otbPerBandVectorImageFilterNew.cxx
otbPerBandVectorImageFilterWithMeanFilter.cxx
otbPerBandVectorImageFilterWithSobelFilter.cxx
)
......
......@@ -60,4 +60,7 @@ REGISTER_TEST(otbImageListToVectorImageFilterNew);
REGISTER_TEST(otbImageListToVectorImageFilter);
REGISTER_TEST(otbImageListToImageListApplyFilterNew);
REGISTER_TEST(otbImageListToImageListApplyFilter);
REGISTER_TEST(otbPerBandVectorImageFilterNew);
REGISTER_TEST(otbPerBandVectorImageFilterWithMeanFilter);
REGISTER_TEST(otbPerBandVectorImageFilterWithSobelFilter);
}
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